Skip to content

fix(github-actions): remove redundant LATEST_TAG assignment in tag_af… #9

fix(github-actions): remove redundant LATEST_TAG assignment in tag_af…

fix(github-actions): remove redundant LATEST_TAG assignment in tag_af… #9

name: Auto Tagging After Tests
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0 # Fetch all history
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.5
- name: Run tests
run: |
go test -v ./...
tagging:
needs: [ test ]
if: success()
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0 # Fetch all history
- name: Check for existing tags on latest main
id: check_tags
run: |
# Gets the hash of the current HEAD
CURRENT_COMMIT=$(git rev-parse HEAD)
# Finds labels that match the current commit
TAG_FOR_CURRENT_COMMIT=$(git tag --points-at "$CURRENT_COMMIT")
# Check for labels
if [ -n "$TAG_FOR_CURRENT_COMMIT" ]; then
# Converts a list of labels to an array
IFS=$'\n' read -d '' -r -a TAGS_ARRAY <<< "$TAG_FOR_CURRENT_COMMIT"
# Find the latest tags, assuming the tags are in chronological order
LATEST_TAG=${TAGS_ARRAY[-1]}
echo "$LATEST_TAG"
fi
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: Get latest release
id: get_latest_release
run: |
LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ env.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')
echo "LATEST_RELEASE=$LATEST_RELEASE" >> $GITHUB_OUTPUT
- name: Determine next version
id: determine_next_version
run: |

Check failure on line 65 in .github/workflows/tag_after_test.yml

View workflow run for this annotation

GitHub Actions / Auto Tagging After Tests

Invalid workflow file

The workflow is not valid. .github/workflows/tag_after_test.yml (Line: 65, Col: 14): The expression is not closed. An unescaped ${{ sequence was found, but the closing }} sequence was not found.
LATEST_TAG=${{ steps.check_tags.outputs.LATEST_TAG }}
if [[ -z "$LATEST_TAG" ]]; then
NEXT_TAG="v0.0.1"
else
VERSION_ARRAY=(${{ steps.check_tags.outputs.LATEST_TAG }#.v}~'.')
MAJOR=${VERSION_ARRAY[0]}
MINOR=${VERSION_ARRAY[1]}
PATCH=${VERSION_ARRAY[2]}
let PATCH+=1
NEXT_TAG=v$MAJOR.$MINOR.$PATCH
fi
echo "NEXT_TAG=$NEXT_TAG" >> $GITHUB_OUTPUT
- name: Generate changelog
id: generate_changelog
run: |
LATEST_RELEASE=${{ steps.get_latest_release.outputs.LATEST_RELEASE }}
if [[ -z "$LATEST_RELEASE" ]]; then
# If no release, start from the first commit
CHANGELOG=$(git log --pretty=format:"* %s (%an, %ar)" --reverse)
else
# Get all submission information since the last release
CHANGELOG=$(git log "$LATEST_RELEASE"..HEAD --pretty=format:"* %s (%an, %ar)")
fi
echo "CHANGELOG=$CHANGELOG" >> $GITHUB_OUTPUT
- name: Create release
if: ${{ steps.determine_next_version.outputs.NEXT_TAG }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.determine_next_version.outputs.NEXT_TAG }}
body: |
# Changelog
${{ steps.generate_changelog.outputs.CHANGELOG }}
draft: false
prerelease: false