Skip to content

Commit bec401f

Browse files
Merge pull request #85 from ssvlabs/chore/improve-ci
chore: harden dist artifact push error handling
2 parents 0015966 + e01dbae commit bec401f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: CI
33
on:
44
push:
55

6+
permissions:
7+
contents: write
8+
69

710
jobs:
811
pr-checks:
@@ -115,4 +118,26 @@ jobs:
115118
message: "ci: update artifacts [skip ci]"
116119
skip-empty: true
117120

118-
- run: git push origin || echo "nothing to push"
121+
- name: Push artifact commit
122+
shell: bash
123+
run: |
124+
set -euo pipefail
125+
126+
BRANCH=main
127+
git fetch origin "$BRANCH"
128+
129+
LOCAL_HEAD="$(git rev-parse HEAD)"
130+
REMOTE_HEAD="$(git rev-parse "origin/$BRANCH")"
131+
132+
if [ "$LOCAL_HEAD" = "$REMOTE_HEAD" ]; then
133+
echo "No new commit to push."
134+
exit 0
135+
fi
136+
137+
# Prevent pushing stale dist from an outdated run.
138+
if ! git merge-base --is-ancestor "$REMOTE_HEAD" "$LOCAL_HEAD"; then
139+
echo "::error::Remote $BRANCH moved. This run is outdated; not pushing artifacts."
140+
exit 1
141+
fi
142+
143+
git push --porcelain origin "HEAD:$BRANCH"

0 commit comments

Comments
 (0)