Release #6
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: | |
| jobs: | |
| github_release: | |
| name: GitHub Release | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: write | |
| outputs: | |
| new_release_version: ${{ steps.semantic.outputs.new_release_version }} | |
| new_release_published: ${{ steps.semantic.outputs.new_release_published }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| ref: main | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "lts/*" | |
| - name: Install semantic release and plugins | |
| run: | | |
| npm install -g semantic-release@v24.2.1 \ | |
| conventional-changelog-cli \ | |
| conventional-changelog-conventionalcommits \ | |
| @semantic-release/changelog \ | |
| @semantic-release/exec \ | |
| @semantic-release/git \ | |
| @semantic-release/github | |
| - name: Semantic Release Dry Run | |
| id: semantic | |
| run: | | |
| dry_run_output=$(semantic-release --dry-run 2>&1 || true) | |
| echo "$dry_run_output" | |
| # Check if there are no changes | |
| if [[ "$dry_run_output" == *"no new version is released"* ]]; then | |
| echo "No new release needed" | |
| echo "new_release_published=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Extract version from dry run output | |
| version=$(echo "$dry_run_output" | grep -oP "The next release version is \K[0-9]+\.[0-9]+\.[0-9]+") | |
| if [ -z "$version" ]; then | |
| echo "::error ::Could not determine version" | |
| exit 1 | |
| fi | |
| echo "new_release_version=$version" >> $GITHUB_OUTPUT | |
| # Run actual release | |
| if semantic-release; then | |
| echo "Release successful" | |
| echo "new_release_published=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Release failed" | |
| exit 1 | |
| fi | |
| env: | |
| CI: true | |
| GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_TOKEN }} | |
| publish: | |
| name: Publish to PyPI | |
| needs: github_release | |
| if: needs.github_release.outputs.new_release_published == 'true' | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Fetch changes on main | |
| run: git pull origin main | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install build twine | |
| - name: Build package | |
| run: python -m build | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: twine upload dist/* |