Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions .github/workflows/license-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,30 @@ jobs:

# Check out the actual PR branch so we can push changes back if needed
- name: Check out PR branch
id: pr_branch
env:
GH_TOKEN: ${{ github.token }}
run: gh pr checkout ${{ github.event.pull_request.number }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
if gh pr checkout "$PR_NUMBER"; then
exit 0
fi

state=$(gh pr view "$PR_NUMBER" --json state --jq '.state')
if [[ "$state" == "CLOSED" ]]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "::notice::Pull request is closed; skipping license update."
exit 0
Comment on lines +36 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): A closed pull request whose branch is still checkoutable proceeds through license validation and remediation because the workflow checks the pull request state only after gh pr checkout fails. The workflow can therefore regenerate and push license updates to a closed pull request.

Triggers: When a pull request is closed but its source branch remains available, including a workflow run that continues after the PR is closed.

Suggested fix: Check the pull request state before attempting checkout, or query the state after a successful checkout as well and set skip=true for closed pull requests.

Comment on lines +40 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): A checkout failure for a merged pull request is treated as an unexpected checkout error because the reported state is MERGED, not CLOSED; the workflow therefore fails instead of skipping the already-closed pull request.

Triggers: When the pull request is merged and its branch or pull-request ref can no longer be checked out.

Suggested fix: Treat both CLOSED and MERGED states as skippable, or use the pull request's closed/merged status explicitly.

fi

exit 1
Comment on lines +36 to +47

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Any checkout failure on a pull request whose API state is CLOSED is converted into a successful skipped step, including failures caused by authentication, network, Git, or another checkout problem unrelated to closure. The workflow then passes without reporting the real checkout failure.

Triggers: When a closed pull request encounters a non-closure-related checkout error.

Suggested fix: Preserve the checkout failure unless the failure is known to result from a closed or merged pull request, or validate the relevant PR state before checkout and distinguish other errors.

Suggested change
if gh pr checkout "$PR_NUMBER"; then
exit 0
fi
state=$(gh pr view "$PR_NUMBER" --json state --jq '.state')
if [[ "$state" == "CLOSED" ]]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "::notice::Pull request is closed; skipping license update."
exit 0
fi
exit 1
state=$(gh pr view "$PR_NUMBER" --json state --jq '.state')
if [[ "$state" == "CLOSED" || "$state" == "MERGED" ]]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "::notice::Pull request is closed or merged; skipping license update."
exit 0
fi
gh pr checkout "$PR_NUMBER"


- name: Build UI
if: steps.pr_branch.outputs.skip != 'true'
uses: ./.github/actions/build-ui

- name: Set up Go
if: steps.pr_branch.outputs.skip != 'true'
uses: actions/setup-go@v7
with:
go-version-file: "go.mod"
Expand All @@ -44,6 +60,7 @@ jobs:
# which causes go-licenses to raise "Package ... does not have module info" errors.
# For more information, https://github.com/google/go-licenses/issues/244#issuecomment-1885098633
- name: Regenerate licenses
if: steps.pr_branch.outputs.skip != 'true'
env:
CI: "true"
run: |
Expand All @@ -53,11 +70,12 @@ jobs:

- name: Check for changes
id: changes
if: steps.pr_branch.outputs.skip != 'true'
continue-on-error: true
run: script/licenses-check

- name: Commit and push fixes
if: steps.changes.outcome == 'failure'
if: steps.pr_branch.outputs.skip != 'true' && steps.changes.outcome == 'failure'
continue-on-error: true
id: push
run: |
Expand All @@ -68,7 +86,7 @@ jobs:
git push

- name: Check if already commented
if: steps.changes.outcome == 'failure' && steps.push.outcome == 'failure'
if: steps.pr_branch.outputs.skip != 'true' && steps.changes.outcome == 'failure' && steps.push.outcome == 'failure'
id: check_comment
uses: actions/github-script@v9
with:
Expand All @@ -87,7 +105,7 @@ jobs:
core.setOutput('already_commented', alreadyCommented ? 'true' : 'false');

- name: Comment with instructions if cannot push
if: steps.changes.outcome == 'failure' && steps.push.outcome == 'failure' && steps.check_comment.outputs.already_commented == 'false'
if: steps.pr_branch.outputs.skip != 'true' && steps.changes.outcome == 'failure' && steps.push.outcome == 'failure' && steps.check_comment.outputs.already_commented == 'false'
uses: actions/github-script@v9
with:
script: |
Expand All @@ -111,6 +129,5 @@ jobs:
});

- name: Fail check if changes needed
if: steps.changes.outcome == 'failure'
if: steps.pr_branch.outputs.skip != 'true' && steps.changes.outcome == 'failure'
run: exit 1

Loading