Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 95 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,112 @@
# See source with more comments and detailed explanations at:
# https://python-semantic-release.readthedocs.io/en/latest/configuration/automatic-releases/github-actions.html#gh-actions-examples

name: Release

on:
push:
branches:
- main

permissions:
contents: read

jobs:
release:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-release-${{ github.ref_name }}
cancel-in-progress: false

permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup | Checkout Repository on Release Branch
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
token: ${{ secrets.GH_TOKEN_FOR_SEMANTIC_RELEASE }}

- name: Setup | Force release branch to be at workflow sha
run: |
git reset --hard ${{ github.sha }}

- name: Evaluate | Verify upstream has NOT changed
shell: bash
run: |
set +o pipefail

UPSTREAM_BRANCH_NAME="$(git status -sb | head -n 1 | awk -F '\\.\\.\\.' '{print $2}' | cut -d ' ' -f1)"
printf '%s\n' "Upstream branch name: $UPSTREAM_BRANCH_NAME"

set -o pipefail

if [ -z "$UPSTREAM_BRANCH_NAME" ]; then
printf >&2 '%s\n' "::error::Unable to determine upstream branch name!"
exit 1
fi

git fetch "${UPSTREAM_BRANCH_NAME%%/*}"

if ! UPSTREAM_SHA="$(git rev-parse "$UPSTREAM_BRANCH_NAME")"; then
printf >&2 '%s\n' "::error::Unable to determine upstream branch sha!"
exit 1
fi

HEAD_SHA="$(git rev-parse HEAD)"

if [ "$HEAD_SHA" != "$UPSTREAM_SHA" ]; then
printf >&2 '%s\n' "[HEAD SHA] $HEAD_SHA != $UPSTREAM_SHA [UPSTREAM SHA]"
printf >&2 '%s\n' "::error::Upstream has changed, aborting release..."
exit 1
fi

printf '%s\n' "Verified upstream branch has not changed, continuing with release..."

- name: Action | Semantic Version Release
id: release
uses: python-semantic-release/[email protected]
with:
fetch-depth: 0 # Fetch all history for semantic-release
github_token: ${{ secrets.GH_TOKEN_FOR_SEMANTIC_RELEASE }}
git_committer_name: "github-actions"
git_committer_email: "[email protected]"

- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Publish | Upload to GitHub Release Assets
uses: python-semantic-release/[email protected]
if: steps.release.outputs.released == 'true'
with:
github_token: ${{ secrets.GH_TOKEN_FOR_SEMANTIC_RELEASE }}
tag: ${{ steps.release.outputs.tag }}

- name: Install dependencies
run: uv sync
- name: Upload | Distribution Artifacts
uses: actions/upload-artifact@v4
with:
name: distribution-artifacts
path: dist
if-no-files-found: error

deploy:
runs-on: ubuntu-latest
needs: release
if: ${{ needs.release.outputs.released == 'true' }}

- name: Release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: uv run semantic-release version
permissions:
contents: read
id-token: write

steps:
- name: Setup | Download Build Artifacts
uses: actions/download-artifact@v4
id: artifact-download
with:
name: distribution-artifacts
path: dist

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
print-hash: true
verbose: true
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dev = [
"pytest-cov>=6.2.1",
"pytest-mock>=3.14.1",
"pytest-socket>=0.7.0",
"python-semantic-release>=10.2.0",
]

[tool.mypy]
Expand Down
Loading