-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
89 lines (84 loc) · 2.75 KB
/
action.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: GitHub tagger
description: Bump and push git tag
inputs:
token:
description: Required for permission to tag the repo.
required: true
with_month:
description: Add the month number as a second part of the tag.
default: false
add_tag:
description: Add a tag to the commit.
default: true
outputs:
new_tag:
description: 'Generated tag'
value: ${{ steps.new-tag-step.outputs.tag }}
old_tag:
description: 'Old tag'
value: ${{ steps.old-tag-step.outputs.tag }}
runs:
using: composite
steps:
- name: Get existing comment
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Search for existing tag
id: find-tag
shell: bash
run: |
echo "tag=$(git tag -l --points-at ${{ github.event.pull_request.head.sha || github.sha }})" >> $GITHUB_OUTPUT
- name: Raise error if tag already exists
if: ${{ steps.find-tag.outputs.tag }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('Tag (${{ steps.find-tag.outputs.tag }}) already exists on current commit (${{ github.event.pull_request.head.sha || github.sha }})')
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Get current tag
shell: bash
id: old-tag-step
run: |
echo "tag=$(git describe --tags --first-parent --abbrev=0)" >> $GITHUB_OUTPUT
- name: Get new tag
id: new-tag-step
shell: python
run: |
import os
import re
from datetime import date
old_tag = '${{ steps.old-tag-step.outputs.tag }}'
with_month = '${{ inputs.with_month }}' == 'true'
today = date.today()
if with_month:
# e.g. 2022.5.10
if re.match(r'\d{4}\.\d{1,2}\.\d+', old_tag):
year, month, build = map(int, old_tag.split('.'))
else:
year, month, build = 0, 0, 0
if today.year != year or today.month != month:
build = 0
build += 1
new_tag = f'{today.year}.{today.month}.{build}'
else:
# e.g. 2022.146
if old_tag:
year, build = [int(x) if x.isdigit() else 0 for x in old_tag.split('.', maxsplit=1)]
else:
year, build = 0, 0
if today.year != year:
build = 0
build += 1
new_tag = f'{today.year}.{build}'
with open(os.getenv("GITHUB_OUTPUT"), 'w') as f:
print(f'tag={new_tag}', file=f)
- name: GitHub tag bump
if: inputs.add_tag == 'true'
uses: anothrNick/github-tag-action@f278d49d30cdd8775cc3e7dd00b5ee11686ee297 # 1.38.0
env:
GITHUB_TOKEN: ${{ inputs.token }}
CUSTOM_TAG: ${{ steps.new-tag-step.outputs.tag }}