Update Release Tag in File #13
Workflow file for this run
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
name: Update Release Tag in File | |
on: | |
push: | |
tags: | |
- '*' # Triggers when any tag is pushed | |
jobs: | |
update-file: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch full history | |
token: ${{ secrets.GIT_HUB_TOKEN }} | |
- name: Extract tag name | |
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Checkout the tagged commit | |
run: | | |
git checkout $TAG_NAME | |
git switch -c temp-branch # Create a new branch from the tag | |
- name: Check if file already contains the tag | |
id: check-tag | |
run: | | |
if grep -q "${TAG_NAME}" config/config.go; then | |
echo "Tag already present. Skipping commit." | |
echo "SKIP_COMMIT=true" >> $GITHUB_ENV | |
fi | |
- name: Replace template string in file | |
if: env.SKIP_COMMIT != 'true' | |
run: sed -i "s/{{RELEASE_TAG}}/${TAG_NAME}/g" config/config.go | |
- name: Commit and push changes | |
if: env.SKIP_COMMIT != 'true' | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git commit -am "Update release tag to ${TAG_NAME}" | |
git tag -f $TAG_NAME # Force update the tag | |
git push origin temp-branch:$TAG_NAME --force # Update the tag |