🔧 chore(ci): refactor github release and publishing workflows #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
branches: | |
- main | |
- master | |
jobs: | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
fetch-depth: 2 | |
- name: Setup uv with Python 3.12 | |
uses: astral-sh/setup-uv@v5 | |
with: | |
python-version: "3.12" | |
enable-cache: true | |
cache-dependency-glob: "uv.lock" | |
- name: Check if there is a parent commit | |
id: check-parent-commit | |
run: | | |
echo "::set-output name=sha::$(git rev-parse --verify --quiet HEAD^)" | |
- name: Detect and tag new version | |
id: check-version | |
if: steps.check-parent-commit.outputs.sha | |
uses: salsify/[email protected] | |
with: | |
version-command: | | |
cat pyproject.toml | grep "version = " | head -n 1 | awk -F'"' '{print $2}' | |
- name: Bump version for developmental release | |
if: "! steps.check-version.outputs.tag" | |
run: | | |
bumpver update --patch && | |
version=$(cat pyproject.toml | grep "version = " | head -n 1 | awk -F'"' '{print $2}') && | |
bumpver update --set-version $version.dev.$(date +%s) | |
- name: Build package | |
run: "uv build" | |
- name: Store the distribution packages | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Publish to PyPI | |
if: steps.check-version.outputs.tag | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://pypi.org/legacy/ | |
- name: Publish to TestPyPI | |
if: "! steps.check-version.outputs.tag" | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
- name: Sign the dists with Sigstore | |
uses: sigstore/[email protected] | |
with: | |
inputs: >- | |
./dist/*.tar.gz | |
./dist/*.whl | |
- name: Publish the release notes | |
uses: release-drafter/[email protected] | |
with: | |
publish: ${{ steps.check-version.outputs.tag != '' }} | |
tag: ${{ steps.check-version.outputs.tag }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create GitHub Release | |
if: steps.check-version.outputs.tag | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: >- | |
gh release create | |
"${{ steps.check-version.outputs.tag }}" | |
--repo "$GITHUB_REPOSITORY" | |
--notes "" | |
- name: Upload artifact signatures to GitHub Release | |
if: steps.check-version.outputs.tag | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: >- | |
gh release upload | |
"${{ steps.check-version.outputs.tag }}" dist/** | |
--repo "$GITHUB_REPOSITORY" |