Skip to content

Publish the latest release on PyPI #2

Publish the latest release on PyPI

Publish the latest release on PyPI #2

Workflow file for this run

name: Publish the latest release on PyPI
on:
push:
tags:
- 'v*'
branches:
- main # Restricts the workflow to only run on tags pushed to the main branch
jobs:
validate-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Validate Tag Format
run: |
TAG_REGEX='^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\-\.]+)?$'
TAG="${GITHUB_REF/refs\/tags\//}"
if [[ "$TAG" =~ $TAG_REGEX ]]; then
echo "Tag format is valid."
else
echo "::error::Tag $TAG does not match the 'vMAJOR.MINOR.PATCH' or 'vMAJOR.MINOR.PATCH-pre-release' format."
exit 1
build-and-test:
needs: validate-tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Run tests
run: |
poetry run pytest
publish-to-pypi:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Build the distribution
run: poetry build
- name: Publish
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_KEY }}
create-github-release:
needs: publish-to-pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create Release on GitHub
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: 'Automated release of version ${{ github.ref_name }}'
draft: false
prerelease: false