Skip to content

Release

Release #12

Workflow file for this run

name: Release
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
permissions:
contents: write
id-token: write
jobs:
release:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
version: ${{ steps.version.outputs.version }}
skip: ${{ steps.version.outputs.skip }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: main
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Compute next version
id: version
run: |
latest_tag=$(git describe --tags --match 'v*' --abbrev=0 2>/dev/null || echo "v0.0.0")
# Skip if HEAD is already tagged
if git describe --tags --match 'v*' --exact-match HEAD 2>/dev/null; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "HEAD is already tagged, skipping"
exit 0
fi
IFS='.' read -r major minor patch <<< "${latest_tag#v}"
commits=$(git log "${latest_tag}..HEAD" --format="%s" 2>/dev/null || git log --format="%s")
if echo "$commits" | grep -qE "^[a-z]+(\(.+\))?!:|BREAKING CHANGE:"; then
ver="$((major + 1)).0.0"
elif echo "$commits" | grep -qE "^feat(\(.+\))?:"; then
ver="${major}.$((minor + 1)).0"
else
ver="${major}.${minor}.$((patch + 1))"
fi
# Skip if computed version matches what's already in source
current=$(grep -Po '(?<=^__version__ = ")[^"]+' src/opendata_sdk/_version.py)
if [ "$ver" = "$current" ]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "Computed version ${ver} matches current, skipping"
exit 0
fi
echo "version=${ver}" >> "$GITHUB_OUTPUT"
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "Next version: ${ver}"
- name: Bump version in source files
if: steps.version.outputs.skip != 'true'
run: |
VER="${{ steps.version.outputs.version }}"
sed -i "s/^__version__ = \".*\"/__version__ = \"${VER}\"/" src/opendata_sdk/_version.py
sed -i "s/^version = \".*\"/version = \"${VER}\"/" pyproject.toml
- name: Commit, tag, and push
if: steps.version.outputs.skip != 'true'
run: |
VER="${{ steps.version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add src/opendata_sdk/_version.py pyproject.toml
git commit -m "chore(release): v${VER}"
git tag "v${VER}"
git push origin HEAD:main --tags
- name: Create GitHub Release
if: steps.version.outputs.skip != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VER="${{ steps.version.outputs.version }}"
latest_tag=$(git describe --tags --match 'v*' --abbrev=0 "v${VER}^" 2>/dev/null || echo "")
if [ -n "$latest_tag" ]; then
NOTES=$(git log "${latest_tag}..v${VER}" --format="- %s" --no-merges | grep -v "chore(release)")
else
NOTES=$(git log "v${VER}" --format="- %s" --no-merges | grep -v "chore(release)")
fi
gh release create "v${VER}" \
--title "v${VER}" \
--notes "${NOTES:-No notable changes}" \
--repo "${{ github.repository }}"
publish:
needs: release
if: needs.release.outputs.skip != 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: v${{ needs.release.outputs.version }}
- name: Verify version matches tag
run: |
VER="${{ needs.release.outputs.version }}"
PKG_VERSION=$(grep -Po '(?<=^__version__ = ")[^"]+' src/opendata_sdk/_version.py)
if [ "$VER" != "$PKG_VERSION" ]; then
echo "ERROR: Tag v${VER} does not match _version.py version ${PKG_VERSION}"
exit 1
fi
echo "Version verified: $PKG_VERSION"
- name: Install uv
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7
with:
version: ">=0.5"
enable-cache: true
prune-cache: true
- name: Set up Python
run: uv python install 3.12
- name: Build package
run: uv build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1
with:
packages-dir: dist/