Skip to content

Commit

Permalink
feat(github-actions): trigger tagging workflow on main branch push, r…
Browse files Browse the repository at this point in the history
…emove tag inputs

- Change the trigger event for tagging workflow from tag pushes to main
  branch pushes to facilitate continuous tagging.
- Remove unnecessary tag inputs and associated logic as the tagging
  process is now automated without user inputs.
- Simplify workflow steps by eliminating the 'untagging' job and refactoring the 'tagging' job to automatically determine the next
  version based on the latest tag.
  • Loading branch information
godcong committed Jul 10, 2024
1 parent f6f9daf commit 1bd7882
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions .github/workflows/tag_after_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ name: Manual Tagging After Tests

on:
push:
tags:
- "v*" # The pattern here matches the tag naming convention you will use
workflow_dispatch:
inputs:
tag_name:
description: "Tag name"
required: true
default: "v0.0.1"
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0 # Fetch all history

- name: Set up Go
uses: actions/setup-go@v3
Expand All @@ -27,40 +24,46 @@ jobs:
run: |
go test -v ./...
untagging:
tagging:
needs: [ test ]
if: failure()
if: success()
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use your PAT here instead of the default token
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
ref: main
fetch-depth: 0 # Fetch all history

- name: Untag release
- name: Get current version
id: get_current_version
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Actions"
git tag -d ${{ github.ref_name }} # Delete local tag
git push origin :refs/tags/${{ github.ref_name }} # Delete remote tag
CURRENT_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "CURRENT_TAG=$CURRENT_TAG" >> $GITHUB_OUTPUT
tagging:
needs: [ test ]
if: success()
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use your PAT here instead of the default token
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Determine next version
id: determine_next_version
run: |
if [[ -z "${{ steps.get_current_version.outputs.CURRENT_TAG }}" ]]; then
NEXT_TAG="v0.0.1"
else
VERSION_ARRAY=(${{
steps.get_current_version.outputs.CURRENT_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: Tag release
if: ${{ steps.determine_next_version.outputs.NEXT_TAG != '' }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Actions"
git tag ${{ github.event.inputs.tag_name }}
git push origin ${{ github.event.inputs.tag_name }}
git tag ${{ steps.determine_next_version.outputs.NEXT_TAG }}
git push origin ${{ steps.determine_next_version.outputs.NEXT_TAG }}

0 comments on commit 1bd7882

Please sign in to comment.