|
| 1 | +name: PyPI Release |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + # Trigger on version tags (e.g., v1.0.0) |
| 6 | + - "v[0-9].[0-9].[0-9]*" |
| 7 | + - "[0-9].[0-9].[0-9]*" |
| 8 | + # Trigger on pre-release tags (e.g., v1.0.0-alpha.1) |
| 9 | + - "v[0-9].[0-9].[0-9]*-*" |
| 10 | + - "[0-9].[0-9].[0-9]*-*" |
| 11 | + # branches: |
| 12 | + # # Trigger on the main branch |
| 13 | + # - main |
| 14 | + # - master |
| 15 | + |
| 16 | +env: |
| 17 | + # package name |
| 18 | + PYPI_NAME: qc-BFit |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + name: Build and Test Distribution |
| 23 | + runs-on: ${{ matrix.os }} |
| 24 | + |
| 25 | + strategy: |
| 26 | + matrix: |
| 27 | + # os: [ubuntu-latest, macos-latest, windows-latest] |
| 28 | + os: [ubuntu-latest] |
| 29 | + # python-version: ["3.9", "3.10", "3.11", "3.12"] |
| 30 | + python-version: ["3.11"] |
| 31 | + outputs: |
| 32 | + os: ${{ matrix.os }} |
| 33 | + python-version: ${{ matrix.python-version }} |
| 34 | + |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + with: |
| 38 | + fetch-depth: 0 |
| 39 | + - name: Set up Python |
| 40 | + uses: actions/setup-python@v5 |
| 41 | + with: |
| 42 | + python-version: ${{ matrix.python-version }} |
| 43 | + # python-version: "3.11" |
| 44 | + - name: Install dependencies |
| 45 | + run: | |
| 46 | + python -m pip install --upgrade pip |
| 47 | + python -m pip install build pytest pytest-cov codecov |
| 48 | + python -m pip install -r requirements.txt |
| 49 | + # python -m pip install -r requirements_dev.txt |
| 50 | + # TODO: Add testing support once the issues are resolved |
| 51 | + # - name: Test package |
| 52 | + # run: | |
| 53 | + # python -m pytest -c pyproject.toml --cov-config=.coveragerc --cov-report=xml --color=yes --cov=bfit bfit/test |
| 54 | + - name: Build package |
| 55 | + run: python -m build --sdist --wheel |
| 56 | + - name: Store the distribution packages |
| 57 | + uses: actions/upload-artifact@v4 |
| 58 | + with: |
| 59 | + # Name of the artifact to upload, unique for each OS and Python version |
| 60 | + name: python-package-distributions |
| 61 | + path: dist/ |
| 62 | + # Optional parameters for better artifact management |
| 63 | + overwrite: true |
| 64 | + include-hidden-files: false |
| 65 | + |
| 66 | + publish-to-pypi: |
| 67 | + name: Publish Python distribution to PyPI |
| 68 | + if: startsWith(github.ref, 'refs/tags/v') |
| 69 | + needs: build |
| 70 | + runs-on: ubuntu-latest |
| 71 | + environment: |
| 72 | + name: PyPI-Release |
| 73 | + url: https://pypi.org/p/${{ env.PYPI_NAME }} |
| 74 | + permissions: |
| 75 | + id-token: write |
| 76 | + |
| 77 | + steps: |
| 78 | + - name: Download all the dists |
| 79 | + uses: actions/download-artifact@v4 |
| 80 | + with: |
| 81 | + name: python-package-distributions |
| 82 | + path: dist/ |
| 83 | + pattern: '**/*.whl' |
| 84 | + - name: Publish distribution to PyPI |
| 85 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 86 | + env: |
| 87 | + TWINE_USERNAME: "__token__" |
| 88 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 89 | + |
| 90 | + github-release: |
| 91 | + name: Sign and Upload Python Distribution to GitHub Release |
| 92 | + needs: |
| 93 | + - build |
| 94 | + - publish-to-pypi |
| 95 | + runs-on: ubuntu-latest |
| 96 | + permissions: |
| 97 | + contents: write |
| 98 | + id-token: write |
| 99 | + |
| 100 | + steps: |
| 101 | + - name: Download all the dists |
| 102 | + uses: actions/download-artifact@v4 |
| 103 | + with: |
| 104 | + name: python-package-distributions |
| 105 | + path: dist/ |
| 106 | + - name: Sign the dists with Sigstore |
| 107 | + uses: sigstore/gh-action-sigstore-python@v3.0.0 |
| 108 | + with: |
| 109 | + inputs: >- |
| 110 | + ./dist/*.tar.gz |
| 111 | + ./dist/*.whl |
| 112 | + - name: Create GitHub Release |
| 113 | + env: |
| 114 | + GITHUB_TOKEN: ${{ github.token }} |
| 115 | + run: > |
| 116 | + gh release create |
| 117 | + '${{ github.ref_name }}' |
| 118 | + --repo '${{ github.repository }}' |
| 119 | + --notes "" |
| 120 | + - name: Upload artifact signatures to GitHub Release |
| 121 | + env: |
| 122 | + GITHUB_TOKEN: ${{ github.token }} |
| 123 | + run: > |
| 124 | + gh release upload |
| 125 | + '${{ github.ref_name }}' dist/** |
| 126 | + --repo '${{ github.repository }}' |
| 127 | +
|
| 128 | + publish-none-pypi: |
| 129 | + name: Publish Python distribution to TestPyPI (none) |
| 130 | + if: startsWith(github.ref, 'refs/tags/v') |
| 131 | + needs: build |
| 132 | + runs-on: ubuntu-latest |
| 133 | + environment: |
| 134 | + name: TestPyPI |
| 135 | + url: https://test.pypi.org/p/${{ env.PYPI_NAME }} |
| 136 | + permissions: |
| 137 | + id-token: write |
| 138 | + |
| 139 | + steps: |
| 140 | + - name: Download all the dists |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + name: python-package-distributions |
| 144 | + path: dist/ |
| 145 | + pattern: '**/*.whl' |
| 146 | + - name: Publish distribution with relaxed constraints |
| 147 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 148 | + with: |
| 149 | + repository-url: https://test.pypi.org/legacy/ |
| 150 | + env: |
| 151 | + TWINE_USERNAME: "__token__" |
| 152 | + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }} |
0 commit comments