-
Notifications
You must be signed in to change notification settings - Fork 1.4k
114 lines (97 loc) · 3.91 KB
/
create-hotfix-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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Create tag on hotfix branch
on:
workflow_dispatch:
jobs:
create_tag:
runs-on: ubuntu-latest
steps:
- name: Generate a token
if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.HYPERSWITCH_BOT_APP_ID }}
private-key: ${{ secrets.HYPERSWITCH_BOT_APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}
- name: Install git-cliff
uses: baptiste0928/cargo-install@v2.2.0
with:
crate: git-cliff
version: 1.2.0
- name: Check if the input is valid hotfix branch
shell: bash
run: |
if [[ ${{github.ref}} =~ ^refs/heads/hotfix-[0-9]{4}\.[0-9]{2}\.[0-9]{2}\.[0-9]+$ ]]; then
echo "::notice::${{github.ref}} is a valid hotfix branch."
else
echo "::error::${{github.ref}} is not a valid hotfix branch."
exit 1
fi
- name: Check if the latest commit is tag
shell: bash
run: |
if [[ -z "$(git tag --points-at HEAD)" ]]; then
echo "::notice::The latest commit is not a tag "
else
echo "::error::The latest commit on the branch is already a tag"
exit 1
fi
- name: Determine current and next tag
shell: bash
run: |
function get_next_tag() {
local previous_tag="${1}"
local previous_hotfix_number
local next_tag
previous_hotfix_number="$(echo "${previous_tag}" | awk -F. '{ print $4 }' | sed -E 's/([0-9]+)(-hotfix([0-9]+))?/\3/')"
if [[ -z "${previous_hotfix_number}" ]]; then
# Previous tag was not a hotfix tag
next_tag="${previous_tag}-hotfix1"
else
# Previous tag was a hotfix tag, increment hotfix number
local hotfix_number=$((previous_hotfix_number + 1))
next_tag="${previous_tag/%${previous_hotfix_number}/${hotfix_number}}"
fi
echo "${next_tag}"
}
# Search for date-like tags (no strict checking), sort and obtain previous tag
PREVIOUS_TAG="$(
git tag --merged \
| grep --extended-regexp '[0-9]{4}\.[0-9]{2}\.[0-9]{2}' \
| sort --version-sort \
| tail --lines 1
)"
NEXT_TAG="$(get_next_tag "${PREVIOUS_TAG}")"
echo "PREVIOUS_TAG=${PREVIOUS_TAG}" >> $GITHUB_ENV
echo "NEXT_TAG=${NEXT_TAG}" >> $GITHUB_ENV
- name: Generate changelog
shell: bash
run: |
# Generate changelog content and store it in `release-notes.md`
git-cliff --config '.github/git-cliff-changelog.toml' --strip header --tag "${NEXT_TAG}" "${PREVIOUS_TAG}^.." \
| sed "/## ${PREVIOUS_TAG#v}\$/,\$d" \
| sed '$s/$/\n- - -/' > release-notes.md
# Append release notes after the specified pattern in CHANGELOG.md
sed --in-place '0,/^- - -/!b; /^- - -/{
a
r release-notes.md
}' CHANGELOG.md
rm release-notes.md
- name: Set Git Configuration
shell: bash
run: |
git config --local user.name 'hyperswitch-bot[bot]'
git config --local user.email '148525504+hyperswitch-bot[bot]@users.noreply.github.com'
- name: Push created commit and tag
shell: bash
run: |
# Stage, commit and tag the changelog
git add CHANGELOG.md
git commit --message "chore(version): ${NEXT_TAG}"
git tag --message "$(git show --no-patch --format=%s HEAD)" "${NEXT_TAG}" HEAD
git push
git push --tags