chore: fix git workflow syntax #6
Workflow file for this run
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 Main Branch | |
on: | |
push: | |
branches: | |
- test-tag-branch | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
tag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Git | |
run: | | |
git config --global user.name 'GitHub Actions' | |
git config --global user.email '[email protected]' | |
- name: Fetch all tags | |
run: | | |
git fetch --tags | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
# Get the latest tag | |
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "none") | |
echo "Latest tag: $latest_tag" | |
echo "latest_tag=$latest_tag" >> $GITHUB_ENV | |
- name: Determine next tag version | |
id: get_next_version | |
run: | | |
latest_tag=${{ env.latest_tag }} | |
if [[ "$latest_tag" == "none" ]]; then | |
echo "No tags found. Starting with v0.0.1" | |
next_tag="v0.0.1" | |
elif [[ $latest_tag =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
major=${BASH_REMATCH[1]} | |
minor=${BASH_REMATCH[2]} | |
patch=${BASH_REMATCH[3]} | |
next_patch=$((patch + 1)) | |
next_tag="v${major}.${minor}.${next_patch}" | |
else | |
echo "Latest tag format is invalid, cannot determine next version." | |
exit 1 | |
fi | |
echo "Next tag version: $next_tag" | |
echo "next_tag=$next_tag" >> $GITHUB_ENV | |
- name: Create and push new tag | |
env: | |
TAG_NAME: ${{ env.next_tag }} | |
run: | | |
git tag $TAG_NAME | |
git push origin $TAG_NAME |