Skip to content

Commit

Permalink
🔧 chore(ci): refactor github release and publishing workflows
Browse files Browse the repository at this point in the history
- consolidate publish-to-pypi and github-release workflows
- simplify job and step configurations
- add dynamic version detection and release drafting
- implement conditional PyPI and TestPyPI publishing
- integrate Sigstore for package signing
- utilize release-drafter for automated release notes
  • Loading branch information
awwaawwa committed Jan 24, 2025
1 parent dba21bf commit ee3d189
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 67 deletions.
42 changes: 42 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
labels:
- 'chore'
- 'maintenance'
- 'refactor'
- title: '📝 Documentation'
labels:
- 'docs'
- 'documentation'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Changes
$CHANGES
## Contributors
$CONTRIBUTORS
101 changes: 34 additions & 67 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,132 +1,99 @@
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
name: Release

on:
push:
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
branches:
- main
- master

jobs:
build:
name: Build distribution 📦
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 a binary wheel and a source tarball
- name: Build package
run: "uv build"

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/yadt # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/yadt

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
- name: Publish to PyPI
if: steps.check-version.outputs.tag
uses: pypa/gh-action-pypi-publish@release/v1
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
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/
github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- 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
"$GITHUB_REF_NAME"
"${{ 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 }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
"$GITHUB_REF_NAME" dist/**
"${{ steps.check-version.outputs.tag }}" dist/**
--repo "$GITHUB_REPOSITORY"

0 comments on commit ee3d189

Please sign in to comment.