-
Notifications
You must be signed in to change notification settings - Fork 8
187 lines (164 loc) · 5.69 KB
/
build-and-test.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
name: Build/Test
on:
workflow_call:
workflow_dispatch:
inputs:
part:
description: 'Name of the charm to build/test manually. Defaults to all charms'
required: false
default: ''
jobs:
modifiedparts:
runs-on: ubuntu-latest
outputs:
parts: ${{ steps.determine-parts.outputs.parts }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
# For non-manual triggered runs
- name: Get modified files
id: changed-files
if: ${{ github.event_name != 'workflow_dispatch' }}
uses: tj-actions/changed-files@v35
- name: Determine charms to build/test
id: determine-parts
env:
INPUT_PART: ${{ inputs.part }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: |
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
if [ -n "$INPUT_PART" ]; then
# Manual run with a specified charm
components=($INPUT_PART)
else
# Manual run, no charm specified -> run all
components=($(find . -maxdepth 1 -type d ! -path '.' -exec bash -c '[[ -f "$0/charmcraft.yaml" ]] && basename "$0"' {} \; | sort))
fi
else
# Automatic run: use changed-files to determine modified charms
components=()
# Retrieve components with a 'tox.ini' file.
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
component=$(echo "$file" | cut -d "/" -f1)
if [[ -f "./$component/charmcraft.yaml" ]]; then
# This is a charm.
components+=("$component")
elif [[ -f "./$component/tox.ini" ]]; then
# Assume this is a library.
# TODO: Add dependent charms here.
:
fi
done
# Remove dups
components=($(echo "${components[@]}" | tr ' ' '\n' | sort -u))
fi
json_output=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${components[@]}")
echo "Modified parts: $json_output"
echo "parts=$json_output" >> $GITHUB_OUTPUT
build:
needs: modifiedparts
name: Build the charm
runs-on: ubuntu-latest
if: ${{ needs.modifiedparts.outputs.parts != '[]' }}
strategy:
matrix:
part: ${{ fromJson(needs.modifiedparts.outputs.parts) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get -qq install libxslt-dev libxml2-dev python3-lxml tox
- name: Run linters
run: tox -c ${{ matrix.part }} -e pep8
- name: Run unit tests
run: tox -c ${{ matrix.part }} -e py3
- name: Setup LXD
uses: canonical/setup-lxd@v0.1.1
with:
channel: 5.21/stable
- name: Build charm(s)
id: builder
run: |
sudo snap install charmcraft --classic
tox -c ${{ matrix.part }} -e build
- name: Upload built charm
uses: actions/upload-artifact@v4
with:
name: charm-${{ matrix.part }}
path: "./${{ matrix.part }}/*.charm"
functional-test:
needs:
- modifiedparts
- build
name: Functional tests
runs-on: [self-hosted, linux, amd64, X64, large, noble]
if: ${{ needs.modifiedparts.outputs.parts != '[]' }}
strategy:
matrix:
part: ${{ fromJson(needs.modifiedparts.outputs.parts) }}
steps:
- name: Download charm
uses: actions/download-artifact@v4
with:
name: charm-${{ matrix.part }}
path: ~/artifacts/
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Copy utils
run: cp tests/scripts/actionutils.sh $HOME
- name: Clear FORWARD firewall rules
run: ~/actionutils.sh cleaript
- name: Setup LXD
run: |
if [[ "$(snap list | grep -c lxd)" -eq 0 ]]; then
sudo snap install lxd --channel=5.21/stable
sudo usermod -aG lxd "$USER"
newgrp lxd
lxd init --minimal
fi
- name: Install dependencies
run: |
sudo apt -y install tox
if [ ! -d "$HOME/.local/share/juju" ]; then
sudo snap install juju --channel=3.6/stable
mkdir -p ~/.local/share/juju
juju bootstrap localhost localhost
fi
sudo snap install --classic juju-crashdump
- name: Run the tests
run: |
date
mv ~/artifacts/*.charm ./
if [[ -f "./${{ matrix.part }}/src/tox.ini" ]]; then
tox -c ${{ matrix.part }}/src -e func-target -- noble-caracal
else
tox -c ${{ matrix.part }} -e func-target -- noble-caracal
fi
- name: Generate crash dumps
if: failure()
run: |
models=$(juju models | grep zaza | awk '{print $1}' | tr -d '*')
rm -rf ./crashdumps
mkdir ./crashdumps
for model in $models; do
juju-crashdump -m $model -o ./crashdumps
done
- name: Upload artifacts on failure
uses: actions/upload-artifact@v4
with:
name: crashdumps-${{ matrix.part }}
path: "./crashdumps/*"
if: failure()
- name: Setup tmate session
if: ${{ failure() && runner.debug }}
uses: canonical/action-tmate@main
- name: Tear down models
if: always()
run: |
models=$(juju models | grep zaza | awk '{print $1}' | tr -d '*')
for model in $models; do
juju destroy-model --no-prompt --force --destroy-storage $model
done