-
Notifications
You must be signed in to change notification settings - Fork 30
293 lines (241 loc) · 9.73 KB
/
release.yml
File metadata and controls
293 lines (241 loc) · 9.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
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
name: Release Juju Dashboard
on:
pull_request:
types:
- closed
branches:
- "release/*"
permissions: write-all
defaults:
run:
shell: bash
jobs:
run-check:
name: "Determine if workflow should run"
runs-on: ubuntu-24.04
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true
outputs:
should-run: ${{ steps.check.outputs.should-run }}
steps:
- name: Only run on `release/x.y.z[-suffix]` branches
if: github.event_name == 'pull_request'
id: check
run: |
# Unfortunately, this step is required since GitHub doesn't allow glob filtering on
# the head branch of a PR.
if [ -z $(echo '${{ github.head_ref }}' | grep -P '^release/\d+\.\d+\.\d+') ]; then
echo 'Not running on a full release branch. Exiting workflow.'
exit 0
else
echo 'Running on release branch, continuing workflow.'
echo 'should-run=true' | tee -a "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pre-release:
name: "Determine release parameters"
runs-on: ubuntu-24.04
needs: [run-check]
if: needs.run-check.outputs.should-run
outputs:
version: ${{ steps.params.outputs.version }}
channel: ${{ steps.params.outputs.channel }}
promote-channel: ${{ steps.params.outputs.promote-channel }}
track: ${{ steps.params.outputs.track }}
is-pre-release: ${{ steps.params.outputs.is-pre-release }}
changelog: ${{ steps.changelog.outputs.changelog }}
steps:
- uses: actions/checkout@v6
- name: Determine release Charmhub parameters
id: params
run: |
version=$(jq -r .version package.json)
track=$(echo "$version" | grep -Po '^\d+\.\d+')
channel="$track/beta"
is_pre_release="true"
if echo $version | grep -P '^\d+\.\d+\.\d+$' ; then
# Can promote from beta to candidate immediately
promote_channel="$track/candidate"
is_pre_release="false"
fi
echo "version=$version" | tee -a "$GITHUB_OUTPUT"
echo "channel=$channel" | tee -a "$GITHUB_OUTPUT"
echo "promote-channel=$promote_channel" | tee -a "$GITHUB_OUTPUT"
echo "track=$track" | tee -a "$GITHUB_OUTPUT"
echo "is-pre-release=$is_pre_release" | tee -a "$GITHUB_OUTPUT"
- name: Extract changelog
uses: ./.github/actions/extract-changelog
id: changelog
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
release:
name: "Release Juju Dashboard"
runs-on: ubuntu-24.04
needs: [pre-release]
strategy:
fail-fast: false
matrix:
charm-kind: [k8s, machine]
steps:
- uses: actions/checkout@v6
- name: Install LXD
uses: canonical/setup-lxd@main
- name: Build dashboard
working-directory: charms/${{ matrix.charm-kind }}-charm
id: build
run: |
OUTPUT=$(./build.sh)
if [ '${{ matrix.charm-kind }}' = 'k8s' ]; then
echo "$OUTPUT" | grep '^id=' >> "$GITHUB_OUTPUT"
fi
- name: Log in to GitHub Container Registry
if: ${{ matrix.charm-kind == 'k8s' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Upload docker image
if: ${{ matrix.charm-kind == 'k8s' }}
run: |
FINAL_TAG='ghcr.io/canonical/juju-dashboard:${{ needs.pre-release.outputs.version }}'
docker image tag '${{ steps.build.outputs.id }}' "$FINAL_TAG"
docker image push "$FINAL_TAG"
- name: Get charm path
id: post-build
run: |
CHARM_DIR='charms/${{ matrix.charm-kind }}-charm'
# Concatenate charm paths into a single line with commas
BUILT_CHARM_PATHS=$(ls -1 $CHARM_DIR/*.charm | xargs -L1 basename | paste -sd ',' -)
echo "charm-dir=$CHARM_DIR" | tee -a "$GITHUB_OUTPUT"
echo "built-charm-path=$BUILT_CHARM_PATHS" | tee -a "$GITHUB_OUTPUT"
- name: Save charm artifact
uses: actions/upload-artifact@v6
with:
name: juju-dashboard-${{ matrix.charm-kind }}
path: ${{ steps.post-build.outputs.charm-dir }}/*.charm
- name: Create new tracks, if required
run: |
track='${{ needs.pre-release.outputs.track }}'
charm_name="$(yq '.name' '${{ steps.post-build.outputs.charm-dir }}/metadata.yaml')"
authorization_header="Macaroon $(echo '${{ secrets.CHARMHUB_TOKEN }}' | base64 -d | jq -r .v)"
jq_filter=".metadata.tracks[].name | select(. == \"$track\")"
matching_track="$(curl -H "Authorization: $authorization_header" -H 'Content-type: application/json' "https://api.charmhub.io/v1/charm/$charm_name" | jq -r "$jq_filter")"
if [ "$matching_track" = '' ]; then
echo "Creating '$track' track for '$charm_name'"
CHARMCRAFT_AUTH='${{ secrets.CHARMHUB_TOKEN }}' charmcraft create-track "$charm_name" "$track"
else
echo "'$track' track for '$charm_name' already created. Continuing..."
fi
- name: Upload charm
uses: canonical/charming-actions/upload-charm@main
with:
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
channel: "${{ needs.pre-release.outputs.channel }}"
charm-path: "${{ steps.post-build.outputs.charm-dir }}"
built-charm-path: "${{ steps.post-build.outputs.built-charm-path }}"
upload-image: true
pull-image: false
charmcraft-channel: latest/stable
github-tag: false
- name: Promote charm
if: needs.pre-release.outputs.promote-channel != ''
uses: andogq/charming-actions/promote-charm@fix/promote-charm-branch # TODO: Replace this once canonical/charming-actions#162 merges
with:
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
origin-channel: "${{ needs.pre-release.outputs.channel }}"
destination-channel: "${{ needs.pre-release.outputs.promote-channel }}"
charm-path: ${{ steps.post-build.outputs.charm-dir }}
charmcraft-channel: latest/stable
- name: Send notification
uses: ./.github/actions/send-notification
with:
webhook-url: "${{ secrets.WEBBOT_URL }}"
message: |
Successfully published Juju Dashboard ${{ matrix.charm-kind }} charm `${{ needs.pre-release.outputs.version }}` to `${{ needs.pre-release.outputs.promote-channel || needs.pre-release.outputs.channel }}`
- name: Send notification on failure
if: failure()
uses: ./.github/actions/send-notification
with:
webhook-url: "${{ secrets.WEBBOT_URL }}"
post-release:
name: "Create tags and releases"
runs-on: ubuntu-24.04
needs: [pre-release, release]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v6
with:
fetch-tags: true
- name: Tag commits
id: tags
run: |
create_or_update_tag () {
tag="$1"
echo "Creating tag '$tag' at $(git rev-parse --short HEAD)"
# Tag the current commit, force updating if required
git tag -f "$tag"
}
# Tag original channel
create_or_update_tag 'track/${{ needs.pre-release.outputs.channel }}'
# Tag promoted channel, if required
if [ ! -z '${{ needs.pre-release.outputs.promote-channel }}' ]; then
create_or_update_tag 'track/${{ needs.pre-release.outputs.promote-channel }}'
fi
# Tag version
version_tag='v${{ needs.pre-release.outputs.version }}'
create_or_update_tag "$version_tag"
git push --tags --force
echo "version-tag=$version_tag" | tee -a "$GITHUB_OUTPUT"
- name: "Download k8s charm artifact"
uses: actions/download-artifact@v7
with:
name: juju-dashboard-k8s
path: release-artifacts
- name: "Download machine charm artifact"
uses: actions/download-artifact@v7
with:
name: juju-dashboard-machine
path: release-artifacts
- name: "Create release"
uses: ncipollo/release-action@v1
with:
name: "Juju Dashboard ${{ needs.pre-release.outputs.version }}"
tag: ${{ steps.tags.outputs.version-tag }}
allowUpdates: true
replacesArtifacts: true
prerelease: ${{ needs.pre-release.outputs.is-pre-release }}
artifacts: release-artifacts/**/*.charm
body: |
Published `${{ steps.tags.outputs.version-tag }}` to Charmhub on `${{ needs.pre-release.outputs.promote-channel || needs.pre-release.outputs.channel }}` channel.
---
# Changelog
${{ needs.pre-release.outputs.changelog }}
sentry-release:
name: "Create Sentry release"
runs-on: ubuntu-24.04
needs: [pre-release]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v6
- name: Install dependencies
run: yarn install
- name: Build dashboard with sourcemaps
run: yarn run vite build --sourcemap=hidden
- name: "Create Sentry release"
uses: getsentry/action-release@v3
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: canonical-ax
SENTRY_PROJECT: juju-dashboard
with:
environment: production
release: ${{ needs.pre-release.outputs.version }}
sourcemaps: "./build"
ignore_missing: true
ignore_empty: true