|  | 
|  | 1 | +name: Publish to PyPI | 
|  | 2 | + | 
|  | 3 | +on: | 
|  | 4 | +  push: | 
|  | 5 | +    tags: | 
|  | 6 | +      - '[0-9]+.[0-9]+.[0-9]+' # Matches semantic versioning tags | 
|  | 7 | +      - '[0-9]+.[0-9]+.[0-9]+-test.*' # Test releases | 
|  | 8 | + | 
|  | 9 | +jobs: | 
|  | 10 | +  test: | 
|  | 11 | +    runs-on: ubuntu-latest | 
|  | 12 | +    strategy: | 
|  | 13 | +      matrix: | 
|  | 14 | +        python-version: ['3.12'] | 
|  | 15 | + | 
|  | 16 | +    steps: | 
|  | 17 | +      - uses: actions/checkout@v3 | 
|  | 18 | + | 
|  | 19 | +      - name: Set up Python ${{ matrix.python-version }} | 
|  | 20 | +        uses: actions/setup-python@v4 | 
|  | 21 | +        with: | 
|  | 22 | +          python-version: ${{ matrix.python-version }} | 
|  | 23 | + | 
|  | 24 | +      - name: Install dependencies and run CI | 
|  | 25 | +        run: | | 
|  | 26 | +          python -m pip install --upgrade pip | 
|  | 27 | +          pip install build pytest pytest-cov setuptools_scm | 
|  | 28 | +          make ci | 
|  | 29 | +
 | 
|  | 30 | +  publish: | 
|  | 31 | +    needs: test | 
|  | 32 | +    runs-on: ubuntu-latest | 
|  | 33 | +    permissions: | 
|  | 34 | +      contents: write | 
|  | 35 | +    steps: | 
|  | 36 | +      - uses: actions/checkout@v3 | 
|  | 37 | + | 
|  | 38 | +      - name: Set up Python | 
|  | 39 | +        uses: actions/setup-python@v4 | 
|  | 40 | +        with: | 
|  | 41 | +          python-version: '3.12' | 
|  | 42 | + | 
|  | 43 | +      - name: Verify tag version matches package version | 
|  | 44 | +        run: | | 
|  | 45 | +          python -m pip install --upgrade pip | 
|  | 46 | +          pip install build pytest pytest-cov setuptools_scm twine | 
|  | 47 | +          PACKAGE_VERSION=$(python -m setuptools_scm) | 
|  | 48 | +          TAG_VERSION=${GITHUB_REF#refs/tags/}  # Remove 'refs/tags/' prefix | 
|  | 49 | +          if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then | 
|  | 50 | +            echo "Package version ($PACKAGE_VERSION) does not match tag version ($TAG_VERSION)" | 
|  | 51 | +            exit 1 | 
|  | 52 | +          fi | 
|  | 53 | +
 | 
|  | 54 | +      - name: Publish to TestPyPI | 
|  | 55 | +        if: contains(github.ref, 'test') | 
|  | 56 | +        env: | 
|  | 57 | +          TWINE_USERNAME: __token__ | 
|  | 58 | +          TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} | 
|  | 59 | +        run: make all && twine upload --repository testpypi dist/* | 
|  | 60 | + | 
|  | 61 | +      - name: Publish to PyPI | 
|  | 62 | +        if: "!contains(github.ref, 'test')" | 
|  | 63 | +        env: | 
|  | 64 | +          TWINE_USERNAME: __token__ | 
|  | 65 | +          TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | 
|  | 66 | +        run: make dist | 
|  | 67 | + | 
|  | 68 | +      - name: Create Release | 
|  | 69 | +        uses: softprops/action-gh-release@v1 | 
|  | 70 | +        with: | 
|  | 71 | +          files: dist/* | 
|  | 72 | +          generate_release_notes: true | 
|  | 73 | +        env: | 
|  | 74 | +          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | 
0 commit comments