Skip to content

Commit 15a6555

Browse files
besalelipeteski22
andauthored
chore(licenses): Add third party license distribution (#207)
* Support NOTICE * Added third-party license validation using go-licenses/v2 * Created Makefile targets: check-licenses, check-notice, and notice for license management * Added CI workflow to validate licenses and NOTICE file on PRs to main * Updated release process to include NOTICE file instead of individual license files * Generated NOTICE file with full license text for all dependencies * Updated documentation to reflect new targets Tested GHA locally using 'act' with: act pull_request -j check-license -P ubuntu-latest=catthehacker/ubuntu:act-latest --container-architecture linux/amd64 --bind Tested Makefile targets locally too --------- Co-authored-by: Peter Wilson <[email protected]>
1 parent 3a0e589 commit 15a6555

File tree

6 files changed

+1123
-19
lines changed

6 files changed

+1123
-19
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: License Validation
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- 'go.mod'
9+
- 'go.sum'
10+
- 'NOTICE'
11+
12+
jobs:
13+
check-license:
14+
runs-on: ubuntu-latest
15+
env:
16+
ALLOWED_LICENSES: "Apache-2.0,MIT,BSD-2-Clause,BSD-3-Clause,ZeroBSD,Unlicense"
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
22+
- name: Cache Go modules
23+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
24+
with:
25+
path: |
26+
~/.cache/go-build
27+
~/go/pkg/mod
28+
key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }}
29+
restore-keys: |
30+
${{ runner.os }}-golang-
31+
32+
- name: Set up Go (from go.mod)
33+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
34+
with:
35+
go-version-file: go.mod
36+
37+
- name: Install go-licenses
38+
run: go install github.com/google/go-licenses/v2@latest
39+
40+
- name: Check allowed licenses
41+
run: go-licenses check ./... --ignore github.com/mozilla-ai/mcpd/v2 --allowed_licenses=${ALLOWED_LICENSES}
42+
43+
- name: Check NOTICE file
44+
run: |
45+
go-licenses report ./... --ignore github.com/mozilla-ai/mcpd/v2 --template build/licenses/notice.tpl > NOTICE.new
46+
if ! cmp -s NOTICE NOTICE.new; then
47+
echo "NOTICE is out of date. Please regenerate it with 'make notice'"
48+
diff -u NOTICE NOTICE.new || true
49+
exit 1
50+
fi

.goreleaser.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ archives:
4242
format_overrides:
4343
- goos: windows
4444
formats: [zip]
45+
files:
46+
- LICENSE
47+
- README.md
48+
- NOTICE
4549

4650
homebrew_casks:
4751
- name: mcpd

Makefile

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build build-dev build-linux build-linux-arm64 clean docs docs-cli docs-local docs-nav install lint local-down local-up test uninstall validate-registry
1+
.PHONY: build build-dev build-linux build-linux-arm64 clean docs docs-cli docs-local docs-nav install lint local-down local-up test uninstall validate-registry check-licenses check-notice notice
22

33
MODULE_PATH := github.com/mozilla-ai/mcpd/v2
44

@@ -29,7 +29,40 @@ LDFLAGS := -s -w -X '$(MODULE_PATH)/internal/cmd.version=$(VERSION)' \
2929
# Build flags for optimization
3030
BUILDFLAGS := -trimpath
3131

32-
lint:
32+
# The license types allowed to be imported by the project
33+
ALLOWED_LICENSES := Apache-2.0,MIT,BSD-2-Clause,BSD-3-Clause,ZeroBSD,Unlicense
34+
35+
check-licenses:
36+
@echo "Checking licenses..."
37+
@go install github.com/google/go-licenses/v2@latest
38+
@set -e; \
39+
if go-licenses check ./... --ignore github.com/mozilla-ai/mcpd/v2 --allowed_licenses=$(ALLOWED_LICENSES); then \
40+
echo "✓ All licenses are allowed."; \
41+
else \
42+
echo "License check failed: some dependencies have disallowed licenses."; \
43+
exit 1; \
44+
fi
45+
46+
check-notice:
47+
@echo "Checking NOTICE..."
48+
@go install github.com/google/go-licenses/v2@latest
49+
@tmp=$$(mktemp); \
50+
trap "rm -f $$tmp" EXIT; \
51+
go-licenses report ./... --ignore github.com/mozilla-ai/mcpd/v2 --template build/licenses/notice.tpl > $$tmp; \
52+
if ! cmp -s NOTICE $$tmp; then \
53+
echo "NOTICE is out of date. Regenerate it with 'make notice'"; \
54+
exit 1; \
55+
else \
56+
echo "✓ NOTICE is up to date"; \
57+
fi
58+
59+
notice:
60+
@echo "Generating NOTICE..."
61+
@go install github.com/google/go-licenses/v2@latest
62+
@go-licenses report ./... --ignore github.com/mozilla-ai/mcpd/v2 --template build/licenses/notice.tpl > NOTICE
63+
@echo "✓ NOTICE generated"
64+
65+
lint: check-notice
3366
golangci-lint run --fix -v
3467

3568
test: lint

0 commit comments

Comments
 (0)