Merge pull request #144 from oscarbenjamin/pr_trusted_publisher #116
This file contains 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: | |
push: | |
branches: | |
- main | |
- master | |
jobs: | |
tag-and-build: | |
name: Tag and build | |
runs-on: ubuntu-latest | |
permissions: write-all | |
outputs: | |
tag: ${{ steps.tag-step.outputs.tag }} | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v4.1.1 | |
with: | |
fetch-depth: 2 | |
- name: Set up Python | |
uses: actions/setup-python@v5.0.0 | |
with: | |
python-version: "3.9" | |
- name: Upgrade pip | |
run: | | |
pip install --upgrade pip | |
pip install hatch | |
- name: Check if there is a parent commit | |
id: check-parent-commit | |
run: | | |
echo "sha=$(git rev-parse --verify --quiet HEAD^)" >> $GITHUB_OUTPUT | |
- name: Detect and tag new version | |
id: check-version | |
if: steps.check-parent-commit.outputs.sha | |
uses: salsify/action-detect-and-tag-new-version@v2.0.3 | |
with: | |
version-command: | | |
hatch version | |
- name: Bump version for developmental release | |
if: "! steps.check-version.outputs.tag" | |
run: | | |
hatch version dev && | |
version=$(hatch version) && | |
hatch version $version$(date +%s) | |
- name: Publish the release notes | |
uses: release-drafter/release-drafter@v6.0.0 | |
with: | |
publish: ${{ steps.check-version.outputs.tag != '' }} | |
tag: ${{ steps.check-version.outputs.tag }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build package | |
run: | | |
hatch build | |
- name: Store tag | |
id: tag-step | |
run: echo "tag=${{ steps.check-version.outputs.tag }}" >> "$GITHUB_OUTPUT" | |
- name: Upload release artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-artifacts | |
path: dist/ | |
pypi-publish: | |
name: Publish to PyPI | |
needs: [tag-and-build] | |
environment: | |
name: release | |
url: https://test.pypi.org/p/protosym | |
permissions: | |
id-token: write | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "Tag = ${{ needs.tag-and-build.outputs.tag }}" | |
- name: Publish package on PyPI | |
if: needs.tag-and-build.outputs.tag | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
- name: Publish package on TestPyPI | |
if: "! needs.tag-and-build.outputs.tag" | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository_url: https://test.pypi.org/legacy/ |