-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (175 loc) · 6.73 KB
/
ci-cd.yaml
File metadata and controls
201 lines (175 loc) · 6.73 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
---
name: "Image: Rebuild CI/CD"
on:
push:
branches:
- main
paths:
- "apps/**"
- "!apps/**/metadata.json"
- "!apps/**/README.md"
jobs:
get-changes:
name: Collect changes
runs-on: ubuntu-latest
outputs:
addedOrModifiedImages: ${{ steps.collect-changes.outputs.addedOrModifiedImages }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Collect changes
id: collect-changes
uses: ./.github/actions/collect-changes
generate-build-matrix:
name: Generate matrix for building images
runs-on: ubuntu-latest
needs: [get-changes]
outputs:
matrix: ${{ steps.get-changed.outputs.changes }}
images: ${{ steps.get-changed.outputs.images }}
if: |
always()
&& contains(needs.*.result, 'success')
&& !contains(needs.*.result, 'failure')
&& !cancelled()
&& needs.get-changes.outputs.addedOrModifiedImages != '[]'
steps:
- name: Install tools
run: |
sudo apt-get update
sudo apt-get -y install moreutils jo
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch modified images
id: get-changed
shell: bash
run: |
declare -a changes_array=()
while read -r app
do
while read -r channel
do
change="$(jo app="$app" channel="$channel")"
changes_array+=($change)
done < <(jq -r '.channels[] | .name' "./apps/$app/metadata.json")
done < <(echo '${{ needs.get-changes.outputs.addedOrModifiedImages }}' | jq --raw-output -c '.[]')
output="$(jo -a ${changes_array[*]})"
echo "changes=$output" >> "$GITHUB_OUTPUT"
image_list="[]"
if [[ "${#changes_array[@]}" -gt 0 ]]; then
image_list="$(printf '%s\n' "${changes_array[@]}" \
| jq -R -s -c 'split("\n") | map(select(length > 0)) | map(fromjson | "\(.app):\(.channel)")')"
fi
echo "images=${image_list}" >> "$GITHUB_OUTPUT"
images-build:
name: Build and push images
runs-on: ubuntu-latest
needs: [generate-build-matrix]
if: |
always()
&& contains(needs.*.result, 'success')
&& !contains(needs.*.result, 'failure')
&& !cancelled()
&& needs.generate-build-matrix.outputs.matrix != '[]'
strategy:
matrix:
image: ${{ fromJson(needs.generate-build-matrix.outputs.matrix) }}
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Extract build metadata
id: vars
uses: ./.github/actions/setup-vars
with:
app: ${{ matrix.image.app }}
channel: ${{ matrix.image.channel }}
- name: Validate metadata
uses: ./.github/actions/validate-cue
with:
app: ${{ matrix.image.app }}
- name: Build test image
uses: ./.github/actions/build-test-image
with:
app: ${{ matrix.image.app }}
channel: ${{ matrix.image.channel }}
upstream_version: ${{ steps.vars.outputs.chan_upstream_version }}
dockerfile: ${{ steps.vars.outputs.chan_dockerfile }}
tag_testing: ${{ steps.vars.outputs.chan_tag_testing }}
- name: Run Goss tests
if: ${{ steps.vars.outputs.chan_tests_enabled == 'true' }}
uses: ./.github/actions/run-goss-tests
with:
tag_testing: ${{ steps.vars.outputs.chan_tag_testing }}
goss_config: ${{ steps.vars.outputs.chan_goss_config }}
goss_args: ${{ steps.vars.outputs.chan_goss_args }}
- name: Build and push release image
uses: ./.github/actions/build-release-image
with:
app: ${{ matrix.image.app }}
channel: ${{ matrix.image.channel }}
upstream_version: ${{ steps.vars.outputs.chan_upstream_version }}
dockerfile: ${{ steps.vars.outputs.chan_dockerfile }}
label_type: ${{ steps.vars.outputs.chan_label_type }}
build_date: ${{ steps.vars.outputs.chan_build_date }}
tag_rolling: ${{ steps.vars.outputs.chan_tag_rolling }}
tag_version: ${{ steps.vars.outputs.chan_tag_version }}
platforms: ${{ steps.vars.outputs.chan_platforms }}
token: ${{ secrets.GH_PAT }}
notify-success:
runs-on: ubuntu-latest
needs: [generate-build-matrix, images-build]
if: |
always()
&& contains(needs.*.result, 'success')
&& !contains(needs.*.result, 'failure')
&& !cancelled()
&& needs.generate-build-matrix.outputs.matrix != '[]'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Notify success
uses: ./.github/actions/notifications
with:
title: "Image rebuilds successful"
tags: '${{ secrets.APPRISE_TAGS }}'
apprise_configuration: '${{ secrets.APPRISE_CONFIG }}'
body: |
✅ **Image Rebuilds Complete**
The following images were successfully rebuilt:
- ${{ join(fromJson(needs.generate-build-matrix.outputs.images || '[]'), '\n- ') }}
---
🕐 Triggered by commit to `main`
📅 Date: ${{ github.event.head_commit.timestamp }}
🔗 Commit: [${{ github.event.head_commit.message }}](${{ github.event.head_commit.url }})
🔗 Workflow: [${{ github.workflow }}](${{ github.run_url }})
🔗 Repository: [${{ github.repository }}](${{ github.event.repository.html_url }})
notify-failure:
runs-on: ubuntu-latest
needs: [generate-build-matrix, images-build]
if: |
always()
&& contains(needs.*.result, 'failure')
&& !cancelled()
&& needs.generate-build-matrix.outputs.matrix != '[]'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Notify failure
uses: ./.github/actions/notifications
with:
title: "Image rebuilds failed"
tags: '${{ secrets.APPRISE_TAGS }}'
apprise_configuration: '${{ secrets.APPRISE_CONFIG }}'
body: |
❌ **Image Rebuilds Failed**
The following images failed to rebuild:
- ${{ join(fromJson(needs.generate-build-matrix.outputs.images || '[]'), '\n- ') }}
---
🕐 Triggered by commit to `main`
📅 Date: ${{ github.event.head_commit.timestamp }}
🔗 Commit: [${{ github.event.head_commit.message }}](${{ github.event.head_commit.url }})
🔗 Workflow: [${{ github.workflow }}](${{ github.run_url }})
🔗 Repository: [${{ github.repository }}](${{ github.event.repository.html_url }})