-
Notifications
You must be signed in to change notification settings - Fork 86
87 lines (77 loc) · 2.89 KB
/
hotfix.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
name: Hotfix Release
permissions:
contents: write
on:
pull_request_target:
types: [closed]
branches:
- main
jobs:
hotfix_release:
if: ${{ github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'hotfix') }}
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
with:
token: "${{ secrets.HOTFIX_ACTION_JOB }}"
fetch-depth: 0
- name: Configure git
run: |
git config user.name 'github-actions-bot'
git config user.email '[email protected]'
git fetch --tags
- name: Get latest release version tag
id: fetch_tag
run: |
LATEST_VERSION=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')
if ! [[ "$LATEST_VERSION" =~ ^v[0-9]+\.[0-9]+\..* ]]; then
echo "Invalid tag format, cannot bump version of: $LATEST_VERSION"
exit 1
fi
echo "latest=$LATEST_VERSION" >> $GITHUB_OUTPUT
- name: Determine next patch version
id: bump
run: |
VERSION="${{ steps.fetch_tag.outputs.latest }}"
VERSION_NO_PREFIX="${VERSION#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_NO_PREFIX"
NEW_PATCH=$((PATCH + 1))
NEW_TAG="v$MAJOR.$MINOR.$NEW_PATCH"
echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT
- name: Create and switch to hotfix branch
run: |
git checkout "${{ steps.fetch_tag.outputs.latest }}"
git checkout -b "hotfix/${{ steps.bump.outputs.tag }}"
- name: Cherry-pick merged commit
run: |
MERGE_COMMIT_SHA="${{ github.event.pull_request.merge_commit_sha }}"
if ! git cherry-pick "$MERGE_COMMIT_SHA"; then
echo "Cherry-pick failed. Please resolve conflicts manually."
exit 1
fi
- name: Create and push tag
id: tag_version
run: |
git tag "${{ steps.bump.outputs.tag }}"
git push origin "${{ steps.bump.outputs.tag }}"
- name: "Create hotfix release"
uses: actions/github-script@v6
with:
github-token: "${{ secrets.HOTFIX_ACTION_TOKEN }}"
script: |
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: "Hotfix ${{ steps.bump.outputs.tag }}",
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: "${{ steps.bump.outputs.tag }}",
});
core.exportVariable('RELEASE_ID', response.data.id);
core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url);
} catch (error) {
core.setFailed(error.message);
}