fix build tagging #3
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
name: Tag on PR Merge | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
tag_version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
# Fetch all tags from the remote | |
git fetch --tags | |
# Get the latest tag from git | |
latest_tag=$(git describe --tags --abbrev=0 --match "v*") | |
echo "Latest tag: $latest_tag" | |
# If there are no tags, start from v0.0.0 | |
if [ -z "$latest_tag" ]; then | |
echo "v0.0.0" > latest_tag.txt | |
else | |
echo "$latest_tag" > latest_tag.txt | |
fi | |
- name: Increment version | |
id: increment_version | |
run: | | |
latest_tag=$(cat latest_tag.txt) | |
# Remove the 'v' from the version to work with the numbers | |
version_without_v=${latest_tag#v} | |
# Split the tag into major, minor, and patch versions | |
IFS='.' read -r -a version_parts <<< "$version_without_v" | |
major=${version_parts[0]} | |
minor=${version_parts[1]} | |
patch=${version_parts[2]} | |
# Increment the patch version | |
new_patch=$((patch + 1)) | |
new_version="v$major.$minor.$new_patch" | |
echo "New version: $new_version" | |
# Save the new version to the GitHub environment to be used in future steps | |
echo "new_version=$new_version" >> $GITHUB_ENV | |
- name: Create and push new tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }} | |
run: | | |
new_version=${{ env.new_version }} | |
# Create a new tag | |
git tag "$new_version" | |
# Push the new tag to the remote repository | |
git push origin "$new_version" |