-
Notifications
You must be signed in to change notification settings - Fork 16
152 lines (133 loc) · 5.84 KB
/
release-bot.yaml
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# This job is not inteneded to be run manually. Instead it assumes that proper
# release commit is pushed to the repository. It will then create a new release
# on GitHub.
name: release-bot
on:
push:
branches:
- 'main'
- 'release/*'
permissions:
contents: read
jobs:
look_for_release:
outputs:
release_found: ${{ steps.commit_parser.outputs.release_found }}
release_type: ${{ steps.commit_parser.outputs.release_type }}
release_latest: ${{ steps.commit_parser.outputs.release_latest }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: search for release command in commit message
id: commit_parser
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const commitMessage = context.payload.head_commit.message
if (commitMessage.includes('chore(release): [bot]')) {
core.setOutput('release_found', 'true')
core.setOutput('release_type', 'release')
if (commitMessage.includes('[latest]')) {
core.setOutput('release_latest', 'true')
}
} else if (commitMessage.includes('chore(prerelease): [bot]')) {
core.setOutput('release_found', 'true')
core.setOutput('release_type', 'prerelease')
if (commitMessage.includes('[latest]')) {
core.setOutput('release_latest', 'true')
}
} else {
core.setOutput('release_found', 'false')
}
semver:
needs:
- look_for_release
if: ${{ needs.look_for_release.outputs.release_found == 'true' }}
outputs:
version: ${{ steps.semver_parser.outputs.fullversion }}
major: ${{ steps.semver_parser.outputs.major }}
minor: ${{ steps.semver_parser.outputs.minor }}
patch: ${{ steps.semver_parser.outputs.patch }}
prerelease: ${{ steps.semver_parser.outputs.prerelease }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Read version from VERSION file
run: |
VERSION=$(cat VERSION)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Parse semver string
id: semver_parser
uses: booxmedialtd/ws-action-parse-semver@7784200024d6b3fc01253e617ec0168daf603de3 # v1.4.7
with:
input_string: ${{ env.VERSION }}
version_extractor_regex: '(.*)$'
- name: check if tag already exists
uses: mukunku/tag-exists-action@bdad1eaa119ce71b150b952c97351c75025c06a9 # v1.6.0
id: tag_exists
with:
tag: ${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: fail if tag already exists
if: ${{ steps.tag_exists.outputs.exists == 'true' }}
run: exit 1
publish-release:
permissions:
contents: write
needs:
- look_for_release
- semver
if: ${{ needs.look_for_release.outputs.release_found == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: ncipollo/release-action@cdcc88a9acf3ca41c16c37bb7d21b9ad48560d87 # v1.15.0
with:
body: |
#### Download Kong Gateway Operator ${{ needs.semver.outputs.version }}:
- [Docker Image](https://hub.docker.com/r/${{ vars.DOCKERHUB_IMAGE_NAME }}/tags?name=${{ needs.semver.outputs.version }})
- [Get started](https://github.com/Kong/gateway-operator/blob/main/README.md)
#### Links:
- [Changelog](https://github.com/Kong/gateway-operator/blob/main/CHANGELOG.md#v${{ needs.semver.outputs.major }}${{ needs.semver.outputs.minor }}${{ needs.semver.outputs.patch }}${{ needs.semver.outputs.prerelease }})
token: ${{ secrets.GITHUB_TOKEN }}
tag: v${{ needs.semver.outputs.version }}
commit: ${{ github.sha }}
prerelease: ${{ needs.look_for_release.outputs.release_type == 'prerelease' }}
create-release-branch:
permissions:
contents: write
needs:
- look_for_release
- publish-release
- semver
# NOTE: only create a release branch if the release is not a patch release
# or a prerelease.
# For patch releases, the release branch should already be in place.
# For prereleases, we do not want to create a release branch.
if: ${{ needs.look_for_release.outputs.release_found == 'true' && needs.semver.outputs.patch == '0' && needs.semver.outputs.prerelease == '' }}
runs-on: ubuntu-latest
steps:
- uses: peterjgrainger/action-create-branch@10c7d268152480ae859347db45dc69086cef1d9c # v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# NOTE: using the full ref name because
# https://github.com/peterjgrainger/action-create-branch?tab=readme-ov-file#branch
branch: 'refs/heads/release/v${{ needs.semver.outputs.major }}.${{ needs.semver.outputs.minor }}.x'
sha: '${{ github.sha }}'
create-cherry-pick-branch-to-main:
permissions:
contents: write
needs:
- look_for_release
- publish-release
- semver
if: ${{ needs.look_for_release.outputs.release_found == 'true' && needs.semver.outputs.patch != '0' && needs.semver.outputs.prerelease == '' && needs.look_for_release.outputs.release_latest == 'true' && github.ref_name != 'main' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: carloscastrojumo/github-cherry-pick-action@503773289f4a459069c832dc628826685b75b4b3 # v1.0.10
with:
branch: main
title: '[cherry-pick] ${{ needs.semver.outputs.version }} - ${{ github.sha }}'
body: 'Cherry picking ${{ needs.semver.outputs.version }} commit (${{ github.sha }}) onto main'