Tag a repo with few checks #13
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: Tag a repo with few checks | |
on: | |
workflow_dispatch: | |
inputs: | |
new-tag: | |
description: Tag in "vN.N.N" format | |
required: true | |
type: string | |
previous-tag: | |
description: Previous tag. "None" if no previous tag | |
required: true | |
type: string | |
jobs: | |
tag-repo: | |
runs-on: ubuntu-latest | |
env: | |
SKIP: 'FALSE' | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Checkout branch for publishing | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.OPENG2P_BOT_GITHUB_PAT }} | |
fetch-depth: 0 | |
- name: Check tag convention | |
run: | | |
pattern="^v[0-9].[0-9].[0-9]$" | |
if ! [[ ${{ inputs.new-tag }} =~ $pattern ]]; then | |
echo "Tag convention not followed" | |
exit 1 | |
fi | |
- name: If tag is None | |
run: | | |
if [[ ${{ inputs.previous-tag }} -eq "None" ]]; then | |
echo "SKIP=TRUE" >> $GITHUB_ENV | |
fi | |
- name: Check if the branch has moved at all | |
run: | | |
if [[ -z $(git diff ${{ inputs.previous-tag }}) ]]; then | |
echo "No changes on this branch. Tag not created" | |
exit 1 | |
fi | |
if: env.SKIP != 'TRUE' | |
- name: Create tag and push | |
run: | | |
git tag ${{ inputs.new-tag }} | |
git push origin ${{ inputs.new-tag }} |