auto-tag #53
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
# This workflow will upload a Python Package using Twine when a release is created | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
name: auto-tag | |
on: | |
workflow_run: | |
workflows: ["test"] | |
branches: [main] | |
types: | |
- completed | |
permissions: | |
contents: write | |
jobs: | |
auto-tag: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GH_PAT }} | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: 3.8 | |
- name: Set up poetry | |
uses: abatilo/actions-poetry@v2 | |
with: | |
poetry-version: 1.4 | |
- name: Install Dependencies | |
run: poetry install --with dev | |
- name: Check for version changes and create a tag | |
run: | | |
# Use poetry's python API to get the new version | |
NEW_VER=$(poetry version -s) | |
# Fetch tags | |
git fetch --prune --tags | |
# Check if tag already exists | |
EXISTING_VERSIONS=$(git tag --list) | |
if [[ $EXISTING_VERSIONS =~ (^|[[:space:]])"$NEW_VER"($|[[:space:]]) ]]; then | |
echo "Tag $NEW_VER already exists. Skipping..." | |
exit 0 | |
else | |
git config --global user.name 'Christopher Hacker' | |
git config --global user.email '[email protected]' | |
echo "Creating tag $NEW_VER..." | |
git tag $NEW_VER | |
git push origin $NEW_VER | |
echo "NEW_VER=$NEW_VER" >> "$GITHUB_ENV" | |
fi |