|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + |
| 7 | +jobs: |
| 8 | + release: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + concurrency: release |
| 11 | + env: |
| 12 | + FORCE_PATCH_IF_NO_COMMIT_TOKEN: false |
| 13 | + IGNORE_PATHS: | |
| 14 | + resources/** |
| 15 | + assets/** |
| 16 | +
|
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: '3.11' |
| 25 | + |
| 26 | + - name: Compute bumped version |
| 27 | + id: version |
| 28 | + env: |
| 29 | + FORCE_PATCH_IF_NO_COMMIT_TOKEN: ${{ env.FORCE_PATCH_IF_NO_COMMIT_TOKEN }} |
| 30 | + IGNORE_PATHS: ${{ env.IGNORE_PATHS }} |
| 31 | + run: | |
| 32 | + set -euo pipefail |
| 33 | + echo "now: $(date -u +"%Y-%m-%dT%H:%M:%S.%3N")" |
| 34 | +
|
| 35 | + # get the latest semantic-version style tag |
| 36 | + _latest_semver_tag=$(git tag --sort=-creatordate | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | head -n1 || true) |
| 37 | + echo "Latest semantic-version style tag: $_latest_semver_tag" |
| 38 | + if [ -z "$_latest_semver_tag" ]; then |
| 39 | + echo "No previous semver tag found — using 0.0.0" |
| 40 | + echo "version=0.0.0" >> "$GITHUB_OUTPUT" |
| 41 | + exit 0 |
| 42 | + else |
| 43 | + LATEST_SEMVER_TAG_NO_V="${_latest_semver_tag#v}" |
| 44 | + fi |
| 45 | +
|
| 46 | + # get info on what's changed since that tag |
| 47 | + _that_commit=$(git rev-list -n 1 "$_latest_semver_tag") |
| 48 | + echo "Looking at what's changed since $_latest_semver_tag / $_that_commit" |
| 49 | + # |
| 50 | + CHANGED_FILES=$(git diff --name-only "$_that_commit"..HEAD) |
| 51 | + echo "Changed files:" |
| 52 | + echo "$CHANGED_FILES" |
| 53 | + # |
| 54 | + COMMIT_LOG=$(git log "$_that_commit"..HEAD --pretty=%B) |
| 55 | + echo "Commit log(s) since then:" |
| 56 | + echo "$COMMIT_LOG" |
| 57 | +
|
| 58 | + # get next version |
| 59 | + export LATEST_SEMVER_TAG_NO_V |
| 60 | + export CHANGED_FILES |
| 61 | + export COMMIT_LOG |
| 62 | + VERSION=$(python compute_next_version.py) |
| 63 | +
|
| 64 | + # handle output |
| 65 | + if [ -z "$VERSION" ]; then |
| 66 | + echo "No release needed — skipping" |
| 67 | + echo "version=" >> "$GITHUB_OUTPUT" |
| 68 | + else |
| 69 | + echo "Bumped version: $VERSION" |
| 70 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Install build tools |
| 74 | + if: steps.version.outputs.version != '' |
| 75 | + run: | |
| 76 | + set -euo pipefail |
| 77 | + echo "now: $(date -u +"%Y-%m-%dT%H:%M:%S.%3N")" |
| 78 | + |
| 79 | + exit 1 # TODO: REMOVE |
| 80 | + |
| 81 | + python -m pip install --upgrade pip |
| 82 | + pip install build twine setuptools setuptools-scm |
| 83 | +
|
| 84 | + - name: Build package |
| 85 | + if: steps.version.outputs.version != '' |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | + echo "now: $(date -u +"%Y-%m-%dT%H:%M:%S.%3N")" |
| 89 | + # Validate setuptools-scm usage |
| 90 | + if ! grep -q 'setuptools-scm' pyproject.toml; then |
| 91 | + echo "❌ setuptools-scm not found in pyproject.toml — aborting" |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | +
|
| 95 | + if grep -A 5 '^\[project\]' pyproject.toml | grep -q '^version\s*='; then |
| 96 | + echo "❌ [project] version is explicitly set — must be managed by setuptools-scm" |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | +
|
| 100 | + echo "✅ setuptools-scm is configured properly" |
| 101 | +
|
| 102 | + SETUPTOOLS_SCM_PRETEND_VERSION=${{ steps.version.outputs.version }} python -m build |
| 103 | +
|
| 104 | + - name: Create GitHub Release via API |
| 105 | + if: steps.version.outputs.version != '' |
| 106 | + env: |
| 107 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 108 | + VERSION: ${{ steps.version.outputs.version }} |
| 109 | + run: | |
| 110 | + set -euo pipefail |
| 111 | + echo "now: $(date -u +"%Y-%m-%dT%H:%M:%S.%3N")" |
| 112 | + API_URL="https://api.github.com/repos/${{ github.repository }}/releases" |
| 113 | + TAG="release-${VERSION}" |
| 114 | + PAYLOAD=$(jq -n \ |
| 115 | + --arg tag_name "$TAG" \ |
| 116 | + --arg target_commitish "${{ github.sha }}" \ |
| 117 | + --arg name "Release $VERSION" \ |
| 118 | + --arg body "Automated release for commit ${{ github.sha }}" \ |
| 119 | + '{ tag_name: $tag_name, target_commitish: $target_commitish, name: $name, body: $body, draft: false, prerelease: false }') |
| 120 | + curl -sSf -X POST -H "Authorization: Bearer $GH_TOKEN" \ |
| 121 | + -H "Content-Type: application/json" \ |
| 122 | + -d "$PAYLOAD" "$API_URL" |
| 123 | +
|
| 124 | + - name: Upload to PyPI |
| 125 | + if: steps.version.outputs.version != '' |
| 126 | + env: |
| 127 | + TWINE_USERNAME: __token__ |
| 128 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 129 | + run: | |
| 130 | + set -euo pipefail |
| 131 | + echo "now: $(date -u +"%Y-%m-%dT%H:%M:%S.%3N")" |
| 132 | + twine upload dist/* |
0 commit comments