Tagging #119
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: Tagging | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "deployment/*" | |
workflow_run: | |
workflows: | |
- CI | |
types: | |
- completed | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
COMMIT_MSG: ${{ github.event.head_commit.message }} | |
jobs: | |
tagging: | |
runs-on: ubuntu-latest | |
if: ${{ contains(github.ref, 'main') }} | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v4 | |
- name: Fetch remote tags | |
run: git fetch origin +refs/tags/*:refs/tags/* | |
- name: Set Tag Value | |
run: | | |
echo "DATE=v$(echo `date +'%Y.%m'`)" >> $GITHUB_ENV | |
echo "CHANGELOG=`git log --oneline $(git describe --tags v2021.08 --abbrev=0 @^ | head -n 1)..@`" >> $GITHUB_ENV | |
- name: Create Tag | |
uses: actions/github-script@v6 | |
if: ${{ env.DATE }} | |
with: | |
github-token: ${{ github.token }} | |
script: | | |
let tagExists = []; | |
try { | |
await github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "refs/tags/${{ env.DATE }}", | |
message: "${{ env.CHANGELOG }}", | |
sha: context.sha | |
}); | |
} catch (e) { | |
console.log("Tag already exists: " + e) | |
tagExists.push(e); | |
} | |
if (tagExists.length > 0) { | |
await github.rest.git.updateRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "tags/${{ env.DATE }}", | |
message: "${{ env.CHANGELOG }}", | |
sha: context.sha | |
}); | |
} |