-
Notifications
You must be signed in to change notification settings - Fork 2
321 lines (275 loc) · 10.4 KB
/
create-release.yml
File metadata and controls
321 lines (275 loc) · 10.4 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
name: Create Release
on:
push:
branches:
- main
concurrency: release
env:
BUILDERS_FILEPATH: "builders.json"
jobs:
preparation:
name: Preparation
runs-on: ubuntu-24.04
outputs:
builders: ${{ steps.get-builders.outputs.builders }}
combos: ${{ steps.get_combos.outputs.combos }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Get Builders
id: get-builders
run: |
builders=$(jq -n -c '[]')
if [ -f ${{ env.BUILDERS_FILEPATH }} ]; then
builders=$(jq -c '.builders' ${{ env.BUILDERS_FILEPATH }})
else
# Strip off the Github org prefix from repo name
# paketo-buildpacks/builder-with-some-name --> builder-with-some-name
registry_repo=$(echo "${{ github.repository }}" | sed 's/^.*\///')
builders=$(jq -n -c '[
{
"name": "'"${registry_repo}"'",
"path": ".",
"container_repository": "'"${registry_repo}"'",
"test_runners": ["ubuntu-24.04"]
}
]')
fi
# Filter only the necessary fields
builders=$(echo "$builders" | jq 'map({
name,
path,
container_repository,
test_runners
})')
builders=$(jq -c <<< "$builders")
echo "builders=$builders"
echo "builders=$builders" >> "$GITHUB_OUTPUT"
- name: Get Combos
id: get_combos
run: |
builders=$(echo '${{ steps.get-builders.outputs.builders }}' | jq -c '.[]')
combos=$(jq -n -c '[]')
for builder in $builders; do
runners=$(echo $builder | jq -r '.test_runners[]')
builder_name=$(echo $builder | jq -r '.name')
builder_path=$(echo $builder | jq -r '.path')
for runner in $runners; do
combos=$(
jq \
--arg builder_name "$builder_name" \
--arg runner "$runner" \
--arg builder_path "$builder_path" \
'. + [{"builder": $builder_name, "runner": $runner, "path": $builder_path}]' \
<<< "$combos"
)
done
done
combos=$(jq -c <<< "$combos")
echo "combos=$combos"
echo "combos=$combos" >> "$GITHUB_OUTPUT"
builder_files_changed:
name: Builder Files Changed
runs-on: ubuntu-24.04
needs: preparation
outputs:
builders_changed: ${{ steps.compare_previous_release.outputs.builders_changed }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0 # gets full history
- name: Compare previous releases
id: compare_previous_release
run: |
builders=$(echo '${{ needs.preparation.outputs.builders }}' | jq -c '.[]')
for builder in $builders; do
builder_path=$(echo "$builder" | jq -r '.path')
changed=$(git diff --name-only $(git describe --tags --abbrev=0) -- $builder_path/builder.toml)
if [ -z "${changed}" ]
then
# We do not write on the github output because this step runs multiple times
# and it might overwrite any true value written by the else statement.
echo "No changes for $builder_path/builder.toml"
else
echo "Changes detected for $builder_path/builder.toml"
echo "builders_changed=true" >> $GITHUB_OUTPUT
fi
done
smoke:
name: Smoke Test
needs: [preparation, builder_files_changed]
if: ${{ needs.builder_files_changed.outputs.builders_changed == 'true' }}
strategy:
matrix:
combos: ${{ fromJSON(needs.preparation.outputs.combos) }}
runs-on: ${{ matrix.combos.runner }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Run Smoke Tests
run: ./scripts/smoke.sh --builder-dir "${{ matrix.combos.path }}"
get_builders_info:
name: Get Builders Info
runs-on: ubuntu-24.04
needs: [preparation, builder_files_changed, smoke]
strategy:
matrix:
builders: ${{ fromJSON(needs.preparation.outputs.builders) }}
services:
registry:
image: registry:3
ports:
- 5000:5000
outputs:
builder_info: ${{ steps.notes.outputs.body }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Get pack version
id: pack-version
run: |
version=$(jq -r .pack "scripts/.util/tools.json")
echo "version=${version#v}" >> "$GITHUB_OUTPUT"
- name: Install Global Pack
uses: buildpacks/github-actions/setup-pack@main
with:
pack-version: ${{ steps.pack-version.outputs.version }}
- name: Builder info
id: notes
run: |
registry_builder_name=localhost:5000/${{ matrix.builders.name }}
./scripts/publish.sh --builder-toml-path "${{ matrix.builders.path }}/builder.toml" \
--builder-image-ref "${registry_builder_name}"
pack inspect-builder $registry_builder_name | grep -v 'Inspecting builder' \
| grep -v 'REMOTE:' \
| grep -v 'LOCAL:' \
| grep -v '\(not present\)' \
| grep -v 'Warning' > "${{ matrix.builders.name }}-info.md"
- name: Upload info for ${{ matrix.builders.name }}
uses: actions/upload-artifact@v6
with:
name: "${{ matrix.builders.name }}-info.md"
path: "${{ matrix.builders.name }}-info.md"
release:
name: Release
runs-on: ubuntu-24.04
needs: [preparation, get_builders_info]
steps:
- name: Checkout With History
uses: actions/checkout@v6
with:
fetch-depth: 0 # gets full history
- name: Download Release Note File(s)
uses: actions/download-artifact@v6
with:
path: info
pattern: "*info.md"
merge-multiple: true
- name: Generate Release Notes and Assets
id: generate_release_notes_and_assets
run: |
set -euo pipefail
shopt -s inherit_errexit
builders=$(echo '${{ needs.preparation.outputs.builders }}' | jq -c '.[]')
builders_length=$(echo '${{ needs.preparation.outputs.builders }}' | jq 'length')
release_notes_dir="info"
# Start with an empty array
assets=$(jq -n -c '[]')
# Generate release assets only if we have more than one builder
if [ "$builders_length" -gt 1 ]; then
for builder in $builders; do
builder_name=$(echo "$builder" | jq -r '.name')
assets="$(jq -c \
--arg release_notes_dir "${release_notes_dir}" \
--arg builder_name "${builder_name}" \
'. += [
{
"path": ($release_notes_dir + "/" + $builder_name + "-" + "info.md"),
"name": ($builder_name + "-" + "info.md"),
"content_type": "text/markdown"
}
]' <<<"${assets}")"
done
fi
echo "assets=${assets}" >> "$GITHUB_OUTPUT"
# translates 'paketo-buildpacks' to 'paketobuildpacks'
DOCKERHUB_ORG="${GITHUB_REPOSITORY_OWNER/-/}"
release_body=""
if [ "$builders_length" -gt 1 ]; then
for builder in $builders; do
container_repository=$(echo "$builder" | jq -r '.container_repository')
release_body+="Builder: \`${DOCKERHUB_ORG}/${container_repository}\`\n"
done
payload="{\"body\" : \"\n${release_body}\"}"
else
builder=$(echo "$builders" | head -n 1)
release_body="$(cat $release_notes_dir/$(echo "$builder" | jq -r '.name')-info.md \
| sed -e '/./,$!d' \
| awk -F, '{printf "%s\\n", $0}')"
payload="{\"body\" : \"\`\`\`\n${release_body}\n\`\`\`\"}"
fi
echo "release_body=${payload}" >> "$GITHUB_OUTPUT"
- name: Publish Release
id: publish
uses: release-drafter/release-drafter@v6
with:
config-name: release-drafter-config.yml
publish: true
env:
GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
- name: Update Release Notes
run: |
set -euo pipefail
shopt -s inherit_errexit
payload='${{ steps.generate_release_notes_and_assets.outputs.release_body }}'
curl --fail \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${GITHUB_TOKEN}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \
-d "${payload}"
assets='${{ steps.generate_release_notes_and_assets.outputs.assets }}'
# Update release assets
for row in $(echo "${assets}" | jq -c '.[]'); do
path=$(echo "$row" | jq -r '.path')
name=$(echo "$row" | jq -r '.name')
content_type=$(echo "$row" | jq -r '.content_type')
echo "Uploading asset: ${name} from path: ${path}"
curl -L \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: ${content_type}" \
"https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${name}" \
--data-binary "@${path}"
done
env:
RELEASE_ID: ${{ steps.publish.outputs.id }}
GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
failure:
name: Alert on Failure
runs-on: ubuntu-24.04
needs: [ smoke, release, get_builders_info, preparation ]
if: ${{ always() && needs.smoke.result == 'failure' || needs.release.result == 'failure' || needs.get_builders_info.result == 'failure' || needs.preparation.result == 'failure' }}
steps:
- name: File Failure Alert Issue
uses: paketo-buildpacks/github-config/actions/issue/file@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
repo: ${{ github.repository }}
label: "failure:release"
comment_if_exists: true
issue_title: "Failure: Create Release workflow"
issue_body: |
Create Release workflow [failed](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}).
comment_body: |
Another failure occurred: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}