Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3ee7234

Browse filesBrowse files
feat: auto-fix license files on PRs and improve CI reliability
- license-check.yml: Auto-regenerate licenses, push fix to PR, and comment - script/licenses: Pin go-licenses version in CI for reproducibility - script/licenses-check: Pin go-licenses version in CI - code-scanning.yml: Exclude third-party folder from CodeQL Inspired by cli/cli improvements: - cli/cli#11161 (pinned version) - cli/cli#11127 (GHAS exclusion) - cli/cli#11370 (auto-regenerate)
1 parent f347720 commit 3ee7234
Copy full SHA for 3ee7234

4 files changed

+91-8Lines changed: 91 additions & 8 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/code-scanning.yml‎

Copy file name to clipboardExpand all lines: .github/workflows/code-scanning.yml
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ jobs:
4646
queries: "" # Default query suite
4747
packs: github/ccr-${{ matrix.language }}-queries
4848
config: |
49+
paths-ignore:
50+
- third-party
51+
- third-party-licenses.*.md
4952
default-setup:
5053
org:
5154
model-packs: [ ${{ github.event.inputs.code_scanning_codeql_packs }} ]
Collapse file
+71-5Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,87 @@
1-
# Create a github action that runs the license check script and fails if it exits with a non-zero status
1+
# Automatically fix license files on PRs that need updates
2+
# Instead of just failing, this workflow pushes the fix and comments on the PR
23

34
name: License Check
4-
on: [push, pull_request]
5+
on:
6+
pull_request:
7+
paths:
8+
- "**.go"
9+
- go.mod
10+
- go.sum
11+
- ".github/licenses.tmpl"
12+
- "script/licenses*"
13+
- "third-party-licenses.*.md"
14+
- "third-party/**"
515
permissions:
6-
contents: read
16+
contents: write
17+
pull-requests: write
718

819
jobs:
920
license-check:
1021
runs-on: ubuntu-latest
22+
# Don't run on forks (they can't push back) or dependabot (has its own token)
23+
if: github.event.pull_request.head.repo.full_name == github.repository
1124

1225
steps:
1326
- name: Check out code
1427
uses: actions/checkout@v6
28+
with:
29+
ref: ${{ github.head_ref }}
30+
# Need full history for push
31+
fetch-depth: 0
1532

1633
- name: Set up Go
1734
uses: actions/setup-go@v6
1835
with:
1936
go-version-file: "go.mod"
20-
- name: check licenses
21-
run: ./script/licenses-check
37+
38+
# actions/setup-go does not setup the installed toolchain to be preferred over the system install,
39+
# which causes go-licenses to raise "Package ... does not have module info" errors.
40+
# For more information, https://github.com/google/go-licenses/issues/244#issuecomment-1885098633
41+
- name: Regenerate licenses
42+
run: |
43+
export GOROOT=$(go env GOROOT)
44+
export PATH=${GOROOT}/bin:$PATH
45+
./script/licenses
46+
47+
- name: Check for changes
48+
id: changes
49+
run: |
50+
if git diff --exit-code; then
51+
echo "changed=false" >> $GITHUB_OUTPUT
52+
echo "✅ License files are up to date"
53+
else
54+
echo "changed=true" >> $GITHUB_OUTPUT
55+
echo "📝 License files need updating"
56+
git diff --stat
57+
fi
58+
59+
- name: Commit and push fixes
60+
if: steps.changes.outputs.changed == 'true'
61+
run: |
62+
git config --local user.name "github-actions[bot]"
63+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
64+
git add third-party third-party-licenses.*.md
65+
git commit -m "chore: regenerate third-party licenses"
66+
git push
67+
68+
- name: Comment on PR
69+
if: steps.changes.outputs.changed == 'true'
70+
uses: actions/github-script@v7
71+
with:
72+
script: |
73+
github.rest.issues.createComment({
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
issue_number: context.issue.number,
77+
body: `## 📜 License files updated
78+
79+
I noticed the third-party license files were out of date and pushed a fix to this PR.
80+
81+
**What changed:** Dependencies were added, removed, or updated, which requires regenerating the license documentation.
82+
83+
**What I did:** Ran \`./script/licenses\` and committed the result.
84+
85+
Please pull the latest changes before pushing again.`
86+
})
87+
Collapse file

‎script/licenses‎

Copy file name to clipboardExpand all lines: script/licenses
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515

1616
set -e
1717

18-
go install github.com/google/go-licenses@latest
18+
# Pinned version for CI reproducibility, latest for local development
19+
# See: https://github.com/cli/cli/pull/11161
20+
if [ "$CI" = "true" ]; then
21+
go install github.com/google/go-licenses@5348b744d0983d85713295ea08a20cca1654a45e # v2.0.1
22+
else
23+
go install github.com/google/go-licenses@latest
24+
fi
1925

2026
rm -rf third-party
2127
mkdir -p third-party
Collapse file

‎script/licenses-check‎

Copy file name to clipboard
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/bin/bash
22

3-
go install github.com/google/go-licenses@latest
3+
# Pinned version for CI reproducibility, latest for local development
4+
# See: https://github.com/cli/cli/pull/11161
5+
if [ "$CI" = "true" ]; then
6+
go install github.com/google/go-licenses@5348b744d0983d85713295ea08a20cca1654a45e # v2.0.1
7+
else
8+
go install github.com/google/go-licenses@latest
9+
fi
410

511
for goos in linux darwin windows ; do
612
# Note: we ignore warnings because we want the command to succeed, however the output should be checked
@@ -10,12 +16,14 @@ for goos in linux darwin windows ; do
1016
# depending on the license.
1117
GOOS="${goos}" GOFLAGS=-mod=mod go-licenses report ./... --template .github/licenses.tmpl > third-party-licenses.${goos}.copy.md || echo "Ignore warnings"
1218
if ! diff -s third-party-licenses.${goos}.copy.md third-party-licenses.${goos}.md; then
13-
printf "License check failed.\n\nPlease update the license file by running \`.script/licenses\` and committing the output."
19+
printf "License check failed for %s.\n\nPlease update the license file by running \`./script/licenses\` and committing the output.\n" "${goos}"
1420
rm -f third-party-licenses.${goos}.copy.md
1521
exit 1
1622
fi
1723
rm -f third-party-licenses.${goos}.copy.md
1824
done
1925

26+
echo "License check passed for all platforms."
27+
2028

2129

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.