Skip to content

Commit ce66002

Browse files
ci: improve release workflow with retry logic for creating/updating releases
1 parent d8f6566 commit ce66002

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

.github/workflows/create-release.yaml

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ env:
1313
MAX_RETRIES: 3
1414
RETRY_DELAY: 30
1515

16+
permissions:
17+
contents: write
18+
issues: write
19+
1620
jobs:
1721
update-release:
1822
runs-on: ubuntu-latest
@@ -94,20 +98,31 @@ jobs:
9498
env:
9599
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96100
run: |
97-
# Check if release exists
98-
if gh release view "${{ env.VERSION }}" &>/dev/null; then
99-
# Update existing release and upload ISO
100-
gh release edit "${{ env.VERSION }}" \
101-
--title "Release ${{ env.VERSION }}" \
102-
--notes-file release_notes.md
103-
gh release upload "${{ env.VERSION }}" ./iso-files/*
104-
else
105-
# Create new release with ISO
106-
gh release create "${{ env.VERSION }}" \
107-
--title "Release ${{ env.VERSION }}" \
108-
--notes-file release_notes.md \
109-
--target ${GITHUB_REF#refs/heads/} \
110-
./iso-files/*
101+
retries=0
102+
max_retries=${{ env.MAX_RETRIES }}
103+
104+
while [ $retries -lt $max_retries ]; do
105+
if gh release view "${{ env.VERSION }}" &>/dev/null; then
106+
gh release edit "${{ env.VERSION }}" \
107+
--title "Release ${{ env.VERSION }}" \
108+
--notes-file release_notes.md && \
109+
gh release upload "${{ env.VERSION }}" ./iso-files/* && break
110+
else
111+
gh release create "${{ env.VERSION }}" \
112+
--title "Release ${{ env.VERSION }}" \
113+
--notes-file release_notes.md \
114+
--target ${GITHUB_REF#refs/heads/} \
115+
./iso-files/* && break
116+
fi
117+
118+
retries=$((retries + 1))
119+
[ $retries -lt $max_retries ] && sleep ${{ env.RETRY_DELAY }}
120+
done
121+
122+
if [ $retries -eq $max_retries ]; then
123+
echo "::error::Failed to create/update release after $max_retries attempts"
124+
exit 1
125+
fi
111126
112127
- name: Upload Build Logs
113128
if: always()
@@ -119,10 +134,13 @@ jobs:
119134

120135
- name: Notify on Failure
121136
if: failure()
137+
env:
138+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122139
uses: actions/github-script@v6
123140
with:
141+
github-token: ${{ secrets.GITHUB_TOKEN }}
124142
script: |
125-
const issue = await github.rest.issues.create({
143+
await github.rest.issues.create({
126144
owner: context.repo.owner,
127145
repo: context.repo.repo,
128146
title: '❌ Release Update Failed',

0 commit comments

Comments
 (0)