Skip to content

Commit addc103

Browse files
authored
Improve release workflow: detect tag on push, wait for auto-created tag, and robustly handle artifacts/checksums
- Use ref_name when triggered by a tag push; otherwise wait for the auto-created tag and pick the latest v*.*.* tag - Expose both version and tag as outputs - Use safer find/cp invocation for release files and add conditional checksum generation (handle missing artifacts) - Use the full tag (with "v" prefix) when creating the GitHub release
1 parent 88bcb14 commit addc103

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

.github/workflows/release.yml

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -355,36 +355,44 @@ jobs:
355355
with:
356356
fetch-depth: 0
357357

358-
- name: Wait for tag to be available
358+
- name: Determine version
359+
id: version
359360
run: |
360-
echo "Waiting for tag to be available..."
361-
MAX_ATTEMPTS=60
362-
ATTEMPT=0
363-
364-
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
365-
git fetch origin --tags
366-
if git describe --tags --abbrev=0 2>/dev/null; then
367-
echo "✅ Tag is available"
368-
break
369-
fi
370-
ATTEMPT=$((ATTEMPT + 1))
371-
if [ $ATTEMPT -lt $MAX_ATTEMPTS ]; then
372-
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS: Tag not yet available, waiting..."
373-
sleep 2
361+
# If triggered by tag push, use ref_name
362+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
363+
TAG="${{ github.ref_name }}"
364+
VERSION=${TAG#v}
365+
else
366+
# If triggered by workflow_dispatch, wait for the tag created by auto-version
367+
echo "Waiting for tag to be available..."
368+
MAX_ATTEMPTS=60
369+
ATTEMPT=0
370+
371+
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
372+
git fetch origin --tags --force
373+
# Get the most recently created tag
374+
TAG=$(git tag --sort=-creatordate --list 'v*.*.*' | head -1)
375+
if [ -n "$TAG" ]; then
376+
VERSION=${TAG#v}
377+
echo "✅ Tag found: $TAG"
378+
break
379+
fi
380+
381+
ATTEMPT=$((ATTEMPT + 1))
382+
if [ $ATTEMPT -lt $MAX_ATTEMPTS ]; then
383+
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS: Tag not yet available, waiting..."
384+
sleep 2
385+
fi
386+
done
387+
388+
if [ -z "$TAG" ]; then
389+
echo "❌ Timeout waiting for tag"
390+
exit 1
374391
fi
375-
done
376-
377-
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
378-
echo "❌ Timeout waiting for tag"
379-
exit 1
380392
fi
381-
382-
- name: Get latest tag
383-
id: version
384-
run: |
385-
TAG=$(git describe --tags --abbrev=0)
386-
VERSION=${TAG#v}
393+
387394
echo "version=$VERSION" >> $GITHUB_OUTPUT
395+
echo "tag=$TAG" >> $GITHUB_OUTPUT
388396
echo "Release version: $VERSION"
389397
echo "Tag: $TAG"
390398
@@ -396,20 +404,25 @@ jobs:
396404
- name: Prepare release files
397405
run: |
398406
mkdir -p release
399-
find artifacts -type f -name '*.tar.gz' -o -name '*.zip' | xargs -I {} cp {} release/
407+
find artifacts -type f \( -name '*.tar.gz' -o -name '*.zip' \) -exec cp {} release/ \;
400408
ls -lh release/
401409
402410
- name: Create checksums
403411
run: |
404412
cd release
405-
sha256sum * > SHA256SUMS.txt
406-
cat SHA256SUMS.txt
413+
if [ $(ls -1 *.tar.gz *.zip 2>/dev/null | wc -l) -gt 0 ]; then
414+
sha256sum *.tar.gz *.zip > SHA256SUMS.txt 2>/dev/null || sha256sum * > SHA256SUMS.txt
415+
cat SHA256SUMS.txt
416+
else
417+
echo "No artifacts found"
418+
fi
407419
408420
- name: Generate release notes
409421
run: |
410422
RUNNER_VERSION=$(grep "__version__" runner.py | sed 's/__version__ = "\(.*\)"/\1/')
411423
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
412424
RELEASE_VER="${{ steps.version.outputs.version }}"
425+
TAG_NAME="${{ steps.version.outputs.tag }}"
413426
414427
cat > release/RELEASE_NOTES.md << EOF
415428
# Python Script Runner ${{ github.ref_name }}
@@ -490,7 +503,7 @@ jobs:
490503
- name: Create GitHub Release
491504
uses: softprops/action-gh-release@v1
492505
with:
493-
tag_name: v${{ steps.version.outputs.version }}
506+
tag_name: ${{ steps.version.outputs.tag }}
494507
files: |
495508
release/python3-runner-*.tar.gz
496509
release/python3-runner-*.zip

0 commit comments

Comments
 (0)