|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + validate-tag: |
| 10 | + name: Validate tag follows RELEASE.md |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Set up Python |
| 14 | + uses: actions/setup-python@v5 |
| 15 | + with: |
| 16 | + python-version: "3.10" |
| 17 | + |
| 18 | + - name: Validate tag format |
| 19 | + run: | |
| 20 | + TAG="${{ github.ref_name }}" |
| 21 | + |
| 22 | + python << EOF |
| 23 | + import re |
| 24 | + |
| 25 | + tag = '$TAG' |
| 26 | + |
| 27 | + # Check for valid patterns: vX.Y.Z, vX.Y.ZrcN, vX.Y.ZaN, vX.Y.ZbN |
| 28 | + # With optional .postN suffix: vX.Y.Z.postN, vX.Y.ZrcN.postN, etc. |
| 29 | + # Where X, Y, Z, N are numbers |
| 30 | + pattern = r'^v\d+\.\d+\.\d+(rc\d+|a\d+|b\d+)?(\.post\d+)?$' |
| 31 | + |
| 32 | + if not re.match(pattern, tag): |
| 33 | + print(f'✗ Tag {tag} does not match required format (per RELEASE.md)') |
| 34 | + print(' Valid formats: vX.Y.Z, vX.Y.ZrcN, vX.Y.ZaN, vX.Y.ZbN') |
| 35 | + print(' With optional .postN: vX.Y.Z.postN, vX.Y.ZrcN.postN, etc.') |
| 36 | + print(' Where X, Y, Z, N are numbers') |
| 37 | + exit(1) |
| 38 | + |
| 39 | + print(f'✓ Tag {tag} is valid') |
| 40 | + EOF |
| 41 | +
|
| 42 | + build: |
| 43 | + name: Build distribution 📦 |
| 44 | + needs: validate-tag |
| 45 | + runs-on: ubuntu-latest |
| 46 | + |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + fetch-depth: 0 # IMPORTANT: Required for setuptools-scm to see tags! |
| 51 | + persist-credentials: false |
| 52 | + |
| 53 | + - name: Set up Python |
| 54 | + uses: actions/setup-python@v5 |
| 55 | + with: |
| 56 | + python-version: "3.10" |
| 57 | + |
| 58 | + - name: Install uv |
| 59 | + uses: astral-sh/setup-uv@v4 |
| 60 | + with: |
| 61 | + enable-cache: true |
| 62 | + |
| 63 | + - name: Build a binary wheel and a source tarball |
| 64 | + run: uv build |
| 65 | + |
| 66 | + - name: Store the distribution packages |
| 67 | + uses: actions/upload-artifact@v4 |
| 68 | + with: |
| 69 | + name: python-package-distributions |
| 70 | + path: dist/ |
| 71 | + |
| 72 | + publish-to-pypi: |
| 73 | + name: Publish Python 🐍 distribution 📦 to PyPI |
| 74 | + needs: build |
| 75 | + runs-on: ubuntu-latest |
| 76 | + environment: |
| 77 | + name: pypi |
| 78 | + url: https://pypi.org/p/brainsets |
| 79 | + permissions: |
| 80 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 81 | + |
| 82 | + steps: |
| 83 | + - name: Download all the dists |
| 84 | + uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + name: python-package-distributions |
| 87 | + path: dist/ |
| 88 | + |
| 89 | + - name: Publish distribution 📦 to PyPI |
| 90 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments