Skip to content

fix(sync-actions): create tag when no changes; tag merge commit when PR merges#19

Merged
pelikhan merged 3 commits intomainfrom
copilot/update-sync-actions-yml
Mar 11, 2026
Merged

fix(sync-actions): create tag when no changes; tag merge commit when PR merges#19
pelikhan merged 3 commits intomainfrom
copilot/update-sync-actions-yml

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

"Create tag" was gated on changed == 'true', so tags were never created on no-op syncs. When a PR was created, the tag pointed to the sync branch HEAD instead of the merge commit on main.

Changes

  • Condition: Removed && steps.create-pr.outputs.changed == 'true' from the "Create tag" step — tag is now created regardless of whether a PR was needed.
  • Correct commit: When a PR was merged, fetch and reset to origin/main before tagging so the tag lands on the merge commit, not the stale branch HEAD:
    git fetch origin main
    git checkout -B main origin/main

Copilot AI and others added 3 commits March 11, 2026 15:02
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review March 11, 2026 15:13
Copilot AI review requested due to automatic review settings March 11, 2026 15:13
@pelikhan pelikhan merged commit e2e40fa into main Mar 11, 2026
4 checks passed
@pelikhan pelikhan deleted the copilot/update-sync-actions-yml branch March 11, 2026 15:13

# When a PR was created and merged, we need to pull the merge commit from main
# because the working directory is still on the sync branch.
if [[ "${{ steps.create-pr.outputs.changed }}" == "true" ]]; then
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the sync-actions GitHub Actions workflow to create tags after syncing actions from github/gh-aw, including logic to tag the merge result rather than the sync branch.

Changes:

  • Adjusts the “Create tag” step condition to run when should_create_tag is true.
  • Adds logic to fetch and checkout main before tagging when a sync PR was created/merged.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +337 to +342
# When a PR was created and merged, we need to pull the merge commit from main
# because the working directory is still on the sync branch.
if [[ "${{ steps.create-pr.outputs.changed }}" == "true" ]]; then
echo "PR was merged — fetching main to tag the merge commit..."
git fetch origin main
git checkout -B main origin/main
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tagging by checking out origin/main after the PR merge can tag the wrong commit if other commits land on main between the merge and this step. To ensure the tag points to the sync PR’s merge commit, capture the PR’s mergeCommit SHA (e.g., via gh pr view) and checkout/tag that specific SHA instead of origin/main HEAD.

Suggested change
# When a PR was created and merged, we need to pull the merge commit from main
# because the working directory is still on the sync branch.
if [[ "${{ steps.create-pr.outputs.changed }}" == "true" ]]; then
echo "PR was merged — fetching main to tag the merge commit..."
git fetch origin main
git checkout -B main origin/main
# When a PR was created and merged, we need to tag the merge commit for that PR
# rather than whatever commit happens to be at the tip of main when this step runs.
if [[ "${{ steps.create-pr.outputs.changed }}" == "true" ]]; then
echo "PR was merged — resolving merge commit SHA to tag..."
PR_NUMBER="${{ steps.create-pr.outputs.pr_number }}"
if [[ -z "$PR_NUMBER" ]]; then
echo "Error: PR number not available; cannot determine merge commit to tag." >&2
exit 1
fi
# Ensure gh is authenticated. Prefer an existing GH_TOKEN/GITHUB_TOKEN if set.
if [[ -z "${GH_TOKEN:-}" && -n "${GITHUB_TOKEN:-}" ]]; then
export GH_TOKEN="$GITHUB_TOKEN"
fi
MERGE_COMMIT_SHA="$(gh pr view "$PR_NUMBER" --json mergeCommit --jq '.mergeCommit.oid')"
if [[ -z "$MERGE_COMMIT_SHA" || "$MERGE_COMMIT_SHA" == "null" ]]; then
echo "Error: Could not determine merge commit SHA for PR #$PR_NUMBER." >&2
exit 1
fi
echo "Fetching and checking out merge commit $MERGE_COMMIT_SHA for PR #$PR_NUMBER..."
git fetch origin
git checkout "$MERGE_COMMIT_SHA"

Copilot uses AI. Check for mistakes.
Comment on lines 331 to 333
- name: Create tag
if: steps.resolve-ref.outputs.should_create_tag == 'true' && steps.create-pr.outputs.changed == 'true'
if: steps.resolve-ref.outputs.should_create_tag == 'true'
run: |
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Create tag step now runs whenever should_create_tag == 'true', even when steps.create-pr.outputs.changed is false. Since the script force-deletes and re-creates the annotated tag, re-running the workflow with no file changes will still rewrite the tag object (and may trigger downstream automation). Consider either restoring the changed == 'true' guard, or making tag creation idempotent by skipping delete/recreate when the existing tag already points to the intended commit.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants