-
Notifications
You must be signed in to change notification settings - Fork 40
chore: ♻️ Dynamic discovery of modules to dependabot tidy #792
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 |
|---|---|---|
|
|
@@ -10,15 +10,20 @@ name: Dependabot go mod tidy | |
| on: | ||
| pull_request: | ||
| paths: | ||
| - "authbridge/authlib/go.mod" | ||
| - "authbridge/authlib/go.sum" | ||
| - "authbridge/cmd/*/go.mod" | ||
| - "authbridge/cmd/*/go.sum" | ||
| - "authbridge/**/go.mod" | ||
| - "authbridge/**/go.sum" | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| # A Dependabot force-push (rebase) landing while a tidy is in flight would | ||
| # otherwise produce two jobs racing to push the same ref; the loser fails | ||
| # non-fast-forward. Cancel the older run — its tidy is already superseded. | ||
| concurrency: | ||
| group: dependabot-tidy-${{ github.head_ref }} | ||
| cancel-in-progress: true | ||
|
Comment on lines
+23
to
+25
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. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
file=".github/workflows/dependabot-tidy.yml"
printf '%s\n' '--- workflow ---'
cat -n "$file"
printf '%s\n' '--- related workflow references ---'
rg -n --glob '*.yml' --glob '*.yaml' 'dependabot-tidy|gh pr close|gh pr reopen|concurrency:|cancel-in-progress' .githubRepository: rossoctl/cortex Length of output: 3940 🌐 Web query:
💡 Result: When a GitHub Actions workflow run is triggered within a concurrency group configured with Citations:
🌐 Web query:
💡 Result: The GitHub CLI (gh) provides dedicated commands to close and reopen pull requests directly from the terminal. Both commands accept the pull request number, URL, or branch name as the target [1][2]. gh pr close The gh pr close command closes an existing pull request [1]. Usage: gh pr close { | | } [flags] Options: -c, --comment: Adds a closing comment to the pull request [1]. -d, --delete-branch: Deletes the local and remote branch associated with the pull request after closing it [1]. gh pr reopen The gh pr reopen command reopens a previously closed pull request [2]. Usage: gh pr reopen { | | } [flags] Options: -c, --comment: Adds a reopening comment to the pull request [2]. Both commands support the global -R or --repo flag, which allows you to specify a repository in [HOST/]OWNER/REPO format if you are not working within the target repository's directory [1][2]. Citations: 🌐 Web query:
💡 Result: In the context of workflow automation and CI/CD pipelines, such as GitHub Actions, if a job condition evaluates to true, the job is allowed to execute or continue running [1]. Specifically, in systems like GitHub Actions: - Execution: When a workflow or job is evaluated, the system checks the defined condition (e.g., using an if statement) [1]. If the condition evaluates to true, the job or step proceeds as defined [1]. If it evaluates to false, the job or step is typically skipped [1]. - Cancellation Scenarios: During a workflow cancellation process, the system re-evaluates if-conditions for active jobs [1]. If a job’s condition evaluates to true (such as when using the always function), the job will ignore the cancellation request and continue to run [1]. Conversely, if the condition evaluates to false, the job is marked for cancellation and proceeds through the termination sequence [1]. Citations: 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
p = Path(".github/workflows/dependabot-tidy.yml")
text = p.read_text()
for i, line in enumerate(text.splitlines(), 1):
if i in range(23, 26) or i in range(27, 31) or i in range(73, 83):
print(f"{i:4}: {line}")
PYRepository: rossoctl/cortex Length of output: 951 🏁 Script executed: #!/bin/bash
set -eu
url='https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-cancellation'
body="$(curl -LfsS "$url")"
printf '%s\n' "$body" | sed 's/<[^>]*>/ /g' | tr -s '[:space:]' ' ' | grep -o -E '.{0,220}(re-evaluat|condition evaluates|always\(\)|cancel).{0,320}' | head -n 20Repository: rossoctl/cortex Length of output: 10609 🌐 Web query:
💡 Result: In GitHub Actions, an implicit Citations:
🌐 Web query:
💡 Result: In the context of GitHub Actions, there is no technical function named cancellation success. It appears you may be referring to the interaction between job status functions—specifically success, cancelled, and always—and the job cancellation mechanism [1][2][3]. When a GitHub Actions job is cancelled, the runner triggers a cancellation token to stop running steps [4][5]. The following behaviors apply regarding job status functions: 1. success vs!cancelled: By default, steps run only if the previous steps succeeded (equivalent to an implicit if: success condition) [3]. If a job is cancelled, success evaluates to false, causing subsequent steps to be skipped [3]. If you want a job or step to execute even if the job was cancelled, you should use if: ${{!cancelled }} instead of always where possible, as always can lead to tasks that are difficult to stop [3]. 2. Handling Cancellation: When a job is cancelled, the runner attempts to re-evaluate the if conditions for currently running steps [3][6]. If a step has a condition like always, it may continue to run despite the cancellation [3]. This is why!cancelled is generally recommended over always to ensure that cleanup or post-processing tasks run without making the job effectively uncancellable [3]. 3. Composite Actions: There have been known issues where composite action steps might not receive the cancellation signal correctly or where status functions like success behave unexpectedly due to how composite actions share cancellation tokens with their parent steps [4][2]. Fixes have been implemented to ensure that composite steps are properly interrupted when a job is cancelled [4]. If you are experiencing issues where a step is not behaving as expected during cancellation, ensure you are using the appropriate condition for your requirements: - success: Runs only if the job has not failed or been cancelled [2][3]. - cancelled: Returns true if the job was cancelled [2]. -!cancelled: Recommended for tasks that must run even if the job is cancelled (e.g., cleanup) [3]. - always: Runs regardless of status, but use with caution as it can make steps hard to terminate [3]. Citations:
🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
path = Path(".github/workflows/dependabot-tidy.yml")
lines = path.read_text().splitlines()
def line_containing(fragment):
return next((i + 1 for i, line in enumerate(lines) if fragment in line), None)
concurrency = line_containing("cancel-in-progress: true")
job_if = line_containing("if: github.actor == 'dependabot[bot]'")
close = line_containing("gh pr close")
reopen = line_containing("gh pr reopen")
step_if = line_containing("if: steps.commit.outputs.changed == 'true'")
assert concurrency and job_if and close and reopen and step_if
assert close < reopen
job_condition = lines[job_if - 1].split("if:", 1)[1].strip()
step_condition = lines[step_if - 1].split("if:", 1)[1].strip()
status_functions = ("success(", "always(", "cancelled(", "failure(")
print(f"concurrency cancellation enabled: {concurrency}")
print(f"job condition: {job_condition}")
print(f"job condition has explicit status function: {any(x in job_condition for x in status_functions)}")
print(f"retrigger condition: {step_condition}")
print(f"retrigger condition has explicit status function: {any(x in step_condition for x in status_functions)}")
print(f"close command line: {close}")
print(f"reopen command line: {reopen}")
print("close precedes reopen: true")
PYRepository: rossoctl/cortex Length of output: 482 Make the CI re-trigger safe under cancellation. If cancellation occurs between 🤖 Prompt for AI AgentsSource: MCP tools |
||
|
|
||
| jobs: | ||
| tidy: | ||
| if: github.actor == 'dependabot[bot]' | ||
|
|
@@ -39,17 +44,12 @@ jobs: | |
| - name: Run go mod tidy in every module | ||
| run: | | ||
| set -euo pipefail | ||
| for mod in \ | ||
| authbridge/authlib \ | ||
| 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 | ||
| while IFS= read -r -d '' go_mod; do | ||
| mod=$(dirname "$go_mod") | ||
| echo "::group::go mod tidy in $mod" | ||
| (cd "$mod" && go mod tidy) | ||
| echo "::endgroup::" | ||
| done < <(find authbridge -name go.mod -not -path '*/demos/*' -print0 | sort -z) | ||
|
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 — The exit status of That is the same failure shape as the mapfile -d '' mods < <(find authbridge -name go.mod -not -path '*/demos/*' -print0 | sort -z)
if [ ${#mods[@]} -eq 0 ]; then
echo "::error::no go.mod files found under authbridge/ — module discovery is broken"
exit 1
fi
for go_mod in "${mods[@]}"; do
mod=$(dirname "$go_mod")
echo "::group::go mod tidy in $mod"
(cd "$mod" && go mod tidy)
echo "::endgroup::"
doneSame null-delimited safety, but zero matches now fails instead of passing quietly. |
||
|
|
||
| - name: Commit and push if changed | ||
| id: commit | ||
|
|
||
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.
nit — this can land the tidy commit without the CI re-trigger. Flagging because it follows from the concurrency group I suggested on #789, so it is my edge case to own.
The push (line ~76) and the close/reopen re-trigger (lines 81-82) are two non-atomic steps.
cancel-in-progress: trueadds a window where a run pushes its tidy commit and is then cancelled before re-triggering CI. The superseding run tidies, finds nothing left to change, setschanged=false, and returns early — so close/reopen never happens and the PR sits with the fix applied but its checks never re-run.Narrow: it needs a Dependabot push inside a seconds-wide window, and that push to preserve the just-created commit rather than rebase it away. In the common case the comment's reasoning is exactly right — the older tidy is superseded and cancelling is correct.
Not worth restructuring for on its own. It mostly disappears if the close/reopen workaround is replaced with a Dependabot-secret token (the remaining #789 suggestion), since a push under a non-
GITHUB_TOKENidentity re-triggers workflows by itself and the two-step sequence collapses into one.