Skip to content

Commit ceb082a

Browse files
Merge branch 'main' into dependabot/go_modules/github.com/google/jsonschema-go-0.4.2
2 parents 06ca0ec + 4f064a3 commit ceb082a

File tree

4 files changed

+114
-8
lines changed

4 files changed

+114
-8
lines changed

.github/workflows/code-scanning.yml

Lines 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 }} ]

.github/workflows/docker-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
# multi-platform images and export cache
5555
# https://github.com/docker/setup-buildx-action
5656
- name: Set up Docker Buildx
57-
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
57+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
5858

5959
# Login against a Docker registry except on PR
6060
# https://github.com/docker/login-action
Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
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+
# Tries to auto-commit the fix, or comments with instructions if push fails
23

34
name: License Check
4-
on: [push, pull_request]
5+
on:
6+
pull_request:
7+
branches:
8+
- main # Only run when PR targets main
9+
paths:
10+
- "**.go"
11+
- go.mod
12+
- go.sum
13+
- ".github/licenses.tmpl"
14+
- "script/licenses*"
15+
- "third-party-licenses.*.md"
16+
- "third-party/**"
517
permissions:
6-
contents: read
18+
contents: write
19+
pull-requests: write
720

821
jobs:
922
license-check:
@@ -12,10 +25,87 @@ jobs:
1225
steps:
1326
- name: Check out code
1427
uses: actions/checkout@v6
28+
with:
29+
ref: ${{ github.head_ref }}
1530

1631
- name: Set up Go
1732
uses: actions/setup-go@v6
1833
with:
1934
go-version-file: "go.mod"
20-
- name: check licenses
21-
run: ./script/licenses-check
35+
36+
# actions/setup-go does not setup the installed toolchain to be preferred over the system install,
37+
# which causes go-licenses to raise "Package ... does not have module info" errors.
38+
# For more information, https://github.com/google/go-licenses/issues/244#issuecomment-1885098633
39+
- name: Regenerate licenses
40+
env:
41+
CI: "true"
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+
continue-on-error: true
50+
run: script/licenses-check
51+
52+
- name: Commit and push fixes
53+
if: steps.changes.outcome == 'failure'
54+
continue-on-error: true
55+
id: push
56+
run: |
57+
git config user.name "github-actions[bot]"
58+
git config user.email "github-actions[bot]@users.noreply.github.com"
59+
git add third-party-licenses.*.md third-party/
60+
git commit -m "chore: regenerate license files
61+
62+
Auto-generated by license-check workflow"
63+
git push
64+
65+
- name: Check if already commented
66+
if: steps.changes.outcome == 'failure' && steps.push.outcome == 'failure'
67+
id: check_comment
68+
uses: actions/github-script@v7
69+
with:
70+
script: |
71+
const { data: comments } = await github.rest.issues.listComments({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
issue_number: context.issue.number
75+
});
76+
77+
const alreadyCommented = comments.some(comment =>
78+
comment.user.login === 'github-actions[bot]' &&
79+
comment.body.includes('## ⚠️ License files need updating')
80+
);
81+
82+
core.setOutput('already_commented', alreadyCommented ? 'true' : 'false');
83+
84+
- name: Comment with instructions if cannot push
85+
if: steps.changes.outcome == 'failure' && steps.push.outcome == 'failure' && steps.check_comment.outputs.already_commented == 'false'
86+
uses: actions/github-script@v7
87+
with:
88+
script: |
89+
await github.rest.issues.createComment({
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
issue_number: context.issue.number,
93+
body: `## ⚠️ License files need updating
94+
95+
The license files are out of date. I tried to fix them automatically but don't have permission to push to this branch.
96+
97+
**Please run:**
98+
\`\`\`bash
99+
script/licenses
100+
git add third-party-licenses.*.md third-party/
101+
git commit -m "chore: regenerate license files"
102+
git push
103+
\`\`\`
104+
105+
Alternatively, enable "Allow edits by maintainers" in the PR settings so I can fix it automatically.`
106+
});
107+
108+
- name: Fail check if changes needed
109+
if: steps.changes.outcome == 'failure'
110+
run: exit 1
111+

script/licenses

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,23 @@
1616
#
1717
# Normally these warnings are packages containing non go code, which may or may not require explicit attribution,
1818
# depending on the license.
19-
2019
set -e
2120

22-
go install github.com/google/go-licenses@latest
21+
# Pinned version for CI reproducibility, latest for local development
22+
# See: https://github.com/cli/cli/pull/11161
23+
if [ "$CI" = "true" ]; then
24+
go install github.com/google/go-licenses@5348b744d0983d85713295ea08a20cca1654a45e # v2.0.1
25+
else
26+
go install github.com/google/go-licenses@latest
27+
fi
28+
29+
# actions/setup-go does not setup the installed toolchain to be preferred over the system install,
30+
# which causes go-licenses to raise "Package ... does not have module info" errors in CI.
31+
# For more information, https://github.com/google/go-licenses/issues/244#issuecomment-1885098633
32+
if [ "$CI" = "true" ]; then
33+
export GOROOT=$(go env GOROOT)
34+
export PATH=${GOROOT}/bin:$PATH
35+
fi
2336

2437
# actions/setup-go does not setup the installed toolchain to be preferred over the system install,
2538
# which causes go-licenses to raise "Package ... does not have module info" errors in CI.

0 commit comments

Comments
 (0)