Create Release #4
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: Create Release | |
on: | |
workflow_dispatch: | |
inputs: | |
upload_to_pypi: | |
description: 'Upload the release to PyPI' | |
type: boolean | |
required: false | |
default: true | |
permissions: | |
actions: write | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.get-version.outputs.VERSION }} | |
steps: | |
- name: Checkout project | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
- name: Install Poetry | |
uses: abatilo/actions-poetry@v4 | |
with: | |
poetry-version: "1.8.5" | |
- name: Setup a local virtual environment | |
run: | | |
poetry config virtualenvs.create true --local | |
poetry config virtualenvs.in-project true --local | |
- name: Define a cache for the virtual environment based on the dependencies lock file | |
uses: actions/cache@v4 | |
with: | |
path: ./.venv | |
key: venv-${{ hashFiles('poetry.lock') }} | |
- name: Build | |
run: | | |
poetry install | |
poetry build | |
- name: Get package version to create a new tag and release | |
id: get-version | |
run: echo "VERSION=$(poetry version --short)" >> $GITHUB_OUTPUT | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: csaps-packages | |
path: dist/* | |
overwrite: true | |
publish: | |
name: Publish | |
needs: [ build ] | |
runs-on: ubuntu-latest | |
environment: | |
name: release | |
url: https://pypi.org/project/csaps | |
permissions: | |
id-token: write | |
contents: write | |
env: | |
TAG_NAME: v${{ needs.build.outputs.version }} | |
steps: | |
- name: Download build artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: csaps-packages | |
path: dist | |
- name: Check tag ${{ env.TAG_NAME }} | |
uses: mukunku/[email protected] | |
id: check-tag | |
with: | |
tag: ${{ env.TAG_NAME }} | |
- name: Create tag ${{ env.TAG_NAME }} | |
if: ${{ steps.check-tag.outputs.exists == 'false' }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/${{ env.TAG_NAME }}', | |
sha: context.sha | |
}) | |
- name: Create release ${{ env.TAG_NAME }} | |
uses: softprops/action-gh-release@v2 | |
with: | |
name: ${{ env.TAG_NAME }} | |
tag_name: ${{ env.TAG_NAME }} | |
files: dist/* | |
- name: Upload to PyPI | |
if: ${{ inputs.upload_to_pypi }} | |
uses: pypa/gh-action-pypi-publish@release/v1 |