-
Notifications
You must be signed in to change notification settings - Fork 17
executable file
·229 lines (202 loc) · 7.31 KB
/
create-draft-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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
name: Create or Update Draft Release
on:
push:
branches:
- main
repository_dispatch:
types: [ version-bump ]
workflow_dispatch:
inputs:
version:
description: 'Version of the release to cut (e.g. 1.2.3)'
required: false
concurrency: release
jobs:
unit:
name: Unit Tests
runs-on: ubuntu-22.04
outputs:
builders: ${{ steps.builders.outputs.builders }}
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 'stable'
- name: Checkout
uses: actions/checkout@v3
- name: Run Unit Tests
run: ./scripts/unit.sh
- name: Get builders from integration.json
id: builders
run: |
source "${{ github.workspace }}/scripts/.util/builders.sh"
builders="$(util::builders::list "${{ github.workspace }}/integration.json")"
printf "Output: %s\n" "${builders}"
printf "builders=%s\n" "${builders}" >> "$GITHUB_OUTPUT"
integration:
name: Integration Tests
runs-on: ubuntu-22.04
needs: unit
strategy:
matrix:
builder: ${{ fromJSON(needs.unit.outputs.builders) }}
fail-fast: false # don't cancel all test jobs when one fails
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 'stable'
- name: Checkout
uses: actions/checkout@v3
- name: Run Integration Tests
run: ./scripts/integration.sh --builder ${{ matrix.builder }} --token ${{ github.token }}
env:
TMPDIR: "${{ runner.temp }}"
release:
name: Release
runs-on: ubuntu-22.04
needs: integration
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 'stable'
- name: Checkout
uses: actions/checkout@v3
with:
fetch-tags: true
- name: Reset Draft Release
id: reset
uses: paketo-buildpacks/github-config/actions/release/reset-draft@main
with:
repo: ${{ github.repository }}
token: ${{ github.token }}
- name: Calculate Semver Tag
if: github.event.inputs.version == ''
id: semver
uses: paketo-buildpacks/github-config/actions/tag/calculate-semver@main
with:
repo: ${{ github.repository }}
token: ${{ github.token }}
ref-name: ${{ github.ref_name }}
- name: Set Release Tag
id: tag
run: |
tag="${{ github.event.inputs.version }}"
if [ -z "${tag}" ]; then
tag="${{ steps.semver.outputs.tag }}"
fi
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
- name: Package
run: ./scripts/package.sh --version "${{ steps.tag.outputs.tag }}"
- name: Get buildpack type
id: get_buildpack_type
run: |
if [ -f "extension.toml" ]; then
echo "buildpack_type=extension" >> "$GITHUB_OUTPUT"
else
echo "buildpack_type=buildpack" >> "$GITHUB_OUTPUT"
fi
- name: Get buildpack path
id: get_buildpack_path
run: |
if [ -f "build/buildpackage.cnb" ]; then
echo "path=build/buildpackage.cnb" >> "$GITHUB_OUTPUT"
else
echo "path=build/buildpackage-linux-amd64.cnb" >> "$GITHUB_OUTPUT"
fi
- name: Create Release Notes
id: create-release-notes
uses: paketo-buildpacks/github-config/actions/release/notes@main
with:
repo: ${{ github.repository }}
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
buildpack_type: ${{ steps.get_buildpack_type.outputs.buildpack_type }}
buildpackage_path: ${{ steps.get_buildpack_path.outputs.path }}
- name: Get Image Digest
id: image_digest
run: |
image_name="localhost:5000/npm-install:latest"
./scripts/publish.sh \
--buildpack-archive ./build/buildpack.tgz \
--image-ref $image_name
echo "digest=$(sudo skopeo inspect "docker://${image_name}" --tls-verify=false | jq -r .Digest)" >> "$GITHUB_OUTPUT"
- name: Set Correct Image Digest on the Release notes
run: |
printf '${{ steps.create-release-notes.outputs.release_body }}' \
| sed -E \
"s/\*\*Digest:\*\* \`sha256:[a-f0-9]{64}\`/\*\*Digest:\*\* \`${{ steps.image_digest.outputs.digest }}\`/" \
> ./release_notes
printf '${{ steps.image_digest.outputs.digest }}' > ./index-digest.sha256
- name: Create release assets
id: create_release_assets
run: |
release_assets=$(jq -n --arg repo_name "${{ github.event.repository.name }}" --arg tag "${{ steps.tag.outputs.tag }}" '
[
{
"path": "build/buildpack.tgz",
"name": ($repo_name + "-" + $tag + ".tgz"),
"content_type": "application/gzip"
},
{
"path": "./index-digest.sha256",
"name": ($repo_name + "-" + $tag + "-" + "index-digest.sha256"),
"content_type": "text/plain"
}
]')
for filepath in build/*.cnb; do
filename=$(basename "$filepath")
asset_name=""
if [[ "$filename" == "buildpackage-linux-amd64.cnb" ]]; then
asset_name="${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.cnb"
elif [[ "$filename" == "buildpackage.cnb" ]]; then
asset_name="${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.cnb"
else
formatted_filename="${filename#buildpackage-}"
asset_name="${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}-${formatted_filename}"
fi
release_assets=$(echo "$release_assets" | jq --arg asset_name "${asset_name}" --arg filepath "$filepath" '
. + [
{
"path": $filepath,
"name": $asset_name,
"content_type": "application/gzip"
}
]')
done
release_assets=$(jq -c <<< "$release_assets" )
printf "release_assets=%s\n" "${release_assets}" >> "$GITHUB_OUTPUT"
- name: Create Release
uses: paketo-buildpacks/github-config/actions/release/create@main
with:
repo: ${{ github.repository }}
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
tag_name: v${{ steps.tag.outputs.tag }}
target_commitish: ${{ github.sha }}
name: v${{ steps.tag.outputs.tag }}
body_filepath: "./release_notes"
draft: true
assets: ${{ steps.create_release_assets.outputs.release_assets }}
failure:
name: Alert on Failure
runs-on: ubuntu-22.04
needs: [ unit, integration, release ]
if: ${{ always() && needs.unit.result == 'failure' || needs.integration.result == 'failure' || needs.release.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 Draft Release workflow"
issue_body: |
Create Draft 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}}