-
Notifications
You must be signed in to change notification settings - Fork 0
231 lines (202 loc) · 8.91 KB
/
Copy pathcode-release_preview.yml
File metadata and controls
231 lines (202 loc) · 8.91 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
---
name: code-release-preview
concurrency:
group: release-preview
cancel-in-progress: true
on:
pull_request:
types: [labeled, synchronize, ready_for_review, opened]
branches: ['main', 'main-*']
env:
PR_HEAD_REF: ${{ github.head_ref }}
jobs:
check-changes-in-paths:
name: Check for changes in corresponding paths
permissions:
contents: read
pull-requests: read
runs-on: ubuntu-24.04
if: ${{ github.event.pull_request.draft == false || contains(join(github.event.pull_request.labels.*.name, ', '), 'release-type') || contains(join(github.event.pull_request.labels.*.name, ', '), 'release-preview') }}
outputs:
detected: ${{ steps.changes.outputs.paths }}
steps:
- name: Check for changed files in specific paths
id: changes
uses: dorny/paths-filter@ebc4d7e9ebcb0b1eb21480bb8f43113e996ac77a # v3.0.1
with:
filters: |
paths:
- 'code/**'
- '.github/workflows/code*'
release-preview:
name: Release Preview
permissions:
contents: read
pull-requests: write
needs: check-changes-in-paths
if: ${{ (contains(join(github.event.pull_request.labels.*.name, ', '), 'release-type') || contains(join(github.event.pull_request.labels.*.name, ', '), 'release-preview')) && needs.check-changes-in-paths.outputs.detected == 'true' }}
runs-on: ubuntu-24.04
steps:
- name: Checkout merge commit
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Maven Cache
uses: actions/cache@v4
continue-on-error: true
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Setup asdf Cache
uses: actions/cache@v4
continue-on-error: true
with:
path: ~/.asdf/data
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
restore-keys: |
${{ runner.os }}-asdf-
- name: Validate tool-versions content
run: |
if grep -Evq '^[a-zA-Z0-9_-]+ [a-zA-Z0-9._+-]+$' code/.tool-versions; then
echo "::error::Invalid .tool-versions content detected"
exit 1
fi
- name: Save tool-versions content
run: |
{
echo "TOOL_VERSIONS<<EOF"
cat code/.tool-versions
echo "EOF"
} >> "$GITHUB_ENV"
- name: Setup asdf environment
uses: asdf-vm/actions/install@b7bcd026f18772e44fe1026d729e1611cc435d47 # v4
with:
tool_versions: ${{ env.TOOL_VERSIONS }}
- name: Setup Java environment vars
run: |
JAVA_HOME="$(asdf where java)"
echo "JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: Setup hotfix release type version and simulate merge
if: ${{ contains(github.event.pull_request.labels.*.name, 'release-type/hotfix') }}
run: echo "RELEASE_VERSION=patch" >> "$GITHUB_ENV"
- name: Setup multi-hotfix release type version
if: contains(github.event.pull_request.labels.*.name, 'release-type/multi-hotfix')
run: echo "RELEASE_VERSION=patch" >> "$GITHUB_ENV"
- name: Setup patch release type version
if: contains(github.event.pull_request.labels.*.name, 'release-type/patch')
run: echo "RELEASE_VERSION=patch" >> "$GITHUB_ENV"
- name: Setup minor release type version
if: contains(github.event.pull_request.labels.*.name, 'release-type/minor')
run: echo "RELEASE_VERSION=minor" >> "$GITHUB_ENV"
- name: Setup major release type version
if: contains(github.event.pull_request.labels.*.name, 'release-type/major')
run: echo "RELEASE_VERSION=major" >> "$GITHUB_ENV"
- name: Check merge strategy
run: |
if [[ "$PR_HEAD_REF" == hotfix* && "${{ contains(github.event.pull_request.labels.*.name, 'release-type/multi-hotfix') }}" != "true" ]] ;
then
echo "MERGE_STRATEGY=Squash and Merge" >> "$GITHUB_ENV"
elif [[ "${{vars.DEVELOPMENT_FLOW}}" == 'trunk-based-development' && ("$PR_HEAD_REF" == hotfix* && "${{ contains(github.event.pull_request.labels.*.name, 'release-type/multi-hotfix') }}" == "true") ]] ;
then
echo "MERGE_STRATEGY=Create a merge commit" >> "$GITHUB_ENV"
elif [[ "${{ vars.DEVELOPMENT_FLOW }}" == 'trunk-based-development' ]] ;
then
echo "MERGE_STRATEGY=Squash and Merge" >> "$GITHUB_ENV"
else
echo "MERGE_STRATEGY=Create a merge commit" >> "$GITHUB_ENV"
fi
- name: Check if CHANGELOG.md has changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if git diff --quiet HEAD^ HEAD -- code/CHANGELOG.md; then
echo "::error title={No CHANGELOG.md changes}::{No CHANGELOG.md changes were found. Update the UNRELEASED section with the new changes.}"
gh pr comment ${{ github.event.number }} --body "
### :x: No changes in the \`CHANGELOG.md\` file
No changes were found in the \`CHANGELOG.md\` file. Please, update the UNRELEASED section, listing the new changes that applies to this release."
exit 1
fi
- name: Update CHANGELOG.md
id: update-changelog
uses: release-flow/keep-a-changelog-action@74931dec7ecdbfc8e38ac9ae7e8dd84c08db2f32 # v3.0.0
with:
command: bump
version: ${{ env.RELEASE_VERSION }}
changelog: code/CHANGELOG.md
fail-on-empty-release-notes: false
keep-unreleased-section: true
tag-prefix: ""
- name: Add PR comment with release preview
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TASKS=$(awk -v version="${{ steps.update-changelog.outputs.version }}" '
BEGIN { capture=0; found_version=0 }
$0 ~ "## \\[" version "\\] -" { capture=1; found_version=1; print; next }
capture && $0 ~ /^## \[.*\] -/ { capture=0 }
capture { print }
END {
if (found_version) {
while ((getline line < "code/CHANGELOG.md") > 0) {
if (line ~ /^\[.*\]:/) {
print line
}
}
}
}
' code/CHANGELOG.md)
MESSAGE="
### :rocket: Release Preview Success
You are going to release the version **${RELEASE_VERSION}** with the following changes:
$TASKS
### 💡 Merge Strategy: $MERGE_STRATEGY
Remember to use the **'$MERGE_STRATEGY'** strategy to merge this _Pull Request (\`$PR_HEAD_REF\` → \`${{ github.event.pull_request.base.ref }}\`)_.
"
gh pr comment ${{ github.event.number }} --body "$(echo -e "$MESSAGE")"
release-preview-no-code-changes:
name: Add PR comment with configuration management information
permissions:
contents: read
pull-requests: write
needs: check-changes-in-paths
if: ${{ (contains(join(github.event.pull_request.labels.*.name, ', '), 'release-type') || (contains(join(github.event.pull_request.labels.*.name, ', '), 'release-preview'))) && needs.check-changes-in-paths.outputs.detected == 'false' }}
runs-on: ubuntu-24.04
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout merge commit
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Add PR comment with release preview
run: |
BODY="
### :exclamation: :exclamation: :exclamation: This Pull Request will not trigger a Release
A Pull Request with no changes to the \`code/\` folder will not trigger a release"
gh pr comment ${{ github.event.number }} --body "$BODY"
release-preview-no-release-labels:
name: Add PR comment with release information
permissions:
contents: read
pull-requests: write
needs: check-changes-in-paths
if: ${{ !contains(join(github.event.pull_request.labels.*.name, ', '), 'release-type') && needs.check-changes-in-paths.outputs.detected == 'true' && github.event.pull_request.draft == false && vars.DEVELOPMENT_FLOW != 'trunk-based-development' }}
runs-on: ubuntu-24.04
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout merge commit
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Add PR comment with release preview
run: |
gh pr comment ${{ github.event.number }} --body "
### :exclamation: :exclamation: :exclamation: This Pull Request will not trigger a Release
A Pull Request with no \`release-type/...\` labels will not trigger a release, so you need to label this PR if you want to create a release.
"