Skip to content

feat(github-actions): enhance script to handle initial release tagging #21

feat(github-actions): enhance script to handle initial release tagging

feat(github-actions): enhance script to handle initial release tagging #21

name: Auto Tagging And Release 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 -race -v ./...
tagging:
needs: [ test ]
if: success()
runs-on: ubuntu-latest
permissions:
contents: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0 # Fetch all history
- 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: |
chmod +x ./scripts/git/next_tag.sh
chmod +x ./scripts/git/commit_tag.sh
LATEST_TAG=$(./scripts/git/commit_tag.sh)
NEXT_TAG=$(./scripts/git/next_tag.sh)
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "NEXT_TAG=$NEXT_TAG" >> $GITHUB_OUTPUT
- name: Generate changelog
id: generate_changelog
run: |
LATEST_RELEASE=${{ steps.get_latest_release.outputs.LATEST_RELEASE }}
echo "# Changelog" > changelog.txt
if [[ -n "$LATEST_RELEASE" ]]; then
# If there's no previous release, get only the current commit's log
git config --global core.pager cat
# git log --pretty=format:"* %s (%an, %ar)"
git log --pretty=format:"* %s (%an, %ar)" >> changelog.txt
else
# Get all submission information since the last release
CHANGELOG=$(git log "$LATEST_RELEASE"..HEAD --pretty=format:"* %s (%an, %ar)")
git log "$LATEST_RELEASE"..HEAD --pretty=format:"* %s (%an, %ar)" >> changelog.txt
fi
- name: Create release
if: ${{ !steps.determine_next_version.outputs.LATEST_TAG }}
uses: softprops/action-gh-release@v1
with:
tag_name: Release ${{ steps.determine_next_version.outputs.NEXT_TAG }}
body_path: changelog.txt
draft: false
prerelease: false
- name: Create release (only if LATEST_TAG exists)
if: ${{ steps.determine_next_version.outputs.LATEST_TAG }}
uses: softprops/action-gh-release@v1
with:
body_path: changelog.txt
draft: false
prerelease: false