diff --git a/.forgejo/workflows/autotagger.yaml b/.forgejo/workflows/autotagger.yaml new file mode 100644 index 0000000..c125de7 --- /dev/null +++ b/.forgejo/workflows/autotagger.yaml @@ -0,0 +1,66 @@ +name: Autotagger +on: + push: + branches: + - 'main' + +jobs: + Autotagger: + runs-on: docker + container: catthehacker/ubuntu:act-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Git + run: | + git config --global user.name "SeaswimmerTheFsh" + git config --global user.email "seaswimmerthefsh@gmail.com" + + - name: Import GPG key + uses: actions/gpg@v4 + with: + gpg_private_key : ${{ secrets.GPG_PRIVATE_KEY }} + passphrase : ${{ secrets.GPG_PASSPHRASE }} + + - name: Extract commit message + id: extract_commit_message + run: echo "::set-output name=message::$(git log --format=%B -n 1 $GITHUB_SHA) + + - name: Get new version + id: get_version + run: ::set-output name=version::$(awk -F '=' '/^ *version/ {gsub(/[[:space:]]/, "", $2); print $2}' pyproject.toml) + + - name: Get latest tag + id: get_latest_tag + run: | + git fetch --tags + LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) + echo "::set-output name=latest_tag::$LATEST_TAG" + + - name: Compare version and latest tag + id: compare + run: | + VERSION=${{ steps.get_version.outputs.version }} + LATEST_TAG=${{ steps.get_latest_tag.outputs.latest_tag }} + if [ "$VERSION" = "$LATEST_TAG" ]; then + echo "::set-output name=latest_tag::$LATEST_TAG" + fi + echo "::set-output name=version::$VERSION" + + - name: Create tag + if: steps.compare.outputs.version + run: | + VERSION=${{ steps.get_version.outputs.version }} + git tag -s $VERSION -m "version bumped to $VERSION" + git push origin $VERSION + + - name: Update latest tag + if: steps.compare.outputs.latest_tag + run: | + MESSAGE=${{ steps.extract_commit_message.outputs.message }} + LATEST_TAG=${{ steps.compare.outputs.latest_tag }} + git tag -fs $LATEST_TAG -m "$MESSAGE" + git push origin $LATEST_TAG --force