-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Tag Prefix Workflow | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
tag-and-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Git | ||
run: | | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --global user.name "GitHub Actions" | ||
- name: Push Additional Tags with Dynamic Prefixes | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
ORIGINAL_TAG=${GITHUB_REF#refs/tags/} | ||
# Find directories containing go.mod, extract directory names, and push tags with these names as prefixes | ||
find . -maxdepth 2 -type f -name "go.mod" | while read -r line; do | ||
DIR_NAME=$(dirname "$line") | ||
PREFIX=${DIR_NAME#"./"} # Remove leading "./" | ||
# Check if PREFIX is not empty and not the root directory | ||
if [[ -n "$PREFIX" && "$PREFIX" != "." ]]; then | ||
NEW_TAG="${PREFIX}/${ORIGINAL_TAG}" | ||
echo "Creating and pushing tag: $NEW_TAG" | ||
git tag $NEW_TAG $ORIGINAL_TAG | ||
git push origin $NEW_TAG | ||
else | ||
echo "Skipping root directory" | ||
fi | ||
done |