-
Notifications
You must be signed in to change notification settings - Fork 6
55 lines (55 loc) · 1.53 KB
/
tag.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: Tag a repo with few checks
on:
workflow_call:
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
default: latest
secrets:
OPENG2P_BOT_GITHUB_PAT:
required: true
jobs:
tag-repo:
runs-on: ubuntu-latest
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: Check if the branch has moved at all
run: |
check_branch_and_exit (){
if [[ -z $(git diff $1) ]]; then
echo "::error::No changes on this branch. Tag not created"
exit 1
fi
}
if [[ "${{ inputs.previous-tag }}" == "latest" ]]; then
latest_tag=$(git describe --tags)
check_branch_and_exit "$latest_tag"
elif [[ "${{ inputs.previous-tag }}" == "None" ]]; then
echo ""
else
check_branch_and_exit "${{ inputs.previous-tag }}"
fi
- name: Create tag and push
run: |
git tag ${{ inputs.new-tag }}
git push origin ${{ inputs.new-tag }}