Skip to content

fix: fetch remote branch before pushing CI trigger empty commit to avoid non-fast-forward rejection#23152

Merged
dsyme merged 2 commits intomainfrom
copilot/fix-gh-aw-ci-trigger-token-issue
Mar 26, 2026
Merged

fix: fetch remote branch before pushing CI trigger empty commit to avoid non-fast-forward rejection#23152
dsyme merged 2 commits intomainfrom
copilot/fix-gh-aw-ci-trigger-token-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

When GH_AW_CI_TRIGGER_TOKEN is set and pushSignedCommits creates the PR branch via the GitHub GraphQL createCommitOnBranch mutation, the remote branch tip gets a different SHA than the local branch tip. The subsequent empty commit push is then rejected by git as non-fast-forward, silently swallowed as a warning, and CI never triggers on the PR.

Changes

  • extra_empty_commit.cjs: After adding the ci-trigger remote, fetch the remote branch and reset --hard to it before creating the empty commit. This syncs local HEAD to the API-created remote tip, making the push a valid fast-forward. If fetch/reset fails (e.g. branch not yet on remote), logs a warning and falls back to local HEAD.
await exec.exec("git", ["remote", "add", "ci-trigger", remoteUrl]);

// Sync with remote to handle API-created branches (signed commits via createCommitOnBranch)
try {
  await exec.exec("git", ["fetch", "ci-trigger", branchName]);
  await exec.exec("git", ["reset", "--hard", `ci-trigger/${branchName}`]);
} catch {
  core.info(`Could not sync local branch with remote ${branchName} - will attempt push with local HEAD`);
}

await exec.exec("git", ["commit", "--allow-empty", "-m", message]);
await exec.exec("git", ["push", "ci-trigger", branchName]);
  • extra_empty_commit.test.cjs: Tests verifying fetch + reset --hard are called in the correct order (after remote add, before commit+push), and that the function degrades gracefully when fetch fails.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw -buildtags x_amd64/compile git rev-�� --show-toplevel x_amd64/compile /usr/bin/git -bool tions/setup/js/nrev-parse ache/node/24.14.--show-toplevel git (http block)
  • https://api.github.com/orgs/test-owner/actions/secrets
    • Triggering command: /usr/bin/gh gh api /orgs/test-owner/actions/secrets --jq .secrets[].name 0c12b8082c5f6786node cfg 64/pkg/tool/linudevelopment 05ebed2f72bb4ffc/opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/link . it 64/pkg/tool/linu-importcfg /hom�� git 0c12b8082c5f6786-w 64/pkg/tool/linu-buildmode=exe -bare-uzazvL Initial commit rgo/bin/git 64/pkg/tool/linux_amd64/vet (http block)
  • https://api.github.com/repos/actions/ai-inference/git/ref/tags/v1
    • Triggering command: /usr/bin/gh gh api /repos/actions/ai-inference/git/ref/tags/v1 --jq .object.sha user.name Test User /usr/bin/git se ode_modules/viterev-parse x_amd64/compile git rev-�� --show-toplevel x_amd64/compile /usr/bin/git ub/workflows git 64/bin/git /usr/bin/git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v3
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v3 --jq .object.sha sistency_GoAndJavaScript212681731/001/test-frontmatter-with-env-template-expressions.md /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warn-ifaceassert /usr/bin/git node --conditions development git rev-�� ons-test3162626591 dodHjVTve9Rd /usr/bin/git l ode_modules/viterev-parse 64/pkg/tool/linu--show-toplevel git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v5
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha .go /tmp/go-build355557888/b216/vet.cfg 0/x64/bin/node origin ode_modules/vite/tmp/test-expr-1598671621.js ache/uv/0.11.1/xgithub.token 0/x64/bin/node ve -bool tions/setup/js/node_modules/vitest/suppress-warn-ifaceassert tnet/tools/git -errorsas -ifaceassert -nilfunc tions/setup/js/node_modules/vitestatus (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha Actor: ${{ github.actor }}, Repo: ${{ github.repository }} ache/go/1.25.0/x/tmp/go-build1429002305/b112/vet.cfg /usr/bin/git bbd818c7d325afa2git ode_modules/viterev-parse ache/node/24.14.--show-toplevel git rev-�� --show-toplevel ode_modules/vite.github/workflows/test.md /usr/bin/git -unreachable=falgit .com/repo.git.urrev-parse o git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha --show-toplevel git /usr/bin/git 0059-50196/test-git git ache/node/24.14.--show-toplevel git rev-�� --show-toplevel ache/node/24.14.0/x64/bin/node /usr/bin/git k/_temp/uv-pythogit k/gh-aw/gh-aw/acrev-parse /home/REDACTED/go/--show-toplevel git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v6
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha rhysd/actionlint:latest 64/pkg/tool/linu/tmp/go-build1429002305/b375/vet.cfg /usr/bin/git -e st/suppress-warnrev-parse odules/npm/node_--show-toplevel git -C /tmp/gh-aw-test-runs/20260326-190059-50196/test-3345063812 status /usr/bin/git .github/workflowgit l it git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha --show-toplevel 64/pkg/tool/linux_amd64/compile /usr/bin/git g_.a k/gh-aw/gh-aw/acrev-parse ache/go/1.25.0/x--show-toplevel git rev-�� --show-toplevel ache/go/1.25.0/x64/pkg/tool/linux_amd64/asm /usr/bin/git xfGfCF9kB git k/_temp/ghcca-no--show-toplevel git (http block)
  • https://api.github.com/repos/actions/github-script/git/ref/tags/v8
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha --reverse cfg 64/pkg/tool/linux_amd64/vet HEAD condition-branch-o ache/uv/0.11.1/x/tmp/go-build3341247704/b001/_pkg_.a 64/pkg/tool/linu-trimpath /hom�� tions/setup/js/n-p st/suppress-warnmain 64/pkg/tool/linu-lang=go1.25 -m Initial commit it st/dist/workers/-dwarf=false (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha /js/generate_safe_outputs_tools.cjs st/suppress-warnings.cjs 64/pkg/tool/linux_amd64/vet node --conditions development st/dist/workers//home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warn-ifaceassert /hom�� odules/npm/node_node 0c12b8082c5f6786--conditions ules/.bin/node -b ab261874^ ab261874 ache/node/24.14.-importcfg (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha git cfg 64/pkg/tool/linux_amd64/vet . git /git 64/pkg/tool/linuTest User --ex�� --require cfg 0/x64/bin/node node --conditions development ache/go/1.25.0/x64/pkg/tool/linu--port (http block)
  • https://api.github.com/repos/actions/setup-go/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-go/git/ref/tags/v4 --jq .object.sha -bool -buildtags /usr/bin/git -errorsas -ifaceassert -nilfunc git rev-�� --git-dir -tests /usr/bin/git se l x_amd64/compile git (http block)
  • https://api.github.com/repos/actions/setup-node/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v4 --jq .object.sha test/race-image:v1.0.0 64/pkg/tool/linu-buildtags /usr/bin/git -e st/suppress-warnrev-parse 0/x64/bin/node git chec�� .github/workflows/test.md st/dist/workers/-tests /usr/bin/git se l cfg git (http block)
  • https://api.github.com/repos/actions/upload-artifact/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v4 --jq .object.sha it x_amd64/vet /opt/hostedtoolcache/go/1.25.0/x64/bin/go HEAD dy-branch x_amd64/vet go run runs/20260326-190059-50196/test-3492207175/custom/workflows x_amd64/vet 9002305/b437/vet.cfg c75f3255..HEAD Initial commit x_amd64/vet /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v0.1.2
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v0.1.2 --jq .object.sha 0/x64/lib/node_m-bool l (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v1.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v1.0.0 --jq .object.sha /tmp/go-handler-test-tOvgzu/test.go x_amd64/vet 9002305/b373/vet.cfg /tmp/push-signedgit . run-script/lib/n--show-toplevel go run /tmp/go-handler-test-ck91Fh/test-cwd.go l 0/x64/bin/node c75f3255..HEAD Initial commit x_amd64/vet 0/x64/bin/node (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v1.2.3
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v1.2.3 --jq .object.sha 0059-50196/test-3345063812 x_amd64/vet ache/go/1.25.0/x64/pkg/tool/linux_amd64/vet /tmp/push-signedgit st/suppress-warnrev-parse x_amd64/vet ache/go/1.25.0/x64/pkg/tool/linux_amd64/vet run /tmp/go-handler-test-ck91Fh/test-cwd.go st/dist/workers/forks.js ache/node/24.14.0/x64/bin/node c75f3255..HEAD Initial commit x_amd64/vet /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linuREDACTED (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/1/artifacts
    • Triggering command: /usr/bin/gh gh run download 1 --dir test-logs/run-1 /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vite--conditions x_amd64/compile node --conditions development x_amd64/compile ve -unreachable=false tions/setup/js/node_modules/vitest/suppress-warnings.cjs tions/node_modules/.bin/go extra.txt git de/node/bin/git tions/setup/js/node_modules/vitest/dist/workers//home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warn-ifaceassert (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/12345/artifacts
    • Triggering command: /usr/bin/gh gh run download 12345 --dir test-logs/run-12345 k/gh-aw/gh-aw/actions/setup/js/n-test.run=^Test x_amd64/link node --conditions development x_amd64/link ve r/work/gh-aw/gh-aw/actions/setup/js/generate_safe_outputs_tools.cjs tions/setup/js/node_modules/vitest/suppress-warnings.cjs nfig/composer/vendor/bin/git extra.txt (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/12346/artifacts
    • Triggering command: /usr/bin/gh gh run download 12346 --dir test-logs/run-12346 k/gh-aw/gh-aw/actions/setup/js/n-test.run=^Test x_amd64/compile node --conditions development x_amd64/compile ve -unreachable=false tions/setup/js/node_modules/vitest/suppress-warnings.cjs p/bin/git extra.txt (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/2/artifacts
    • Triggering command: /usr/bin/gh gh run download 2 --dir test-logs/run-2 /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vite--conditions 0/x64/bin/node node --conditions development 0/x64/bin/node estl�� -unreachable=false tions/setup/js/node_modules/vitest/suppress-warnings.cjs tions/setup/js/node_modules/.bin/go extra.txt (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/3/artifacts
    • Triggering command: /usr/bin/gh gh run download 3 --dir test-logs/run-3 /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vite--conditions 0/x64/bin/node node --conditions development 0/x64/bin/node ve r/work/gh-aw/gh-aw/actions/setup/js/generate_safe_outputs_tools.cjs tions/setup/js/node_modules/vitest/suppress-warnings.cjs de_modules/.bin/go extra.txt git k/_temp/uv-pytho--git-dir tions/setup/js/node_modules/vitest/dist/workers//home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warn-ifaceassert (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/4/artifacts
    • Triggering command: /usr/bin/gh gh run download 4 --dir test-logs/run-4 k/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warn--conditions 0/x64/bin/node node --conditions development 0/x64/bin/node ve r/work/gh-aw/gh-aw/actions/setup/js/generate_saf-s tions/setup/js/node_modules/vitest/suppress-warn-w /error extra.txt (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/5/artifacts
    • Triggering command: /usr/bin/gh gh run download 5 --dir test-logs/run-5 /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vite--conditions x_amd64/vet node --conditions development x_amd64/vet ve r/work/gh-aw/gh-aw/actions/setup/js/generate_safe_outputs_tools.cjs tions/setup/js/node_modules/vitest/suppress-warnings.cjs tions/setup/node_modules/.bin/go extra.txt git 0/x64/bin/git tions/setup/js/node_modules/vitest/dist/workers//home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warn-ifaceassert (http block)
  • https://api.github.com/repos/github/gh-aw/actions/workflows
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path 0c12b8082c5f6786node cfg 64/pkg/tool/linudevelopment 05ebed2f72bb4ffcgo . 86_64/git 64/pkg/tool/linux_amd64/vet /hom�� tions/setup/js/n. cfg 64/pkg/tool/linux_amd64/vet -bare-uzazvL main it 64/pkg/tool/linux_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 100 origin /home/REDACTED/.lo-bool 64/pkg/tool/linu-buildtags cat-�� -e st/suppress-warn-ifaceassert 0/x64/bin/node HEAD^ ere ules/.bin/git st/dist/workers/config (http block)
    • Triggering command: /usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 6 st/suppress-warnrev-parse ode-gyp-bin/node--git-dir x_amd64/compile mpor�� -unreachable=false .com/repo.git.url git -u 25266a9e^ node k/gh-aw/gh-aw/actions/setup/js/n/home/REDACTED/work/gh-aw/gh-aw/pkg/cli/actionlint.go (http block)
  • https://api.github.com/repos/github/gh-aw/contents/.github%2Fworkflows%2Faudit-workflows.md
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/dist/workers/forks.js (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha -exist k/gh-aw/gh-aw/actions/setup/js/node_modules/vite--conditions At,event,headBranch,headSha,displayTitle -bare-rmehb4 Fallback commit (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.2.3
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.2.3 --jq .object.sha dd files" cfg 64/pkg/tool/linudevelopment -u (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v2.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq .object.sha bin/git cfg 64/pkg/tool/linudevelopment -b (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq .object.sha de/node/bin/git git 0/x64/bin/node -b (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq .object.sha ode_modules/.bin-u cfg 0/x64/bin/node -b ab261874^ odules/npm/node_/tmp/go-build1429002305/b417/_pkg_.a 0/x64/bin/node ve --is-ancestor tions/setup/js/ngithub.com/github/gh-aw/pkg/fileutil ache/go/1.25.0/x-lang=go1.25 origin refs/heads/race--C /home/REDACTED/wor/tmp/TestGuardPolicyBlockedUsersCommaSeparatedCompiledOutput300740846/001 tions/setup/js/nconfig (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v3.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v3.0.0 --jq .object.sha n-dir/git cfg es/.bin/git -b (http block)
  • https://api.github.com/repos/nonexistent/action/git/ref/tags/v999.999.999
    • Triggering command: /usr/bin/gh gh api /repos/nonexistent/action/git/ref/tags/v999.999.999 --jq .object.sha -bool .com/repo.git.url tions/node_modules/.bin/go -errorsas -ifaceassert -nilfunc k/gh-aw/gh-aw/actions/setup/js/nrev-parse -uns�� ithout_min-integrity2821472102/001 /tmp/go-build355557888/b192/vet.cfg 0/x64/bin/node origin refs/heads/fallbinit modules/@npmcli/run-script/lib/nuser.email 0/x64/bin/node (http block)
  • https://api.github.com/repos/nonexistent/repo/actions/runs/12345
    • Triggering command: /usr/bin/gh gh run view 12345 --repo nonexistent/repo --json status,conclusion fallback.txt /usr/lib/git-corinit /home/REDACTED/.config/composer/ve--show-toplevel uQ/Ri_wf6ull7lkV0w8jYoV/vtdUK9QKNjfUOQG40PjC -ato�� 1943168678/.github/workflows -buildtags o -errorsas -ifaceassert -nilfunc /opt/hostedtoolcache/go/1.25.0/x-importcfg (http block)
  • https://api.github.com/repos/owner/repo/actions/workflows
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path --repo owner/repo 64/pkg/tool/linux_amd64/vet /tmp/push-signedgo . 05ebed2f72bb4ffc/tmp/go-handler-test-cw9yQt/complex.go 64/pkg/tool/linux_amd64/vet /hom�� it cfg 64/pkg/tool/linux_amd64/vet -bare-uzazvL main run-script/lib/n-v 64/pkg/tool/linu-parallel=4 (http block)
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path --repo owner/repo 64/pkg/tool/linux_amd64/vet /tmp/push-signedgo . t 64/pkg/tool/linux_amd64/vet /hom�� e_modules/.bin/g. cfg ode_modules/.bin/git -bare-uzazvL main k/gh-aw/node_modules/.bin/git 64/pkg/tool/linux_amd64/vet (http block)
  • https://api.github.com/repos/owner/repo/contents/file.md
    • Triggering command: /tmp/go-build1429002305/b403/cli.test /tmp/go-build1429002305/b403/cli.test -test.testlogfile=/tmp/go-build1429002305/b403/testlog.txt -test.paniconexit0 -test.v=true -test.parallel=4 -test.timeout=10m0s -test.run=^Test -test.short=true --bare D ode-gyp-bin/git ode_modules/vitest/dist/workers/forks.js diff�� /js/generate_safe_outputs_tools.cjs st/suppress-warnings.cjs 64/pkg/tool/linux_amd64/vet . git /home/REDACTED/.lo--require st/dist/workers//home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warn-ifaceassert (http block)
  • https://api.github.com/repos/test-owner/test-repo/actions/secrets
    • Triggering command: /usr/bin/gh gh api /repos/test-owner/test-repo/actions/secrets --jq .secrets[].name 0c12b8082c5f6786node cfg modules/@npmcli/run-script/lib/node-gyp-bin/go 05ebed2f72bb4ffcgo . git 64/pkg/tool/linux_amd64/vet /hom�� 64/bin/git 0c12b8082c5f6786c75f3255..HEAD 64/pkg/tool/linux_amd64/vet -m Initial commit 86_64/git 64/pkg/tool/linux_amd64/vet (http block)
  • invalid.example.invalid
    • Triggering command: /usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin https://invalid.example.invalid/nonexistent-repo.git git conf�� user.name lure tions/setup/js/node_modules/.bin/git -M main /usr/sbin/git git init�� --bare --initial-branch=main k/gh-aw/gh-aw/actions/setup/js/node_modules/.bin/git '/tmp/bare-incregit '/tmp/bare-increadd cal/bin/git git (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

@villarrealcecilia2024-png

This comment was marked as spam.

When a PR branch is created via the GitHub API (using the createCommitOnBranch
GraphQL mutation in pushSignedCommits), the remote branch tip has a different
SHA than the local branch tip. The subsequent git push of the CI trigger empty
commit was being rejected as non-fast-forward.

Fix: after adding the ci-trigger remote, fetch the remote branch and reset the
local branch to it before creating the empty commit. This syncs local and remote
so the empty commit push is a valid fast-forward.

Handles the fallback case where the fetch fails (e.g. branch not yet on remote)
by logging a warning and continuing with the local HEAD.

Fixes #N/A

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/34cc4736-5028-401f-b70c-af9bb57daa16

Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix empty commit push failure with GH_AW_CI_TRIGGER_TOKEN fix: fetch remote branch before pushing CI trigger empty commit to avoid non-fast-forward rejection Mar 26, 2026
Copilot AI requested a review from dsyme March 26, 2026 19:04
@dsyme dsyme marked this pull request as ready for review March 26, 2026 19:07
Copilot AI review requested due to automatic review settings March 26, 2026 19:07
@dsyme dsyme merged commit bbdbca3 into main Mar 26, 2026
155 of 156 checks passed
@dsyme dsyme deleted the copilot/fix-gh-aw-ci-trigger-token-issue branch March 26, 2026 19:07
Copy link
Copy Markdown
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

Fixes CI-trigger empty commit pushes being rejected as non-fast-forward when the PR branch tip is created server-side (e.g., via createCommitOnBranch for signed commits), by synchronizing the local branch to the remote tip before creating/pushing the empty commit.

Changes:

  • Fetches the ci-trigger remote branch and hard-resets local HEAD to the remote tip before creating the CI-trigger empty commit.
  • Adds tests to assert remote add -> fetch -> reset --hard -> commit -> push ordering and to ensure graceful behavior when fetch/reset fails.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
actions/setup/js/extra_empty_commit.cjs Syncs local branch with the API-created remote tip via git fetch + git reset --hard prior to the empty commit push to avoid non-fast-forward rejection.
actions/setup/js/extra_empty_commit.test.cjs Adds coverage for the new fetch/reset behavior and the fallback path when sync fails.

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

Comment on lines +150 to +153
} catch {
// Non-fatal: if fetch/reset fails (e.g. branch not yet on remote), continue
// with the local HEAD and attempt the push anyway.
core.info(`Could not sync local branch with remote ${branchName} - will attempt push with local HEAD`);
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The catch block for fetch/reset swallows the underlying error, which makes it hard to diagnose real sync failures (e.g., auth/network issues vs missing branch). Capture the thrown error and include its message in the log (and consider using core.warning since a failed sync is likely to lead to a failed push/CI not triggering).

Suggested change
} catch {
// Non-fatal: if fetch/reset fails (e.g. branch not yet on remote), continue
// with the local HEAD and attempt the push anyway.
core.info(`Could not sync local branch with remote ${branchName} - will attempt push with local HEAD`);
} catch (error) {
// Non-fatal: if fetch/reset fails (e.g. branch not yet on remote), continue
// with the local HEAD and attempt the push anyway.
const syncErrorMessage = error instanceof Error ? error.message : String(error);
core.warning(`Could not sync local branch with remote ${branchName} - will attempt push with local HEAD. Underlying error: ${syncErrorMessage}`);

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: GH_AW_CI_TRIGGER_TOKEN empty commit push fails with non-fast-forward when PR is created via safe_output

4 participants