test version release #15
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: Publish the latest release on PyPI | |
on: | |
push: | |
tags: | |
- 'v*' | |
branches: | |
- release # Restricts the workflow to only run on tags pushed to the release branch | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Override the version number' | |
required: false | |
rollback: | |
description: 'Trigger a rollback to the previous stable version' | |
required: false | |
default: false | |
jobs: | |
validate-tag: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Validate Tag Format | |
run: | | |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then | |
TAG_REGEX='^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\-\.]+)?$' | |
echo "Regex to match: $TAG_REGEX" | |
TAG="${GITHUB_REF/refs\/tags\//}" | |
echo "Tag extracted: $TAG" | |
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 | |
fi | |
else | |
echo "No tag associated with push, skipping tag validation." | |
exit 78 # Exiting with neutral status | |
fi | |
shell: bash | |
build-and-package: | |
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 --no-dev | |
- name: Build the distribution | |
run: poetry build | |
- name: Upload distribution for publishing | |
uses: actions/upload-artifact@v2 | |
with: | |
name: dist | |
path: dist/** | |
dry-run-publish: | |
needs: build-and-package | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Download distribution | |
uses: actions/download-artifact@v2 | |
with: | |
name: dist | |
path: dist | |
- name: Dry run publish to PyPI | |
run: | | |
poetry publish --dry-run --build | |
# Uncomment the following lines to enable TestPyPI publishing | |
# test-publish-to-testpypi: | |
# needs: build-and-package | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - name: Set up Python | |
# uses: actions/setup-python@v4 | |
# with: | |
# python-version: '3.11' | |
# - name: Download distribution | |
# uses: actions/download-artifact@v2 | |
# with: | |
# name: dist | |
# path: dist | |
# - name: Publish to TestPyPI | |
# run: | | |
# poetry config repositories.testpypi https://test.pypi.org/legacy/ | |
# poetry publish --repository testpypi --username __token__ --password ${{ secrets.TEST_PYPI_API_TOKEN }} | |
# publish-to-pypi: | |
# needs: | |
# - validate-tag | |
# - build-and-package | |
# - dry-run-publish | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - name: Download distribution | |
# uses: actions/download-artifact@v2 | |
# with: | |
# name: dist | |
# path: dist | |
# - name: Set up Python | |
# uses: actions/setup-python@v4 | |
# with: | |
# python-version: '3.11' | |
# - name: Publish to PyPI | |
# 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 | |
# rollback: | |
# needs: publish-to-pypi | |
# if: ${{ github.event.inputs.rollback == 'true' }} | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - name: Set up Python | |
# uses: actions/setup-python@v4 | |
# with: | |
# python-version: '3.11' | |
# - name: Rollback to previous stable version | |
# run: | | |
# echo "Rolling back to previous stable version..." | |
# # Add rollback logic here |