Skip to content

Prepare Release

Prepare Release #12

name: Prepare Release
on:
workflow_dispatch:
permissions:
contents: read
pull-requests: read
jobs:
metadata:
name: Get Metadata
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v8.0.0
- name: Get Project Version
id: get-version
run: |
# Get the short version output (e.g., "5.0.0.dev1")
VERSION=$(uv version --short)
echo "Version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
check-release:
name: Check Release Status
needs: metadata
runs-on: ubuntu-latest
env:
VERSION_TAG: ${{ format('v{0}', needs.metadata.outputs.version) }}
outputs:
release_exists: ${{ steps.check.outputs.release_exists }}
is_draft: ${{ steps.check.outputs.is_draft }}
permissions:
contents: read
steps:
- name: Check if release exists and is published
id: check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if the release already exists
RELEASE_EXISTS=$(gh release view $VERSION_TAG --json isDraft,isPrerelease --repo $GITHUB_REPOSITORY 2>/dev/null || echo "not_found")
if [ "$RELEASE_EXISTS" != "not_found" ]; then
IS_DRAFT=$(echo $RELEASE_EXISTS | jq -r '.isDraft')
if [ "$IS_DRAFT" = "false" ]; then
echo "Error: Release $VERSION_TAG already exists and is published. Cannot upload to a published release."
exit 1
else
echo "Release $VERSION_TAG exists as a draft. Proceeding with build process."
echo "release_exists=true" >> $GITHUB_OUTPUT
echo "is_draft=true" >> $GITHUB_OUTPUT
fi
else
echo "Release $VERSION_TAG does not exist. Proceeding with build process."
echo "release_exists=false" >> $GITHUB_OUTPUT
echo "is_draft=false" >> $GITHUB_OUTPUT
fi
test:
uses: ./.github/workflows/test.yml
name: Test
needs: [check-release]
build-apps:
uses: ./.github/workflows/build.yml
name: Build All Apps
needs: [check-release]
with:
build-windows-installer: true
build-windows-portable: true
build-python3-zipapp: true
build-python3-wheel: true
release:
name: Upload Release
needs: [test, build-apps, check-release, metadata]
runs-on: ubuntu-latest
env:
VERSION_TAG: ${{ format('v{0}', needs.metadata.outputs.version) }}
permissions:
contents: write
steps:
- name: Download All Packages
uses: actions/download-artifact@v8
with:
merge-multiple: true
- name: Upload Assets to Existing Draft Release
if: needs.check-release.outputs.release_exists == 'true' && needs.check-release.outputs.is_draft == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Uploading assets to existing draft release $VERSION_TAG..."
gh release upload $VERSION_TAG \
*-portable.zip \
*-setup.exe \
*.pyzw \
*.whl \
--clobber --repo $GITHUB_REPOSITORY
- name: Create New Draft Release
if: needs.check-release.outputs.release_exists == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Creating new draft release $VERSION_TAG..."
gh release create $VERSION_TAG \
*-portable.zip \
*-setup.exe \
*.pyzw \
*.whl \
--repo $GITHUB_REPOSITORY \
--draft \
--title "VCF Generator Lite $VERSION_TAG"
- name: Error on Published Release
if: needs.check-release.outputs.is_draft == 'false' && needs.check-release.outputs.release_exists == 'true'
run: |
echo "ERROR: The release $VERSION_TAG is already published. Asset uploads are only allowed for draft releases."
exit 1