Skip to content

Commit 8d99037

Browse files
committed
ci: fall back from stale workflow dispatch refs
1 parent c93b7d8 commit 8d99037

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,20 @@ jobs:
7979
env:
8080
CHECKOUT_REPO: ${{ github.repository }}
8181
CHECKOUT_REF: ${{ inputs.target_ref || github.sha }}
82+
CHECKOUT_FALLBACK_REF: ${{ github.sha }}
83+
GITHUB_EVENT_NAME: ${{ github.event_name }}
8284
run: |
8385
set -euo pipefail
8486
git init "$GITHUB_WORKSPACE"
8587
git -C "$GITHUB_WORKSPACE" config gc.auto 0
8688
git -C "$GITHUB_WORKSPACE" remote add origin "https://github.com/${CHECKOUT_REPO}.git"
87-
git -C "$GITHUB_WORKSPACE" fetch --no-tags --depth=1 origin "+${CHECKOUT_REF}:refs/remotes/origin/checkout"
89+
if ! git -C "$GITHUB_WORKSPACE" fetch --no-tags --depth=1 origin "+${CHECKOUT_REF}:refs/remotes/origin/checkout"; then
90+
if [ "$GITHUB_EVENT_NAME" != "workflow_dispatch" ] || [ "$CHECKOUT_REF" = "$CHECKOUT_FALLBACK_REF" ]; then
91+
exit 1
92+
fi
93+
echo "::warning::workflow_dispatch target_ref '$CHECKOUT_REF' is unavailable; falling back to head SHA '$CHECKOUT_FALLBACK_REF'"
94+
git -C "$GITHUB_WORKSPACE" fetch --no-tags --depth=1 origin "+${CHECKOUT_FALLBACK_REF}:refs/remotes/origin/checkout"
95+
fi
8896
git -C "$GITHUB_WORKSPACE" checkout --detach refs/remotes/origin/checkout
8997
9098
- name: Resolve checkout SHA
@@ -306,12 +314,20 @@ jobs:
306314
env:
307315
CHECKOUT_REPO: ${{ github.repository }}
308316
CHECKOUT_REF: ${{ inputs.target_ref || github.sha }}
317+
CHECKOUT_FALLBACK_REF: ${{ github.sha }}
318+
GITHUB_EVENT_NAME: ${{ github.event_name }}
309319
run: |
310320
set -euo pipefail
311321
git init "$GITHUB_WORKSPACE"
312322
git -C "$GITHUB_WORKSPACE" config gc.auto 0
313323
git -C "$GITHUB_WORKSPACE" remote add origin "https://github.com/${CHECKOUT_REPO}.git"
314-
git -C "$GITHUB_WORKSPACE" fetch --no-tags --depth=1 origin "+${CHECKOUT_REF}:refs/remotes/origin/checkout"
324+
if ! git -C "$GITHUB_WORKSPACE" fetch --no-tags --depth=1 origin "+${CHECKOUT_REF}:refs/remotes/origin/checkout"; then
325+
if [ "$GITHUB_EVENT_NAME" != "workflow_dispatch" ] || [ "$CHECKOUT_REF" = "$CHECKOUT_FALLBACK_REF" ]; then
326+
exit 1
327+
fi
328+
echo "::warning::workflow_dispatch target_ref '$CHECKOUT_REF' is unavailable; falling back to head SHA '$CHECKOUT_FALLBACK_REF'"
329+
git -C "$GITHUB_WORKSPACE" fetch --no-tags --depth=1 origin "+${CHECKOUT_FALLBACK_REF}:refs/remotes/origin/checkout"
330+
fi
315331
git -C "$GITHUB_WORKSPACE" checkout --detach refs/remotes/origin/checkout
316332
317333
- name: Ensure security base commit

0 commit comments

Comments
 (0)