|
| 1 | +name: Release on tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # Trigger when a semver-like tag is pushed (e.g. v1.2.3) |
| 6 | + tags: |
| 7 | + - 'v*.*.*' |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + id-token: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + name: Build and Release |
| 16 | + runs-on: ubuntu-latest |
| 17 | + env: |
| 18 | + CLOUDSMITH_OWNER: ${{ secrets.CLOUDSMITH_OWNER }} |
| 19 | + CLOUDSMITH_REPOSITORY: ${{ secrets.CLOUDSMITH_REPOSITORY }} |
| 20 | + CLOUDSMITH_SERVICE_SLUG: ${{ secrets.CLOUDSMITH_SERVICE_SLUG }} |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Ensure the tag points to master |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + set -euo pipefail |
| 31 | + echo "Tag ref: ${GITHUB_REF} (name: ${GITHUB_REF_NAME}), SHA: ${GITHUB_SHA}" |
| 32 | + # Fetch master to check ancestry |
| 33 | + git fetch --no-tags --prune --depth=1 origin master |
| 34 | + if git merge-base --is-ancestor "${GITHUB_SHA}" origin/master; then |
| 35 | + echo "Tag commit is an ancestor of origin/master. Proceeding." |
| 36 | + else |
| 37 | + if git merge-base --is-ancestor origin/master "${GITHUB_SHA}"; then |
| 38 | + echo "origin/master is an ancestor of tag commit. Proceeding." |
| 39 | + else |
| 40 | + echo "Error: The tag ${GITHUB_REF_NAME} does not point to a commit based on the latest master." |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Set up Python |
| 45 | + uses: actions/setup-python@v5 |
| 46 | + with: |
| 47 | + python-version: '3.11' |
| 48 | + |
| 49 | + - name: Install build tooling |
| 50 | + run: | |
| 51 | + python -m pip install --upgrade pip |
| 52 | + pip install build wheel setuptools |
| 53 | +
|
| 54 | + - name: Verify version matches tag |
| 55 | + shell: bash |
| 56 | + run: | |
| 57 | + set -euo pipefail |
| 58 | + TAG_VERSION="${GITHUB_REF_NAME#v}" |
| 59 | + PKG_VERSION=$(python setup.py --version) |
| 60 | + echo "Package version: ${PKG_VERSION} | Tag version: ${TAG_VERSION}" |
| 61 | + test "${PKG_VERSION}" = "${TAG_VERSION}" || { |
| 62 | + echo "Version mismatch: setup.py (${PKG_VERSION}) != tag (${TAG_VERSION})" |
| 63 | + exit 1 |
| 64 | + } |
| 65 | +
|
| 66 | + - name: Build package (sdist + wheel) |
| 67 | + run: | |
| 68 | + python -m build |
| 69 | + ls -la dist |
| 70 | +
|
| 71 | + - name: Create GitHub Release and upload assets |
| 72 | + uses: softprops/action-gh-release@v2 |
| 73 | + with: |
| 74 | + tag_name: ${{ github.ref_name }} |
| 75 | + name: ${{ github.ref_name }} |
| 76 | + generate_release_notes: true |
| 77 | + files: | |
| 78 | + dist/*.whl |
| 79 | + dist/*.tar.gz |
| 80 | +
|
| 81 | + - name: Install and authenticate Cloudsmith CLI (OIDC) |
| 82 | + uses: cloudsmith-io/cloudsmith-cli-action@v1.0.3 |
| 83 | + with: |
| 84 | + oidc-namespace: ${{ env.CLOUDSMITH_OWNER }} |
| 85 | + oidc-service-slug: ${{ env.CLOUDSMITH_SERVICE_SLUG }} |
| 86 | + |
| 87 | + - name: Upload package to Cloudsmith |
| 88 | + env: |
| 89 | + OWNER: ${{ env.CLOUDSMITH_OWNER }} |
| 90 | + REPO: ${{ env.CLOUDSMITH_REPOSITORY }} |
| 91 | + run: | |
| 92 | + set -euo pipefail |
| 93 | + echo "Uploading to Cloudsmith: ${OWNER}/${REPO}" |
| 94 | + for file in dist/*.{tar.gz,whl}; do |
| 95 | + cloudsmith push python "${OWNER}/${REPO}" "$file" |
| 96 | + done |
| 97 | +
|
| 98 | + # - name: Publish to PyPI (Trusted Publishing) |
| 99 | + # uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments