From c8363ee29dbdcdbe655dfed9c55cf023bf65717b Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Mon, 10 Jun 2024 20:56:38 -0700 Subject: [PATCH] Auto-tag commits on master (#192) --- .github/workflows/tag-release.yml | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/tag-release.yml diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml new file mode 100644 index 0000000..aad8d0c --- /dev/null +++ b/.github/workflows/tag-release.yml @@ -0,0 +1,50 @@ +name: Tag patch release + +on: + push: + branches: + - master # Adjust to match the name of your main branch + paths-ignore: + - .github/** + - README.md + - LICENSE + +jobs: + tag: + runs-on: ubuntu-latest + steps: + # Checkout the repository + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Important to fetch all tags and history + + # Determine the new version number + - name: Get latest tag and increment + id: versioning + run: | + # Fetch all tags + git fetch --tags + + # Get the highest tag number, and add 1 to the patch + TAG=$(git describe --tags `git rev-list --tags --max-count=1`) + echo "Current highest tag is $TAG" + + # Increment the patch version + NEW_TAG="${TAG%.*}.$((${TAG##*.}+1))" + echo "New tag will be $NEW_TAG" + + # Set NEW_TAG as an output variable + echo "NEW_VERSION=$NEW_TAG" >> $GITHUB_ENV + + # Create a new tag + - name: Create Git tag for PR + uses: actions/github-script@v7 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: "refs/tags/${{env.NEW_VERSION}}", + sha: context.sha + })