Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the library version number to publish to pypi, create a git tag and define a github release #688

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 41 additions & 13 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,66 @@
name: Publish 📦 to PyPi 🚀

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+*"
on: workflow_dispatch

jobs:
build-n-publish:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@master
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Gets the tag version
id: context
run: |
echo ::set-output name=TAG_VERSION::${GITHUB_REF#refs/tags/}

- name: Setup the Python Environment by installing Poetry
uses: ./.github/actions/setup-python-build-env

- name: Retrieve the project version
id: version
shell: bash
run: |
echo "proj_version=$(poetry version -s)" >> $GITHUB_OUTPUT

- name: Check if tag exists, only proceed if version has not been released
run: |
echo "Checking for tag: $PROJ_TAG"
if git rev-parse "refs/tags/$PROJ_TAG" >/dev/null 2>&1
echo "Version $PROJ_TAG already exists, version bump required to proceed."
exit 1
fi
env:
PROJ_TAG: v${{ steps.version.outputs.PROJ_VERSION }}

- name: Code Quality Check
shell: bash
run: make install && make tests

- name: Poetry bump version, build and publish
- name: Build library and publish to PyPi
shell: bash
run: |
proj_version=$(poetry version -s)
if [ $proj_version != $TAG_VERSION ]; then echo "Version $proj_version, defined in pyproject.toml, does not match TAG $TAG_VERSION of this release"; exit 3; fi
poetry publish --build -u __token__ -p $PYPI_TOKEN
env:
TAG_VERSION: ${{ steps.context.outputs.TAG_VERSION }}
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

- name: Create and Push Tag 🏷️
run: |
git tag $PROJ_TAG
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}
git push origin $PROJ_TAG
echo "tag_created=true" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PROJ_TAG: v${{ steps.version.outputs.PROJ_VERSION }}

- name: Create a GitHub Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PROJ_TAG: v${{ steps.version.outputs.PROJ_VERSION }}
with:
generate_release_notes: true
tag_name: $PROJ_TAG
Loading
Loading