-
Notifications
You must be signed in to change notification settings - Fork 14
191 lines (157 loc) · 4.82 KB
/
ci.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
name: "CI"
on:
push:
pull_request:
workflow_dispatch:
env:
CHARM_NAME: ${{ vars.CHARM_NAME }}
jobs:
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
- name: Install dependencies for testing
run: |
pip install -r requirements-dev.txt
- name: Run tests
run: |
./run_tests
build:
name: Build charms
needs: unit-tests
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v4
with:
artifact-name: charm-packed
channel:
name: Select Charmhub channel
runs-on: ubuntu-latest
outputs:
test: ${{ steps.channel.outputs.test }}
release: ${{ steps.channel.outputs.release }}
steps:
- name: Select Charmhub channel
id: channel
shell: bash
run: |
set -eux
case ${{ github.ref_name }} in
3.* | 4.*)
TRACK="${{ github.ref_name }}"
DO_RELEASE=true
;;
main)
TRACK="latest"
DO_RELEASE=true
;;
*)
TRACK="latest"
DO_RELEASE=false # Don't release feature branches
;;
esac
# Feature branches will be released to the 'latest' track, so we need
# to include the branch name to disambiguate.
BRANCH="${{ github.ref_name }}-${{ github.sha }}"
echo "test=$TRACK/edge/$BRANCH" >> "$GITHUB_OUTPUT"
if [[ "$DO_RELEASE" == 'true' ]]; then
echo "release=$TRACK/edge" >> "$GITHUB_OUTPUT"
fi
upload:
name: Upload to Charmhub
needs: [build, channel]
runs-on: ubuntu-latest
steps:
- name: Download packed charm
id: download
uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.artifact-name }}
- name: Upload charm to Charmhub
env:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
run: |
sudo snap install charmcraft --classic
charmcraft upload ${{ steps.download.outputs.download-path }}/*.charm \
--name $CHARM_NAME \
--release ${{ needs.channel.outputs.test }}
integration:
name: "Integration tests"
runs-on: ubuntu-latest
needs: [build, upload, channel]
strategy:
fail-fast: false
matrix:
cloud: ["lxd", "microk8s"]
env:
LOCAL_CHARM_PATH: ${{ github.workspace }}/controller.charm
steps:
- name: Download packed charm
id: download
uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.artifact-name }}
- name: Rename charm file
run: |
mv ${{ steps.download.outputs.download-path }}/*.charm \
$LOCAL_CHARM_PATH
- name: Save charmcraft logs as artifact
if: always() && steps.charmcraft.outcome != 'skipped'
uses: actions/upload-artifact@v3
with:
name: charmcraft-upload-logs
path: ~/.local/state/charmcraft/log/
continue-on-error: true
- name: Set up LXD
if: matrix.cloud == 'lxd'
uses: canonical/setup-lxd@90d76101915da56a42a562ba766b1a77019242fd
- name: Set up MicroK8s
if: matrix.cloud == 'microk8s'
uses: balchua/[email protected]
with:
channel: "1.25-strict/stable"
addons: '["dns", "hostpath-storage"]'
- name: Install Juju
run: |
sudo snap install juju --channel 3.1/stable
- name: Bootstrap on LXD
if: matrix.cloud == 'lxd'
run: |
juju bootstrap lxd c \
--controller-charm-path=$LOCAL_CHARM_PATH
- name: Bootstrap on MicroK8s
if: matrix.cloud == 'microk8s'
run: |
sg snap_microk8s <<EOF
juju bootstrap microk8s c \
--controller-charm-channel=${{ needs.channel.outputs.test }}
EOF
- name: Check charm status
run: |
juju switch controller
juju wait-for application controller --timeout 1m
juju status
# TODO: test integration with dashboard / ha-proxy
release:
name: "Release to edge"
runs-on: ubuntu-latest
needs: [upload, channel, integration]
env:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
steps:
- name: Install Charmcraft
run: |
sudo snap install charmcraft --classic
- name: Get uploaded revision
id: revision
run: |
charmcraft status $CHARM_NAME --format json |
jq ${{ needs.channel.outputs.release }} ...
- name: Release to edge
if: github.event_name == 'push' && needs.channel.outputs.release != ''
run: |
charmcraft release $CHARM_NAME \
--revision=${{ steps.revision.outputs.revision }}
--channel=${{ needs.channel.outputs.release }}