-
Notifications
You must be signed in to change notification settings - Fork 9
234 lines (224 loc) · 9.88 KB
/
promote_charm.yaml
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
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
name: Promote charm
on:
workflow_call:
inputs:
base-architecture:
type: string
description: Charm base architecture to promote (e.g. amd64)
default: ""
base-channel:
type: string
description: Charm base channel to promote (e.g. 22.04)
default: ""
base-name:
type: string
description: Charm base name to promote (e.g. ubuntu)
default: ""
charm-directory:
type: string
description: The directory for the charm under the working-directory
default: "."
destination-channel:
type: string
description: 'Destination Channel'
doc-automation-disabled:
type: boolean
description: 'Whether to disable the documentation automation'
default: true
origin-channel:
type: string
description: 'Origin Channel'
working-directory:
type: string
description: The working directory for jobs
default: "./"
jobs:
get-runner-image:
name: Get runner image
runs-on: ubuntu-24.04
outputs:
name: ${{ env.BUILD_ON_NAME }}
channel: ${{ env.BUILD_ON_CHANNEL }}
runs-on: ${{ env.BUILD_ON }}
steps:
- uses: actions/checkout@v4.2.2
- name: Get build-on value
working-directory: ${{ inputs.working-directory }}/${{ inputs.charm-directory }}
run: |
name="ubuntu"
channel="22.04"
if [ -f charmcraft.yaml ]; then
name=$(yq '.bases.[0].build-on.[0].name // "ubuntu"' charmcraft.yaml)
channel=$(yq '.bases.[0].build-on.[0].channel // '22.04'' charmcraft.yaml)
fi
image="$name-$channel"
echo "BUILD_ON_NAME=$name" >> $GITHUB_ENV
echo "BUILD_ON_CHANNEL=$channel" >> $GITHUB_ENV
echo "BUILD_ON=$image" >> $GITHUB_ENV
validate-channels:
name: Validate channels
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4.2.2
- run: |
set -e
origin_track=$(echo ${{ inputs.origin-channel }} | cut -d "/" -f 1)
destination_track=$(echo ${{ inputs.destination-channel }} | cut -d "/" -f 1)
if [ $origin_track != $destination_track ]; then
echo "::error::Destination track $destination_track does not match origin track $origin_track"
exit 1
fi
validate-inputs:
name: Validate inputs
runs-on: ubuntu-24.04
outputs:
arch: ${{ env.BUILD_ON_ARCH }}
channel: ${{ env.BUILD_ON_CHANNEL }}
name: ${{ env.BUILD_ON_NAME }}
needs: [ get-runner-image ]
steps:
- uses: actions/checkout@v4.2.2
- run: |
set -e
CHARMCRAFT_YAML_PATH=${{ inputs.working-directory }}/${{ inputs.charm-directory }}/charmcraft.yaml
if [ ! -f $CHARMCRAFT_YAML_PATH ]; then
echo "charmcraft.yaml not found in $CHARMCRAFT_YAML_PATH"
exit 1
fi
target_base_arch=${{ inputs.base-architecture }}
target_base_channel=${{ inputs.base-channel }}
target_base_name=${{ inputs.base-name }}
if [[ -z "$target_base_arch" ]]; then
target_base_arch=amd64
fi
# if input not configured, use first result found from charmcraft.yaml
if [[ -z "$target_base_channel" ]] && [[ -z "$target_base_name" ]]; then
target_base_channel=${{ needs.get-runner-image.outputs.channel }}
target_base_name=${{ needs.get-runner-image.outputs.name }}
echo "BUILD_ON_ARCH=$target_base_arch" >> $GITHUB_ENV
echo "BUILD_ON_CHANNEL=$target_base_channel" >> $GITHUB_ENV
echo "BUILD_ON_NAME=$target_base_name" >> $GITHUB_ENV
exit 0
fi
# if input is configured, validate
readarray bases < <(yq --output-format json --indent=0 '.bases[]' $CHARMCRAFT_YAML_PATH)
for base in "${bases[@]}"; do
# Check optional run-on first, since build-on is used as default otherwise.
if [[ $(echo $base | yq 'has("run-on")') == "true" ]]; then
readarray run_ons < <(echo $base | yq --output-format json --indent=0 '.run-on[]')
for run_on in $run_ons; do
channel=$(echo $run_on | yq -r '.channel')
name=$(echo $run_on | yq -r '.name')
# Default to amd64 if no architectures provided
architectures=$(echo $run_on | yq -r '.architectures[]')
architectures=${architectures:="amd64"}
for arch in $architectures; do
if [[ "$arch" == "$target_base_arch" ]] && \
[[ "$channel" == "$target_base_channel" ]] && \
[[ "$name" == "$target_base_name" ]]; then
echo "BUILD_ON_ARCH=$target_base_arch" >> $GITHUB_ENV
echo "BUILD_ON_CHANNEL=$channel" >> $GITHUB_ENV
echo "BUILD_ON_NAME=$name" >> $GITHUB_ENV
exit 0
fi
done
done
fi
# Check build-on values.
readarray build_ons < <(echo $base | yq --output-format json --indent=0 '.build-on[]')
for build_on in $build_ons; do
channel=$(echo $build_on | yq -r '.channel')
name=$(echo $build_on | yq -r '.name')
# Default to amd64 if no architectures provided
architectures=$(echo $run_on | yq -r '.architectures[]')
architectures=${architectures:="amd64"}
for arch in $architectures; do
echo $arch
if [[ "$arch" == "$target_base_arch" ]] && \
[[ "$channel" == "$target_base_channel" ]] && \
[[ "$name" == "$target_base_name" ]]; then
echo "BUILD_ON_ARCH=$target_base_arch" >> $GITHUB_ENV
echo "BUILD_ON_CHANNEL=$channel" >> $GITHUB_ENV
echo "BUILD_ON_NAME=$name" >> $GITHUB_ENV
exit 0
fi
done
done
done
echo "No matching base found: $target_base_arch $target_base_channel $target_base_name"
exit 1
promote-charm:
name: Promote charm
runs-on: ubuntu-latest
needs: [validate-channels, validate-inputs]
steps:
- uses: actions/checkout@v4.2.2
- name: Release charm to channel
uses: canonical/charming-actions/release-charm@2.6.3
with:
credentials: ${{ secrets.CHARMHUB_TOKEN }}
charm-path: ${{ inputs.working-directory }}/${{ inputs.charm-directory }}
github-token: ${{ secrets.GITHUB_TOKEN }}
origin-channel: ${{ inputs.origin-channel }}
destination-channel: ${{ inputs.destination-channel }}
base-name: ${{ needs.validate-inputs.outputs.name }}
base-channel: ${{ needs.validate-inputs.outputs.channel }}
base-architecture: ${{ needs.validate-inputs.outputs.arch }}
draft-publish-docs:
name: Draft publish docs
runs-on: ubuntu-24.04
defaults:
run:
working-directory: ${{ inputs.working-directory }}/${{ inputs.charm-directory }}
steps:
- uses: actions/checkout@v4.2.2
- name: Search for docs folder
id: docs-exist
run: echo "docs_exist=$([[ -d docs ]] && echo 'True' || echo 'False')" >> $GITHUB_OUTPUT
- name: Publish documentation
if: ${{ steps.docs-exist.outputs.docs_exist == 'True' && env.discourse_api_username != '' && env.discourse_api_key != '' }}
uses: canonical/discourse-gatekeeper@stable
env:
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
with:
discourse_host: discourse.charmhub.io
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
dry_run: true
github_token: ${{ secrets.GITHUB_TOKEN }}
charm_dir: ${{ inputs.working-directory }}/${{ inputs.charm-directory }}
publish-docs:
if: ${{ github.event.inputs.destination-channel }} == 'latest/stable'
name: Publish docs
runs-on: ubuntu-24.04
defaults:
run:
working-directory: ${{ inputs.working-directory }}/${{ inputs.charm-directory }}
steps:
- uses: actions/checkout@v4.2.2
- name: Search for docs folder
id: docs-exist
run: echo "docs_exist=$([[ -d docs ]] && echo 'True' || echo 'False')" >> $GITHUB_OUTPUT
- name: Publish documentation
if: ${{ steps.docs-exist.outputs.docs_exist == 'True' && env.discourse_api_username != '' && env.discourse_api_key != '' }}
uses: canonical/discourse-gatekeeper@stable
id: publishDocumentation
env:
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
with:
discourse_host: discourse.charmhub.io
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
dry_run: ${{ inputs.doc-automation-disabled }}
github_token: ${{ secrets.GITHUB_TOKEN }}
charm_dir: ${{ inputs.working-directory }}/${{ inputs.charm-directory }}
- name: Show index page
if: ${{ steps.docs-exist.outputs.docs_exist == 'True' && env.discourse_api_username != '' && env.discourse_api_key != '' }}
run: echo '${{ steps.publishDocumentation.outputs.index_url }}'
env:
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}