Harden and correct keep-alive GHA workflow#141
Merged
Conversation
e1ab7f3 to
d4d13f3
Compare
d4d13f3 to
9b9fe1c
Compare
86c8a09 to
4d6b443
Compare
Several correctness, reliability and maintainability issues were found and fixed in the keep-alive workflow: **Correctness** - Fix default branch detection: `github.event.repository.default_branch` is empty on scheduled runs; now resolved via the GitHub API - Fix `$GITHUB_OUTPUT` references that were unquoted - Fix branch strategy: the old approach accumulated commits on the `keep-alive-workflow` branch across runs; now always resets to the tip of the default branch before force-pushing a single empty commit - Fix PR strategy: `gh pr reopen` fails after a force push because GitHub considers the head branch changed; replaced the reopen/close cycle with keeping a single PR permanently open - Fix jq returning literal null: add `// empty` so missing values produce an empty string instead - Remove `2>/dev/null` from `gh` calls, which was silently swallowing errors **Reliability** - No `set -euo pipefail` was present in any run block, allowing intermediate command failures to be silently swallowed. Added to all three blocks. - Add explicit `git fetch origin` before checkout, since `actions/checkout` with `fetch-depth: 1` does not reliably establish remote tracking refs - Add guard to fail fast if the API returns an empty default branch - Add numeric validation of the parsed PR number - Add `concurrency` group to prevent simultaneous runs - Add `workflow_dispatch` bypass to always run keep-alive on manual triggers - Add a new step that explicitly re-enables all scheduled workflows via the GitHub API (`PUT /enable`), resetting their individual 60-day inactivity timers as a belt-and-suspenders measure alongside the branch push - Replace process substitution `<(...)` with command substitution `$(...)` in the enable step so `set -e` correctly propagates API failures **Simplification** - Hoist `GH_TOKEN`, `GH_REPO`, and `BRANCH_NAME` to job-level `env` to reduce duplication across steps - Split the two monolithic steps into three focused ones: enable workflows, push branch, open PR - Replace `issues: read` (unused) with `actions: write` (required for API enablement) - Rename branch from `keep-alive-workflow` to `keep-workflows-alive` - Add build status badge and an important notice to the PR body
4d6b443 to
0491e83
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several correctness, reliability and maintainability issues were found and fixed in the keep-alive workflow:
Correctness
github.event.repository.default_branchis empty on scheduled runs; now resolved via the GitHub API$GITHUB_OUTPUTreferences that were unquotedkeep-alive-workflowbranch across runs; now always resets to the tip of the default branch before force-pushing a single empty commitgh pr reopenfails after a force push because GitHub considers the head branch changed; replaced the reopen/close cycle with keeping a single PR permanently open// emptyso missing values produce an empty string instead2>/dev/nullfromghcalls, which was silently swallowing errorsReliability
set -euo pipefailwas present in any run block, allowing intermediate command failures to be silently swallowed. Added to all three blocks.git fetch originbefore checkout, sinceactions/checkoutwithfetch-depth: 1does not reliably establish remote tracking refsconcurrencygroup to prevent simultaneous runsworkflow_dispatchbypass to always run keep-alive on manual triggersPUT /enable), resetting their individual 60-day inactivity timers as a belt-and-suspenders measure alongside the branch push<(...)with command substitution$(...)in the enable step soset -ecorrectly propagates API failuresSimplification
GH_TOKEN,GH_REPO, andBRANCH_NAMEto job-levelenvto reduce duplication across stepsissues: read(unused) withactions: write(required for API enablement)keep-alive-workflowtokeep-workflows-alive