-
Notifications
You must be signed in to change notification settings - Fork 2
208 lines (182 loc) · 7.68 KB
/
release.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: 'release'
on:
workflow_call:
inputs:
main_branch:
description: Main branch, in format of a string, where a new major release is allowed
required: true
type: string
dist_branches:
required: true
description: Branches to execute on, in format of a string JSON array
type: string
version_bump:
required: false
description: Version bump (patch, minor, or major), or leave blank to infer from PR labels
type: string
version_ini_path:
required: false
description: Path to version.ini file (optional)
type: string
version_ini_prefix:
required: false
description: Content version.ini file (optional)
type: string
toml_conf_path:
required: false
description: Path to a TOML configuration file (optional)
type: string
toml_conf_version_key:
required: false
description: Version key in a TOML configuration file (optional)
type: string
package_json_version:
required: false
description: Update package.json version (optional, use 'true' or 'false' as a string)
type: string
default: 'false'
outputs:
version:
description: The final release version
value: ${{ jobs.release-on-push.outputs.version }}
major:
description: The release major version number
value: ${{ jobs.release-on-push.outputs.major }}
jobs:
debug:
if: github.event.pull_request.merged || inputs.version_bump != ''
runs-on: 'ubuntu-latest'
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: |
echo "$GITHUB_CONTEXT"
release-on-push:
if: github.event.pull_request.merged || inputs.version_bump != ''
runs-on: 'ubuntu-latest'
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Retrieve last tag on branch
run: |
echo "TAG_NAME=$(git describe --tags --match "v*.*.*" --abbrev=0 | cut -c 2-)" >> $GITHUB_OUTPUT
id: last_tag
- name: Debug last tag
run: |
echo last tag ${{ steps.last_tag.outputs.TAG_NAME }}
- uses: jungwinter/split@v2
id: split
with:
msg: ${{ steps.last_tag.outputs.TAG_NAME != '' && steps.last_tag.outputs.TAG_NAME || '0.0.0' }}
separator: '.'
maxsplit: 3
- name: Calculate new versions
env:
MAJOR: ${{ steps.split.outputs._0 }}
MINOR: ${{ steps.split.outputs._1 }}
PATCH: ${{ steps.split.outputs._2 }}
run: |
echo "NEW_MAJOR=$(echo $((MAJOR+1)).0.0)" >> $GITHUB_OUTPUT
echo "NEW_MINOR=$(echo $MAJOR.$((MINOR+1)).0)" >> $GITHUB_OUTPUT
echo "NEW_PATCH=$(echo $MAJOR.$MINOR.$((PATCH+1)))" >> $GITHUB_OUTPUT
id: versions
- name: New possible releases
run: |
echo new major ${{ steps.versions.outputs.NEW_MAJOR }}
echo new minor ${{ steps.versions.outputs.NEW_MINOR }}
echo new patch ${{ steps.versions.outputs.NEW_PATCH }}
- name: Extract branch name
shell: bash
run: echo "BRANCH=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
id: branch
- name: Debug branch name
run: |
echo current branch ${{ steps.branch.outputs.BRANCH }}
- name: Exit on bad tag
if: ${{ (inputs.version_bump == 'major' || (inputs.version_bump == '' && contains(github.event.pull_request.labels.*.name, 'release:major'))) && !contains(steps.branch.outputs.BRANCH, inputs.main_branch) }}
run: |
echo Can't create a major release on branch ${{ steps.branch.outputs.BRANCH }}
exit 1
- name: Exit on bad branch
if: ${{ !contains(fromJson(inputs.dist_branches), steps.branch.outputs.BRANCH) }}
run: |
echo Can't create a release on branch ${{ steps.branch.outputs.BRANCH }}
exit 1
- name: Prepare release tag env var
run: |
echo "RELEASE_VERSION=undefined" >> $GITHUB_ENV
- name: See if major release
if: inputs.version_bump == 'major' || (inputs.version_bump == '' && contains(github.event.pull_request.labels.*.name, 'release:major'))
run: |
echo "RELEASE_VERSION=${{ steps.versions.outputs.NEW_MAJOR }}" >> $GITHUB_ENV
- name: See if minor release
if: inputs.version_bump == 'minor' || (inputs.version_bump == '' && contains(github.event.pull_request.labels.*.name, 'release:minor'))
run: |
echo "RELEASE_VERSION=${{ steps.versions.outputs.NEW_MINOR }}" >> $GITHUB_ENV
- name: See if patch release
if: inputs.version_bump == 'patch' || (inputs.version_bump == '' && contains(github.event.pull_request.labels.*.name, 'release:patch'))
run: |
echo "RELEASE_VERSION=${{ steps.versions.outputs.NEW_PATCH }}" >> $GITHUB_ENV
- name: Exit if no release tag is found
if: contains(env.RELEASE_VERSION, 'undefined')
run: echo No release tag found - $RELEASE_VERSION
- name: Output release version
shell: bash
run: echo "VERSION=$(echo $RELEASE_VERSION)" >> $GITHUB_OUTPUT
id: version_release
- name: Debug release version
run: |
echo release version ${{ steps.version_release.outputs.VERSION }}
- uses: jungwinter/split@v2
id: split_new
with:
msg: '${{ steps.version_release.outputs.VERSION }}'
separator: '.'
maxsplit: 3
- name: Debug major release of new version
run: |
echo major release ${{ steps.split_new.outputs._0 }}
- name: Create new version file with .ini format (optional)
if: ${{ !contains(env.RELEASE_VERSION, 'undefined') && inputs.version_ini_path != '' }}
run: |
echo "${{ inputs.version_ini_prefix }}$RELEASE_VERSION" > ${{ inputs.version_ini_path }}
- name: Update TOML configuration file (optional)
if: ${{ !contains(env.RELEASE_VERSION, 'undefined') && inputs.toml_conf_path != '' && inputs.toml_conf_version_key != ''}}
uses: colathro/[email protected]
with:
file: "${{ inputs.toml_conf_path }}"
key: "${{ inputs.toml_conf_version_key }}"
value: "${{ env.RELEASE_VERSION }}"
- name: Check package.json file existence
id: check_files
uses: andstor/file-existence-action@v3
with:
files: "package.json"
- name: Update package.json version
if: ${{ !contains(env.RELEASE_VERSION, 'undefined') && steps.check_files.outputs.files_exists == 'true' && inputs.package_json_version == 'true' }}
uses: jossef/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
file: package.json
field: version
value: ${{ env.RELEASE_VERSION }}
- uses: stefanzweifel/git-auto-commit-action@v5
if: ${{ !contains(env.RELEASE_VERSION, 'undefined') && (inputs.version_ini_path != '' || inputs.toml_conf_path != '' || inputs.package_json_version == 'true') }}
with:
commit_message: "chore: update version"
branch: ${{ steps.branch.outputs.BRANCH }}
- name: Create release and tag
if: ${{ !contains(env.RELEASE_VERSION, 'undefined') }}
uses: ncipollo/release-action@v1
with:
name: 'Release ${{ env.RELEASE_VERSION }}'
tag: 'v${{ env.RELEASE_VERSION }}'
commit: ${{ steps.branch.outputs.BRANCH }}
generateReleaseNotes: true
outputs:
version: ${{ steps.version_release.outputs.VERSION }}
major: ${{ steps.split_new.outputs._0 }}