-
Notifications
You must be signed in to change notification settings - Fork 162
268 lines (236 loc) · 10.4 KB
/
bundle.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
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
name: Process manifests
on:
push:
branches:
- main
pull_request:
jobs:
process-manifests:
name: Get changes
runs-on: ubuntu-latest
outputs:
changed-manifests: ${{ steps.set-json-output.outputs.all-changed-files }}
deleted-manifests: ${{ steps.set-json-output.outputs.deleted-files }}
checks-only: ${{ steps.set-json-output.outputs.checks-only }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get updated manifests
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
applications/**/manifest.yml
files_ignore: |
.github
example
- name: JSONify changes
id: set-json-output
run: |
if [ "${{ github.event_name }}" != "push" ] ; then
echo checks-only=true >> $GITHUB_OUTPUT ;
fi ;
echo all-changed-files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | jq -R -c 'split(" ")' ) >> $GITHUB_OUTPUT ;
echo deleted-files=$(echo "${{ steps.changed-files.outputs.deleted_files }}" | jq -R -c 'split(" ")' ) >> $GITHUB_OUTPUT ;
- name: Generate diff comment data
id: diff-comment
if: github.event_name == 'pull_request' && steps.changed-files.outputs.all_changed_files != ''
run: |
echo "### Application updates" >> diff.md ;
for manifest in ${{ steps.changed-files.outputs.all_changed_files }} ; do
SHA_DIFF=$( git diff --unified=0 ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- $manifest | grep "commit_sha: " ) ;
OLD_SHA_VALUE=$( echo "$SHA_DIFF" | grep -E '^\-' | sed "s/.*: //" | xargs ) ;
NEW_SHA_VALUE=$( echo "$SHA_DIFF" | grep -E '^\+' | sed "s/.*: //" | xargs ) ;
REPO_URL=$( grep " origin: " $manifest | sed "s/.*origin: \(.*\)/\1/" | sed "s/\(.*\).git$/\1/" ) ;
APP_ID=$(basename $( dirname $manifest ) ) ;
if [ "z$OLD_SHA_VALUE" == "z" ] ; then
echo "New app \`$APP_ID\`: [repo]($REPO_URL/tree/$NEW_SHA_VALUE)" >> diff.md ;
else
echo "Updated app \`$APP_ID\`: [changes]($REPO_URL/compare/$OLD_SHA_VALUE...$NEW_SHA_VALUE)" >> diff.md ;
fi ;
done ;
echo 'repo-diff-md-file=diff.md' >> $GITHUB_OUTPUT ;
echo 'repo-diff<<REPO-DIFF-DATA-EOF' >> $GITHUB_OUTPUT ;
cat diff.md >> $GITHUB_OUTPUT ;
echo 'REPO-DIFF-DATA-EOF' >> $GITHUB_OUTPUT ;
- name: Output diff to job status
if: steps.diff-comment.outputs.repo-diff != ''
run: |
cat "${{ steps.diff-comment.outputs.repo-diff-md-file }}" >> $GITHUB_STEP_SUMMARY ;
- name: Find diff comment
uses: peter-evans/find-comment@v3
id: find-comment
if: steps.diff-comment.outputs.repo-diff != '' && !github.event.pull_request.head.repo.fork
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '### Application updates'
- name: Create or update diff comment
if: steps.diff-comment.outputs.repo-diff != '' && !github.event.pull_request.head.repo.fork
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body: ${{ steps.diff-comment.outputs.repo-diff }}
edit-mode: replace
build-package:
name: Build package
needs: process-manifests
if: needs.process-manifests.outputs.changed-manifests != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
manifest: ${{ fromJson(needs.process-manifests.outputs.changed-manifests) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up source code flag
id: source-code
run: |
ARCHIVARIUS_URL=$( < .github/.ARCHIVARIUS_URL ) ;
echo "ARCHIVARIUS_URL=${ARCHIVARIUS_URL}" >> $GITHUB_ENV ;
if [ "z{{ vars.CATALOG_STAGING }}" != "z" ] ; then
echo "BUNDLE_ALLOW_VERSION_MISMATCH=1" >> $GITHUB_ENV ;
fi ;
- name: Bundle application
id: app-bundle
continue-on-error: true
uses: ./.github/actions/bundle
with:
path: ${{ matrix.manifest }}
skip-source-code: ${{ needs.process-manifests.outputs.checks-only }}
json-manifest: bundle.json
build-artifacts-zip: true
# Uncomment to submit bundles with broken code
# skip-build: true
skip-lint: true
- name: Retry build with RC SDK
id: app-bundle-rc
if: steps.app-bundle.outcome == 'failure'
uses: ./.github/actions/bundle
with:
path: ${{ matrix.manifest }}
skip-source-code: ${{ needs.process-manifests.outputs.checks-only }}
sdk-channel: rc
json-manifest: bundle.json
build-artifacts-zip: true
# Uncomment to submit bundles with broken code
# skip-build: true
skip-lint: true
- name: Get succesful build output
id: get-bundle-path
if: (steps.app-bundle.outputs.bundle-path != '' || steps.app-bundle-rc.outputs.bundle-path != '')
run: |
if [ -f "${{ steps.app-bundle.outputs.bundle-path }}" ] ; then
echo "path=${{ steps.app-bundle.outputs.bundle-path }}" >> $GITHUB_OUTPUT ;
echo "artifacts-path=${{ steps.app-bundle.outputs.artifacts-path }}" >> $GITHUB_OUTPUT ;
elif [ -f $GITHUB_OUTPUT ] ; then
echo "path=${{ steps.app-bundle-rc.outputs.bundle-path }}" >> $GITHUB_OUTPUT ;
echo "artifacts-path=${{ steps.app-bundle-rc.outputs.artifacts-path }}" >> $GITHUB_OUTPUT ;
else
echo Failed to build application bundle! ;
exit 1 ;
fi
APPID=$( jq -r '.id' bundle.json ) ;
APPVERSION=$( jq -r '.version' bundle.json ) ;
echo "app-id=$APPID" >> $GITHUB_OUTPUT ;
echo "app-version=$APPVERSION" >> $GITHUB_OUTPUT ;
- name: Submit application bundle
id: bundle-submit
if: needs.process-manifests.outputs.checks-only != 'true'
run: |
curl --fail-with-body \
-H "Authorization: Bearer ${{ secrets.FAST_AUTH_TOKEN }}" \
-F "bundle=@${{ steps.get-bundle-path.outputs.path }}" \
${{ env.ARCHIVARIUS_URL }}/api/v0/application/version/bundle
- name: Check if version exists
if: needs.process-manifests.outputs.checks-only == 'true' && steps.app-bundle.outputs.bundle-path != ''
run: |
VER_HTTP_CODE=$( curl -sw '%{http_code}' -o /dev/null \
"${{ env.ARCHIVARIUS_URL }}/api/v0/application/${{ steps.get-bundle-path.outputs.app-id }}/versions?version=${{ steps.get-bundle-path.outputs.app-version }}" ) ;
if [ "$VER_HTTP_CODE" != "404" ] ; then
echo "Version ${{ steps.get-bundle-path.outputs.app-version }} for ${{ steps.get-bundle-path.outputs.app-id }} already exists (or server failed, code ${VER_HTTP_CODE})!" ;
exit 1 ;
fi
- name: Create bundle artifact
if: needs.process-manifests.outputs.checks-only == 'true' && steps.get-bundle-path.outputs.path != ''
uses: actions/upload-artifact@v4
with:
name: "${{ steps.get-bundle-path.outputs.app-id }}-${{ steps.get-bundle-path.outputs.app-version }}-bundle"
path: ${{ steps.get-bundle-path.outputs.path }}
- name: Create build artifacts artifact
if: needs.process-manifests.outputs.checks-only == 'true' && steps.get-bundle-path.outputs.artifacts-path != ''
uses: actions/upload-artifact@v4
with:
name: "${{ steps.get-bundle-path.outputs.app-id }}-${{ steps.get-bundle-path.outputs.app-version }}-build-artifacts"
path: ${{ steps.get-bundle-path.outputs.artifacts-path }}
delete-app:
name: Delete app
needs: process-manifests
if: needs.process-manifests.outputs.deleted-manifests != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
manifest: ${{ fromJson(needs.process-manifests.outputs.deleted-manifests) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up source code flag
id: source-code
run: |
ARCHIVARIUS_URL=$( < .github/.ARCHIVARIUS_URL ) ;
echo "ARCHIVARIUS_URL=${ARCHIVARIUS_URL}" >> $GITHUB_ENV ;
if [ "z{{ vars.CATALOG_STAGING }}" != "z" ] ; then
echo "BUNDLE_ALLOW_VERSION_MISMATCH=1" >> $GITHUB_ENV ;
fi
- name: Extract app id from path
id: get-app-id
run: |
echo "app-id=$( basename $( dirname ${{ matrix.manifest }} ) )" >> $GITHUB_OUTPUT ;
- name: Check if app exists on backend
id: check-app-exists
run: |
curl --fail-with-body \
${{ env.ARCHIVARIUS_URL }}/api/v0/application/${{ steps.get-app-id.outputs.app-id }}
- name: Delete app from backend
id: delete-manifest
if: steps.check-app-exists.outputs.exitcode == 0 && needs.process-manifests.outputs.checks-only != 'true'
run: |
curl --fail-with-body -X DELETE \
-H "Authorization: Bearer ${{ secrets.FAST_AUTH_TOKEN }}" \
${{ env.ARCHIVARIUS_URL }}/api/v0/application/${{ steps.get-app-id.outputs.app-id }}
self-test:
name: Run self-test
needs: process-manifests
if: needs.process-manifests.outputs.deleted-manifests == '[]' && needs.process-manifests.outputs.changed-manifests == '[]'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run self-test
id: self-test
uses: ./.github/actions/bundle
with:
path: example/manifest.yml
- name: Create bundle artifact
uses: actions/upload-artifact@v4
with:
name: "test-bundle"
path: ${{ steps.self-test.outputs.bundle-path }}
report-status:
name: Report status
needs: [ self-test, build-package, delete-app ]
if: always() && !contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
steps:
- run: echo "All good ✨" ;