fix(ci): push detached HEAD to master using HEAD:master refspec #57
No reviewers
Labels
No Label
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sarman/tftsr-devops_investigation#57
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/auto-tag-push-master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
changelogjob checks out$GITHUB_SHAdirectly, leaving git in detached HEAD state with no localmasterbranchgit push origin masterfails:error: src refspec master does not match anygit push origin HEAD:master— explicitly maps current HEAD (detached or not) to the remotemasterbranchTest plan
Commit CHANGELOG.md to masterstep succeedsAutomated PR Review (qwen3-coder-next via liteLLM):\n\nSummary
The PR attempts to fix CI by pushing a detached HEAD to master using the
HEAD:masterrefspec. However, this introduces a critical flaw: in a detached HEAD state (e.g., aftergit checkout FETCH_HEAD),HEADpoints to a commit SHA rather than a branch, and pushingHEAD:mastermay successfully update themasterbranch to that SHA. While technically valid, the workflow does not guarantee that the checkout is of a commit that is actually intended formaster—it merely checks out$GITHUB_SHA, which may be a tag commit, a PR merge, or another non-master target. This risks overwritingmasterwith an unintended commit, especially since the changelog job runs unconditionally on any workflow trigger. Additionally, removing the tag validation beforegit-cliffand changing release creation to only update (no create) breaks idempotent or re-run safety, as missing releases will now fail instead of being created.Findings
[BLOCKER] .gitea/workflows/auto-tag.yml:151 - Using
git push origin HEAD:masterassumes the current detached HEAD commit is a valid, intended tip ofmaster, but$GITHUB_SHAmay be arbitrary (e.g., tag annotation commit, PR branch merge) and not intended formaster.Evidence:
git push origin HEAD:masterFix: Resolve the ref to an intended branch tip (e.g., compute master commit hash explicitly or ensure workflow only runs in contexts where
$GITHUB_SHAis master), or usegit fetch origin master:master && git push origin masterto synchronize to the known remote master.[BLOCKER] .gitea/workflows/auto-tag.yml:117–123: Removed validation (
git rev-parse "refs/tags/...") and release-creation logic, but now fails if release does not exist. The changelog job assumes the release already exists and only attempts to update its body, yet autotag job tags the repo but does not create a Gitea release. This causes the changelog job to fail on first-run (new tag, no release yet).Evidence:
RELEASE_ID=$(curl -sf "$API/releases/tags/$TAG" ... | jq -r '.id')if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then echo "ERROR: Could not find release for tag $TAG"; exit 1; fiFix: Restore release-creation logic or ensure autotag job also creates the Gitea release; do not remove required idempotent creation step.
[WARNING] .gitea/workflows/auto-tag.yml:140: Removed redundant
|| echo "No changes to commit"fallback aftergit commit, but|| echosuppresses exit code and may hide failures. Combined withset -euo pipefail, this is contradictory — ifgit commitfails (e.g., no staged changes), it will exit 0 due to the||, butset -ecould still trigger on failure before the fallback.Evidence:
git commit -m "..." || echo "No changes to commit"Fix: Use
git commit -m "..." || { [ $? -eq 1 ] && echo "No changes to commit" || exit 1; }or remove the fallback and rely onset -e, but prefer explicit handling.Verdict: REQUEST CHANGES
Automated PR Review (qwen3-coder-next via liteLLM):\n\nSummary
The PR attempts to fix CI by using
git push origin HEAD:masterinstead ofgit push origin masterto push to the master branch in a detached HEAD state. However, this change introduces a critical correctness issue:HEAD:masterpushes the current commit as a branch namedmaster, but since the workflow is operating on a detachedFETCH_HEADor specific SHA (notmaster), it may push an incorrect or unrelated commit as themasterbranch. This poses a high risk of corrupting themasterbranch history.Findings
git push origin HEAD:masteris incorrect in detached HEAD state; it pushes the checked-out commit (e.g., a tag reference or arbitrary SHA) asmaster, potentially overwriting or corrupting the realmasterbranch history.Evidence:
git push origin HEAD:masterFix: Replace with
git push origin <branch>:master, where<branch>is explicitly checked out as a local branch namedmaster. E.g., after checkout, rungit branch -f masterthengit push origin master, or usegit fetch origin master:masterto update master directly.Verdict: REQUEST CHANGES
6d8263c5b5to34a69620f5Automated PR Review (qwen3-coder-next via liteLLM):\n\nSummary
The change modifies the git push operation in the
changelogjob to useHEAD:masterrefspec to correctly push from a detached HEAD state. However, a logic flaw exists in the commit handling: it omits the actual commit creation when changes are staged but not committed, potentially leading to uncommitted CHANGELOG.md changes not being pushed despite the push step executing. Additionally, thegit push origin HEAD:mastercommand may push to the correct branch but introduces ambiguity sinceHEADpoints to the commit checkout out ($GITHUB_SHA) rather than the updated working tree.Findings
[WARNING] .gitea/workflows/auto-tag.yml:167 - When
git diff --staged --quietreturns true (no staged changes), the script skips the commit but still proceeds togit push origin HEAD:master, which will push the original commit (pre-changelog update) instead of the current state. This contradicts the intended behavior of pushing the updated CHANGELOG.md.Evidence:
Fix: Wrap the push in the same condition — only push if a commit was made, or use
git diff HEAD~ -- CHANGELOG.mdpost-commit to verify change before pushing.[WARNING] .gitea/workflows/auto-tag.yml:168 - The use of
git push origin HEAD:masterin a detached HEAD state is technically valid but unsafe:HEADrefers to the commit checked out ($GITHUB_SHA) before the commit step, and if the commit was skipped (due to no diff), the pushed state is stale.Evidence:
Fix: Replace with explicit branch-based push: after committing, ensure local
masterbranch points to the new commit, e.g., by updating a local branch reference (or usegit push origin HEAD^{tree}:refs/heads/masteronly ifgit commithappened). Alternatively, commit to a named branch first and push that branch.Verdict: REQUEST CHANGES