-
Notifications
You must be signed in to change notification settings - Fork 40
fix: 🐛 dependabot-tidy workflow with stale cmd modules #789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| name: Dependabot go mod tidy | ||
|
|
||
| # When Dependabot bumps a dep in authbridge/authlib, the cmd/* modules' | ||
| # go.sum files go stale — they reference authlib's transitive deps via | ||
| # replace directives but Dependabot only tidies the directory it updated. | ||
| # CI's `go fmt`/`go vet` then fails with "updates to go.mod needed". | ||
| # | ||
| # Runs only on Dependabot PRs. Human PRs are untouched. | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "authbridge/authlib/go.mod" | ||
| - "authbridge/authlib/go.sum" | ||
| - "authbridge/cmd/*/go.mod" | ||
| - "authbridge/cmd/*/go.sum" | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| tidy: | ||
| if: github.actor == 'dependabot[bot]' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| env: | ||
| GOWORK: "off" | ||
| GOTOOLCHAIN: local | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
|
|
||
| - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 | ||
| with: | ||
| go-version-file: authbridge/authlib/go.mod | ||
|
|
||
| - name: Run go mod tidy in every module | ||
| run: | | ||
| set -euo pipefail | ||
| for mod in \ | ||
| authbridge/authlib \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion — this list is already two modules behind, and it is the one thing I would fix before merging. On
Both have a single-line
Deriving the list removes the drift permanently rather than deferring it: while IFS= read -r gomod; do
mod=$(dirname "$gomod")
echo "::group::go mod tidy in $mod"
(cd "$mod" && go mod tidy)
echo "::endgroup::"
done < <(find authbridge -name go.mod -not -path '*/demos/*' | sort)That also drops the |
||
| authbridge/cmd/authbridge-proxy \ | ||
| authbridge/cmd/authbridge-envoy \ | ||
| authbridge/cmd/abctl; do | ||
| if [ -f "$mod/go.mod" ]; then | ||
| echo "::group::go mod tidy in $mod" | ||
| (cd "$mod" && go mod tidy) | ||
| echo "::endgroup::" | ||
| fi | ||
| done | ||
|
|
||
| - name: Commit and push if changed | ||
| id: commit | ||
| run: | | ||
| set -euo pipefail | ||
| if [ -z "$(git status --porcelain)" ]; then | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| echo "No changes after tidy." | ||
| exit 0 | ||
| fi | ||
| git config user.name "dependabot[bot]" | ||
| git config user.email "49699333+dependabot[bot]@users.noreply.github.com" | ||
| git add -A | ||
| git commit -s -m "chore: go mod tidy across modules | ||
|
|
||
| Auto-tidied by dependabot-tidy workflow to keep cmd/* go.sum | ||
| files in sync with authlib after a Dependabot bump." | ||
| git push | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # Commits pushed with the default GITHUB_TOKEN do not re-trigger other | ||
| # workflows. Close + reopen forces CI to re-run on the new commit. | ||
| # (@dependabot rebase would discard our tidy commit, so it's not usable.) | ||
| - name: Re-trigger CI on the PR | ||
| if: steps.commit.outputs.changed == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| gh pr close "${{ github.event.pull_request.number }}" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion — close+reopen works, but it is a Dependabot signal and there is a cleaner path. Closing a Dependabot PR is something Dependabot acts on: it records the closure and by default will not recreate that same update. Reopening immediately should restore it, but that is worth confirming rather than assuming, because the failure mode is silent — an update that stops being proposed. The supported alternative follows from the same doc that makes this workflow viable at all: Actions secrets are unavailable to Dependabot-triggered runs, but Dependabot secrets are. A PAT or GitHub App token stored there and used for the push produces commits under a non- If you keep close+reopen, the comment explaining why |
||
| gh pr reopen "${{ github.event.pull_request.number }}" | ||
|
Comment on lines
+76
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
repo="$(gh repo view --json nameWithOwner --jq .nameWithOwner)"
# Verify whether fork-style pull request workflows can receive write tokens.
gh api "repos/${repo}/actions/permissions/fork-pr-workflows-private-repos" \
--jq '{run_workflows_from_fork_pull_requests, send_write_tokens_to_workflows, require_approval_for_fork_pr_workflows}'Repository: rossoctl/cortex Length of output: 405 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- workflow ---'
cat -n .github/workflows/dependabot-tidy.yml
printf '%s\n' '--- related workflow triggers and permissions ---'
rg -n --glob '.github/workflows/*.yml' --glob '.github/workflows/*.yaml' \
'pull_request|workflow_run|permissions:|actions:|contents:|pull-requests:' .github/workflowsRepository: rossoctl/cortex Length of output: 6836 🌐 Web query:
💡 Result: By design, GitHub prevents recursive workflow execution by restricting the triggers of the default GITHUB_TOKEN [1][2]. When a workflow uses the GITHUB_TOKEN to perform actions such as creating or updating a pull request, subsequent pull_request events (specifically with the opened, synchronize, or reopened activity types) do not automatically trigger new workflow runs [1][3][2]. Instead, these events create workflow runs that are placed in an approval-required state [1][4]. A user with write access to the repository must manually approve these runs from the pull request interface before they will execute [1][2]. Other pull_request activity types, such as labeled or closed, do not trigger workflow runs at all when caused by the GITHUB_TOKEN [1][2]. Regarding Dependabot and automation requirements: 1. Recursive Prevention: This behavior is a security feature to prevent infinite loops (e.g., a workflow that triggers a push, which triggers the same workflow) [1][2]. 2. Overcoming Restrictions: To allow workflows to trigger automatically without manual approval, you must use a Personal Access Token (PAT) or a GitHub App installation access token instead of the GITHUB_TOKEN [1][2]. 3. Dependabot Specifics: Dependabot-initiated workflows have additional limitations, such as read-only GITHUB_TOKEN permissions by default and restricted access to repository secrets [5][6]. If you are using the pull_request event for Dependabot automation, your workflow may lack the necessary permissions or access to secrets [7][8]. Many developers use the pull_request_target event as an alternative when they need to perform actions (like auto-approving a PR) in the context of the base branch, which grants access to secrets and allows for more robust automation [8]. If you are encountering stuck workflows or require specific automations (like auto-merging or auto-approving), it is common practice to use a PAT with appropriate repository permissions [9][7][10]. Ensure that your workflow permissions (using the permissions key) are also explicitly set to provide the necessary scope (e.g., pull-requests: write) if you continue to use the GITHUB_TOKEN [7][6]. Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- CI workflow ---'
cat -n .github/workflows/ci.yaml
printf '%s\n' '--- pull-request workflows ---'
for file in .github/workflows/pr-verifier.yml .github/workflows/build.yaml .github/workflows/security-scans.yaml; do
if [ -f "$file" ]; then
printf '\n--- %s ---\n' "$file"
cat -n "$file"
fi
done
printf '%s\n' '--- recent Dependabot tidy runs ---'
gh api 'repos/rossoctl/cortex/actions/workflows/dependabot-tidy.yml/runs?per_page=20' \
--jq '.workflow_runs[] | {
id, event, status, conclusion, created_at, updated_at,
head_branch, head_sha, pull_requests: [.pull_requests[]?.number]
}'
printf '%s\n' '--- recent pull-request runs ---'
gh api 'repos/rossoctl/cortex/actions/runs?event=pull_request&per_page=30' \
--jq '.workflow_runs[] | {
name, id, event, status, conclusion, created_at,
head_branch, head_sha, pull_requests: [.pull_requests[]?.number]
}'Repository: rossoctl/cortex Length of output: 28223 🌐 Web query:
💡 Result: In GitHub Actions, workflow runs triggered by the repository's GITHUB_TOKEN generally do not trigger further workflows to prevent infinite recursion [1][2][3]. However, there is a specific exception for the pull_request event. When a workflow uses the GITHUB_TOKEN to create or update a pull request with the opened, synchronize, or reopened activity types, the resulting pull_request event will trigger a workflow run, but it will be placed in an approval-required state [1][2][3]. When this happens, the pull request interface will display a banner in the merge box, and a user with write access to the repository must manually select Approve workflows to run to initiate the workflow [1][2][4]. Other pull_request activity types (such as labeled, edited, or closed) do not trigger new workflow runs even if they are performed via the GITHUB_TOKEN [1][3]. If you require workflow runs triggered by automation to execute automatically without manual approval, you must use a different authentication method, such as a GitHub App installation access token or a personal access token (PAT), instead of the GITHUB_TOKEN when performing the action that creates or updates the pull request [1][2][3]. The workflow_dispatch and repository_dispatch events are also exceptions and will always create workflow runs when triggered by the GITHUB_TOKEN [2][3][4]. Citations:
Use a non- The 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion — no
concurrencygroup, and the push has no retry.Two
synchronizeevents landing close together on the same branch (Dependabot force-pushing a rebase while a tidy run is in flight) give two jobs pushing to the same ref. The loser gets a non-fast-forward rejection and the run fails — noisy, and on a Dependabot PR nobody is watching for it.Cancelling in-progress is the right posture here: a superseded tidy has nothing worth finishing.