Merge pull request #38 from mindfiredigital/master #19
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 and Publish Package | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v3 | |
| with: | |
| python-version: "3.x" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine python-semantic-release>=9.0.0 setuptools-scm | |
| - name: Create release branch | |
| run: | | |
| git config --global user.name "github-actions" | |
| git config --global user.email "github-actions@github.com" | |
| git checkout -b release-main | |
| git push --set-upstream origin release-main | |
| - name: Run semantic-release version on release-main branch | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| semantic-release --verbose version | |
| # For semantic-release 9.x, the publish command needs to be run separately | |
| - name: Run semantic-release publish | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| semantic-release --verbose publish | |
| - name: Push release branch | |
| run: git push origin release-main | |
| - name: Create PR to main | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh pr create \ | |
| --base main \ | |
| --head release-main \ | |
| --title "Automated Release Updates" \ | |
| --body "This pull request contains updates from the semantic-release process." || true | |
| # This is only needed if semantic-release publish didn't handle the PyPI upload | |
| - name: Build and publish package to PyPI if needed | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| if [ ! -f "dist/*" ]; then | |
| python -m build | |
| twine upload dist/* | |
| fi |