From 23568f1f4b224c9836546e24bfdc4328baeb9a43 Mon Sep 17 00:00:00 2001 From: Roman Martsev Date: Wed, 29 May 2024 12:38:20 +0300 Subject: [PATCH] chore(gha): edit latest auto tag, add auto major tag --- ...-tag.yaml => auto-tag-latest-version.yaml} | 4 +-- .github/workflows/auto-tag-major-version.yaml | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) rename .github/workflows/{move-latest-tag.yaml => auto-tag-latest-version.yaml} (88%) create mode 100644 .github/workflows/auto-tag-major-version.yaml diff --git a/.github/workflows/move-latest-tag.yaml b/.github/workflows/auto-tag-latest-version.yaml similarity index 88% rename from .github/workflows/move-latest-tag.yaml rename to .github/workflows/auto-tag-latest-version.yaml index 0b99301..96da8f4 100644 --- a/.github/workflows/move-latest-tag.yaml +++ b/.github/workflows/auto-tag-latest-version.yaml @@ -1,8 +1,8 @@ -name: Move Latest Tag +name: Auto-Tag Latest Version on: release: - types: [created] + types: [published] jobs: move-latest-tag: diff --git a/.github/workflows/auto-tag-major-version.yaml b/.github/workflows/auto-tag-major-version.yaml new file mode 100644 index 0000000..b3d2989 --- /dev/null +++ b/.github/workflows/auto-tag-major-version.yaml @@ -0,0 +1,30 @@ +name: Auto-Tag Major Version + +on: + release: + types: [published] + +jobs: + tag-major-version: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Git + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + + - name: Tag Major Version + run: | + FULL_TAG=${{ github.event.release.tag_name }} + MAJOR_VERSION=$(echo "$FULL_TAG" | sed -E 's/^v([0-9]+)\..*/v\1/') + if git rev-parse "$MAJOR_VERSION" >/dev/null 2>&1; then + echo "Tag $MAJOR_VERSION already exists. Updating the tag..." + git tag -fa "$MAJOR_VERSION" -m "Update major version tag to $MAJOR_VERSION" ${{ github.event.release.target_commitish }} + else + echo "Creating new tag $MAJOR_VERSION..." + git tag -a "$MAJOR_VERSION" -m "Create major version tag $MAJOR_VERSION" ${{ github.event.release.target_commitish }} + fi + git push origin "$MAJOR_VERSION" --force