release #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: "version bump (major|minor|patch)" | |
| required: true | |
| default: patch | |
| type: choice | |
| options: [major, minor, patch] | |
| registry: | |
| description: "where to publish" | |
| type: choice | |
| options: [pypi, testpypi] | |
| default: testpypi | |
| permissions: | |
| contents: write # push commit and tag | |
| id-token: write # for PyPI trusted publishing; required for OIDC | |
| env: | |
| PYTHON_VERSION: "3.10" | |
| jobs: | |
| release: | |
| environment: release-pypi | |
| if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: fail if not on main | |
| if: github.ref != 'refs/heads/main' | |
| run: | | |
| echo "This workflow can only run from main. Current ref: $GITHUB_REF" | |
| exit 1 | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # needed to push tags | |
| - name: set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: install build deps | |
| run: | | |
| python -m pip install --upgrade pip build requests | |
| chmod +x scripts/bump_version.py scripts/zenodo_upload.py | |
| - name: bump version | |
| id: bump | |
| run: | | |
| NEWVER=$(python scripts/bump_version.py "${{ github.event.inputs.bump }}") | |
| echo "new_version=$NEWVER" >> $GITHUB_OUTPUT | |
| echo "version -> $NEWVER" | |
| - name: commit version bump | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add pyproject.toml || true | |
| git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }}" | |
| git tag "v${{ steps.bump.outputs.new_version }}" | |
| git push --follow-tags | |
| - name: build sdist and wheel | |
| run: python -m build | |
| - name: publish to PyPI (trusted publishing) | |
| if: ${{ inputs.registry == 'pypi' }} | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist | |
| - name: publish to TestPyPI (trusted publishing) | |
| if: ${{ inputs.registry == 'testpypi' }} | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist | |
| repository-url: https://test.pypi.org/legacy/ | |
| # - name: zip source (for Zenodo) | |
| # run: | | |
| # mkdir -p release_assets | |
| # cp -r dist release_assets/ | |
| # (cd release_assets && zip -r "source-v${{ steps.bump.outputs.new_version }}.zip" dist) | |
| # - name: upload to Zenodo | |
| # env: | |
| # ZENODO_TOKEN: ${{ secrets.ZENODO_TOKEN }} | |
| # ZENODO_API_URL: ${{ secrets.ZENODO_API_URL }} # optional; set org-wide/repo var; default is prod | |
| # ZENODO_DEPOSITION_ID: ${{ vars.ZENODO_DEPOSITION_ID }} # set this to chain versions; leave unset to create new | |
| # ZENODO_TITLE: ${{ vars.ZENODO_TITLE }} | |
| # ZENODO_DESCRIPTION: ${{ vars.ZENODO_DESCRIPTION }} | |
| # ZENODO_AUTHORS: ${{ vars.ZENODO_AUTHORS }} # JSON list | |
| # ZENODO_COMMUNITIES: ${{ vars.ZENODO_COMMUNITIES }} # JSON list | |
| # ZENODO_KEYWORDS: ${{ vars.ZENODO_KEYWORDS }} # JSON list | |
| # VERSION: ${{ steps.bump.outputs.new_version }} | |
| # FILEPATH: release_assets/source-v${{ steps.bump.outputs.new_version }}.zip | |
| # run: | | |
| # python scripts/zenodo_upload.py |