-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(github-actions): trigger tagging workflow on main branch push, r…
…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
Showing
1 changed file
with
32 additions
and
29 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 }} |