fix(ci): prevent duplicate Update API Client PRs (HYBIM-922) - #139
Conversation
Use a static branch name instead of one including the run ID, so force-pushing to it updates an existing open PR rather than spawning a new one each run. The PR creation step now checks for an existing open PR and skips creation if one is found. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
fercor-cisco
left a comment
There was a problem hiding this comment.
🤖 This review was generated by the Astra agent (claude-opus-4-8). It may contain mistakes.
Verdict: request_changes — Static branch name breaks the "nothing was committed this run" guard in the PR-creation step, which can resurrect spurious PRs or fail the job; force-push also silently discards manual fixes on the open branch.
| if ! git ls-remote --exit-code origin refs/heads/$BRANCH_NAME > /dev/null 2>&1; then | ||
| echo "No branch to create PR from — nothing was committed" | ||
| exit 0 | ||
| fi | ||
| gh pr create -B main -H $BRANCH_NAME --label 'dependencies' --title 'Update API Client' --body 'Fix any breaking changes if this pull request fails to deploy' | ||
| EXISTING_PR=$(gh pr list --base main --head $BRANCH_NAME --state open --json number --jq '.[0].number') | ||
| if [ -n "$EXISTING_PR" ]; then | ||
| echo "PR #$EXISTING_PR already open for branch $BRANCH_NAME — updated via force push" | ||
| else | ||
| gh pr create -B main -H $BRANCH_NAME --label 'dependencies' --title 'Update API Client' --body 'Fix any breaking changes if this pull request fails to deploy' |
There was a problem hiding this comment.
🟠 major (bug): This step's guard no longer means what it used to. Previously the branch name was unique per run (...-{date}-{run_id}), so git ls-remote refs/heads/$BRANCH_NAME succeeding was a reliable proxy for "this run actually committed and pushed". With a static branch name, ls-remote now succeeds whenever the branch exists from ANY prior run, even when the current run made no spec changes (step 1 hit the exit 0 at line 58-60 and never pushed).
Concrete failure: a previous run created the branch + PR, the PR was later closed or merged but the remote branch was not deleted. Today's scheduled run finds no spec changes, so step 1 doesn't push. Step 2 still runs (no if: gate, no dependency on step 1), ls-remote passes because the stale branch exists, EXISTING_PR is empty (old PR is closed), so gh pr create fires — either resurrecting a PR from stale content or failing with "No commits between main and ..." when the branch equals main. Either way this reintroduces the duplicate/spurious-PR behavior the ticket set out to eliminate, or turns the job red.
Fix: have step 1 emit an explicit output (e.g. echo "changed=true" >> "$GITHUB_OUTPUT" after a successful push, via a step id) and gate this step on it (if: steps.<id>.outputs.changed == 'true'), rather than inferring "did we commit" from branch existence.
🤖 Generated by the Astra agent
|
Pushing back on the Claude review:
This is fine, these PRs are supposed to be automated, not manually edited. |
…-922) The previous ls-remote guard was unreliable with a static branch name — it would pass even when the current run made no spec changes, potentially resurrecting a closed PR or failing with "no commits between main and branch". Fix: emit `changed=true` output only after a successful push, and gate the PR creation step on `steps.regenerate.outputs.changed == 'true'`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
10eddb4 to
950d8d2
Compare
|
Verdict: approve — the blocker from the earlier review is resolved and the logic is correct. The core fix is sound:
A stale branch lingering from a closed/merged prior run can no longer trigger a spurious Remaining branches check out:
Minor points (non-blocking)
None of these block merge. |
|
@etserend this seems to be dead code, do you want to remove this before merging?
|
Will clean up in this PR. |
The step's only consumer was the old dynamic branch name which included steps.date.outputs.date. Now that the branch name is static, the step is unused. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
${{ github.run_id }}, so every workflow run created a new unique branch and PRchore/splunk-ao-automation/update-api-clientand force-push to itgh pr createif one already existsTest plan
regenerate-api-clientworkflow manually from this branch and verify it runs without errorsJira: https://splunk.atlassian.net/browse/HYBIM-922
🤖 Generated with Claude Code