Last active
June 28, 2023 21:40
-
-
Save EdyVision/dbdd1764fdc54832cb905b20fb1668dc to your computer and use it in GitHub Desktop.
A GitHub workflow that automatically creates a tag and release based on poetry version mismatch (publishes to GitHub and Pypi)
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
# Automatically creates a new tag, GitHub release, and PyPi release if poetry version doesn't match last release version | |
name: Release | |
on: | |
workflow_dispatch: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
name: Release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: 3.9 | |
- name: Checkout branch "main" | |
uses: actions/checkout@v3 | |
with: | |
ref: 'main' | |
fetch-depth: 0 | |
- name: Install Global Dependencies | |
run: pip install -U pip && pip install poetry wheel | |
- name: Build project for distribution | |
run: poetry build | |
- name: Get Current Version | |
id: get_version | |
run: | | |
TAG_NAME=$(poetry version -s) | |
echo "TAG_NAME=v$TAG_NAME" >> $GITHUB_ENV | |
echo "$TAG_NAME" | |
- name: Check Released Versions | |
id: get_last_release_version | |
run: | | |
LAST_RELEASE=$(git tag --sort=committerdate | tail -1) | |
echo "LAST_RELEASE_VERSION=$LAST_RELEASE" >> $GITHUB_ENV | |
echo "Last released tag: $LAST_RELEASE" | |
- name: Check for Version Mismatch | |
shell: bash | |
if: ${{ env.LAST_RELEASE_VERSION != env.TAG_NAME }} | |
run: | | |
echo "New version found. Matching release will be created." | |
echo "Last version: ${{ env.LAST_RELEASE_VERSION }}" | |
echo "Current version: ${{ env.TAG_NAME }}" | |
- name: Tag and Release GitHub Snapshot | |
id: release-snapshot | |
uses: ncipollo/release-action@v1 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit: main | |
tag: ${{ env.TAG_NAME }} | |
skipIfReleaseExists: true | |
draft: false | |
prerelease: false | |
- name: Publish to PyPI | |
env: | |
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} | |
run: poetry publish |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment