Skip to content

Commit

Permalink
update publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
miaucl committed Sep 14, 2024
1 parent cb89e08 commit 36c3e9c
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Extract tag version
id: extract_tag
Expand Down Expand Up @@ -77,7 +79,35 @@ jobs:
else
echo "Pre-release tag, skipping changelog check"
fi
- name: Check if version type matches branch type
run: |
branch=$(git branch -r --contains ${{ github.ref }} --format "%(refname:lstrip=3)")
echo "Branch: $branch"
version=${GITHUB_REF#refs/tags/}
echo "Version from tag: $version"
# Check if the version is a prerelease
if [[ "$version" =~ [a-zA-Z] ]]; then
echo "Prerelease version detected: $version"
prerelease=true
else
echo "Final release version detected: $version"
prerelease=false
fi
# Fail if it's a prerelease and on the master branch
if [[ "$branch" == "master" && "$prerelease" == "true" ]]; then
echo "Error: Prerelease versions are not allowed on the master branch."
exit 1
fi
# Fail if it's a final release on a non-master branch
if [[ "$branch" != "master" && "$prerelease" == "false" ]]; then
echo "Error: Final releases are not allowed on non-master branches."
exit 1
fi
publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
Expand Down Expand Up @@ -117,6 +147,15 @@ jobs:
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/}
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
- name: Check if version is prerelease
id: check_prerelease
run: |
TAG_VERSION="${{ steps.version.outputs.version }}"
if [[ "$TAG_VERSION" =~ [a-zA-Z] ]]; then
echo "prerelease=true" >> $GITHUB_OUTPUT
else
echo "prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Download all the dists
uses: actions/download-artifact@v4
with:
Expand All @@ -134,6 +173,7 @@ jobs:
tag_name: ${{ github.ref }}
name: Release ${{ steps.version.outputs.version }}
generate_release_notes: true
prerelease: ${{ steps.check_prerelease.outputs.prerelease }} # Mark as prerelease if necessary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifact signatures to GitHub Release
Expand Down

0 comments on commit 36c3e9c

Please sign in to comment.