77
88concurrency : release
99
10+ env :
11+ BUILDERS_FILEPATH : " builders.json"
12+
1013jobs :
14+ preparation :
15+ name : Preparation
16+ runs-on : ubuntu-24.04
17+ outputs :
18+ builders : ${{ steps.get-builders.outputs.builders }}
19+ steps :
20+ - name : Checkout
21+ uses : actions/checkout@v4
22+
23+ - name : Get Builders
24+ id : get-builders
25+ run : |
26+ builders=$(jq -n -c '[]')
27+
28+ if [ -f ${{ env.BUILDERS_FILEPATH }} ]; then
29+ builders=$(jq -c '.builders' ${{ env.BUILDERS_FILEPATH }})
30+ else
31+ # Strip off the Github org prefix from repo name
32+ # paketo-buildpacks/builder-with-some-name --> builder-with-some-name
33+ registry_repo=$(echo "${{ github.repository }}" | sed 's/^.*\///')
34+ builders=$(jq -n -c '[
35+ {
36+ "name": "default",
37+ "path": ".",
38+ "container_repository": "'"${registry_repo}"'"
39+ }
40+ ]')
41+ fi
42+
43+ # Filter only the necessary fields
44+ builders=$(echo "$builders" | jq 'map({
45+ name,
46+ path,
47+ container_repository
48+ })')
49+
50+ builders=$(jq -c <<< "$builders")
51+ echo "builders=$builders"
52+ echo "builders=$builders" >> "$GITHUB_OUTPUT"
53+
54+ builder_files_changed :
55+ name : Builder Files Changed
56+ runs-on : ubuntu-24.04
57+ needs : preparation
58+ outputs :
59+ builders_changed : ${{ steps.compare_previous_release.outputs.builders_changed }}
60+ steps :
61+ - name : Checkout
62+ uses : actions/checkout@v4
63+ with :
64+ fetch-depth : 0 # gets full history
65+
66+ - name : Compare previous releases
67+ id : compare_previous_release
68+ run : |
69+ builders=$(echo '${{ needs.preparation.outputs.builders }}' | jq -c '.[]')
70+ for builder in $builders; do
71+ builder_path=$(echo "$builder" | jq -r '.path')
72+
73+ changed=$(git diff --name-only $(git describe --tags --abbrev=0) -- $builder_path/builder.toml)
74+ if [ -z "${changed}" ]
75+ then
76+ # We do not write on the github output because this step runs multiple times
77+ # and it might overwrite any true value written by the else statement.
78+ echo "No changes for $builder_path/builder.toml"
79+ else
80+ echo "Changes detected for $builder_path/builder.toml"
81+ echo "builders_changed=true" >> $GITHUB_OUTPUT
82+ fi
83+ done
84+
1185 smoke :
1286 name : Smoke Test
1387 runs-on : ubuntu-24.04
88+ needs : [preparation, builder_files_changed]
89+ if : ${{ needs.builder_files_changed.outputs.builders_changed == 'true' }}
90+ strategy :
91+ matrix :
92+ builders : ${{ fromJSON(needs.preparation.outputs.builders) }}
93+ services :
94+ registry :
95+ image : registry:2
96+ ports :
97+ - 5000:5000
1498 outputs :
1599 release_notes : ${{ steps.notes.outputs.body }}
16100 steps :
@@ -34,43 +118,91 @@ jobs:
34118 pack-version : ${{ steps.pack-version.outputs.version }}
35119
36120 - name : Run Smoke Tests
37- run : ./scripts/smoke.sh --name builder
121+ run : |
122+ ./scripts/smoke.sh --builder-dir "${{ matrix.builders.path }}"
38123
39- - name : Generate Release Notes
124+ - name : Generate builder information
40125 id : notes
41126 run : |
42- notes="$(pack inspect-builder builder | grep -v 'Inspecting builder' \
127+ registry_builder_name=localhost:5000/${{ matrix.builders.name }}
128+
129+ ./scripts/publish.sh --builder-toml-path "${{ matrix.builders.path }}/builder.toml" \
130+ --builder-image-ref "${registry_builder_name}"
131+
132+ pack inspect-builder $registry_builder_name | grep -v 'Inspecting builder' \
43133 | grep -v 'REMOTE:' \
44134 | grep -v 'LOCAL:' \
45135 | grep -v '\(not present\)' \
46- | grep -v 'Warning' \
47- | sed -e '/./,$!d' \
48- | awk -F, '{printf "%s\\n", $0}')"
49- echo "body=${notes}" >> "$GITHUB_OUTPUT"
136+ | grep -v 'Warning' > "${{ matrix.builders.name }}-information.md"
137+
138+ - name : Upload information for ${{ matrix.builders.name }}
139+ uses : actions/upload-artifact@v4
140+ with :
141+ name : " ${{ matrix.builders.name }}-information.md"
142+ path : " ${{ matrix.builders.name }}-information.md"
50143
51144 release :
52145 name : Release
53146 runs-on : ubuntu-24.04
54- needs : smoke
147+ needs : [ smoke, preparation]
55148 steps :
56149 - name : Checkout With History
57150 uses : actions/checkout@v4
58151 with :
59152 fetch-depth : 0 # gets full history
60153
61- - name : Compare With Previous Release
62- id : compare_previous_release
154+ - name : Download Release Note File(s)
155+ uses : actions/download-artifact@v4
156+ with :
157+ path : information
158+ pattern : " *information.md"
159+ merge-multiple : true
160+
161+ - name : Generate Release Notes and Assets
162+ id : generate_release_notes_and_assets
63163 run : |
64- if [ -z "$(git diff $(git describe --tags --abbrev=0) -- builder-buildpackless.toml)" ]
65- then
66- echo "builder_changes=false" >> "$GITHUB_OUTPUT"
67- else
68- echo "builder_changes=true" >> "$GITHUB_OUTPUT"
69- fi
164+ set -euo pipefail
165+ shopt -s inherit_errexit
166+
167+ builders=$(echo '${{ needs.preparation.outputs.builders }}' | jq -c '.[]')
168+ release_notes_dir="information"
169+
170+ # Start with an empty array
171+ assets=$(jq -n -c '[]')
172+
173+ # Generate release assets
174+ for builder in $builders; do
175+ builder_name=$(echo "$builder" | jq -r '.name')
176+
177+ assets="$(jq -c \
178+ --arg release_notes_dir "${release_notes_dir}" \
179+ --arg builder_name "${builder_name}" \
180+ '. += [
181+ {
182+ "path": ($release_notes_dir + "/" + $builder_name + "-" + "information.md"),
183+ "name": ($builder_name + "-" + "information.md"),
184+ "content_type": "text/markdown"
185+ }
186+ ]' <<<"${assets}")"
187+ done
188+
189+ echo "assets=${assets}" >> "$GITHUB_OUTPUT"
190+
191+ # translates 'paketo-buildpacks' to 'paketobuildpacks'
192+ DOCKERHUB_ORG="${GITHUB_REPOSITORY_OWNER/-/}"
193+
194+ # Generate release notes
195+ release_body=""
196+ for builder in $builders; do
197+ container_repository=$(echo "$builder" | jq -r '.container_repository')
198+ release_body+="Builder: \`${DOCKERHUB_ORG}/${container_repository}\`\n"
199+ done
200+
201+ payload="{\"body\" : \"\n${release_body}\"}"
202+ echo "release_body=${payload}" >> "$GITHUB_OUTPUT"
70203
71204 - name : Publish Release
72205 id : publish
73- if : ${{ steps.compare_previous_release.outputs.builder_changes == 'true' }}
74206 uses : release-drafter/release-drafter@v6
75207 with :
76208 config-name : release-drafter-config.yml
@@ -79,22 +211,38 @@ jobs:
79211 GITHUB_TOKEN : ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
80212
81213 - name : Update Release Notes
82- if : ${{ steps.compare_previous_release.outputs.builder_changes == 'true' }}
83214 run : |
84215 set -euo pipefail
85216 shopt -s inherit_errexit
86217
87- payload="{\"body\" : \"\`\`\`\n${RELEASE_BODY}\n\`\`\`\"}"
88-
218+ payload='${{ steps.generate_release_notes_and_assets.outputs.release_body }}'
89219 curl --fail \
90220 -X PATCH \
91221 -H "Accept: application/vnd.github.v3+json" \
92222 -H "Authorization: token ${GITHUB_TOKEN}" \
93223 "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \
94224 -d "${payload}"
225+
226+ assets='${{ steps.generate_release_notes_and_assets.outputs.assets }}'
227+
228+ # Update release assets
229+ for row in $(echo "${assets}" | jq -c '.[]'); do
230+ path=$(echo "$row" | jq -r '.path')
231+ name=$(echo "$row" | jq -r '.name')
232+ content_type=$(echo "$row" | jq -r '.content_type')
233+
234+ echo "Uploading asset: ${name} from path: ${path}"
235+
236+ curl -L \
237+ -X POST \
238+ -H "Accept: application/vnd.github.v3+json" \
239+ -H "Authorization: token ${GITHUB_TOKEN}" \
240+ -H "Content-Type: ${content_type}" \
241+ "https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${name}" \
242+ --data-binary "@${path}"
243+ done
95244 env :
96245 RELEASE_ID : ${{ steps.publish.outputs.id }}
97- RELEASE_BODY : ${{ needs.smoke.outputs.release_notes }}
98246 GITHUB_TOKEN : ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
99247
100248 failure :
0 commit comments