@@ -2,43 +2,63 @@ name: Build/Test
2
2
3
3
on :
4
4
workflow_call :
5
+ workflow_dispatch :
6
+ inputs :
7
+ part :
8
+ description : ' Name of the charm to build/test manually. Defaults to all charms'
9
+ required : false
10
+ default : ' '
5
11
6
12
jobs :
7
13
modifiedparts :
8
14
runs-on : ubuntu-latest
9
15
outputs :
10
- parts : ${{steps.changed -parts.outputs.parts }}
16
+ parts : ${{ steps.determine -parts.outputs.parts }}
11
17
steps :
12
18
- name : Checkout repository
13
19
uses : actions/checkout@v4
14
20
21
+ # For non-manual triggered runs
15
22
- name : Get modified files
16
23
id : changed-files
24
+ if : ${{ github.event_name != 'workflow_dispatch' }}
17
25
uses : tj-actions/changed-files@v35
18
26
19
- - name : Set output
20
- id : changed-parts
27
+ - name : Determine charms to build/test
28
+ id : determine-parts
29
+ env :
30
+ INPUT_PART : ${{ inputs.part }}
31
+ GITHUB_EVENT_NAME : ${{ github.event_name }}
21
32
run : |
22
- components=()
23
- # Retrieve components with a 'tox.ini' file.
24
- for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
25
- component=$(echo "$file" | cut -d "/" -f1)
26
- if [[ -f "./$component/charmcraft.yaml" ]]; then
27
- # This is a charm.
28
- components="$components $component"
29
- elif [[ -f "./$component/tox.ini" ]]; then
30
- # Assume this is a library.
31
- # TODO: Add dependent charms here.
32
- :
33
+ if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
34
+ if [ -n "$INPUT_PART" ]; then
35
+ # Manual run with a specified charm
36
+ components=($INPUT_PART)
37
+ else
38
+ # Manual run, no charm specified -> run all
39
+ components=($(find . -maxdepth 1 -type d ! -path '.' -exec bash -c '[[ -f "$0/charmcraft.yaml" ]] && basename "$0"' {} \; | sort))
33
40
fi
34
- done
35
-
36
- components=($components)
37
- components=`echo "${components[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '`
38
- components=($components)
39
- modified_parts=`jq --compact-output --null-input '$ARGS.positional' --args -- "${components[@]}"`
40
- echo "Modified parts: $modified_parts"
41
- echo "parts=$modified_parts" >> $GITHUB_OUTPUT
41
+ else
42
+ # Automatic run: use changed-files to determine modified charms
43
+ components=()
44
+ # Retrieve components with a 'tox.ini' file.
45
+ for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
46
+ component=$(echo "$file" | cut -d "/" -f1)
47
+ if [[ -f "./$component/charmcraft.yaml" ]]; then
48
+ # This is a charm.
49
+ components+=("$component")
50
+ elif [[ -f "./$component/tox.ini" ]]; then
51
+ # Assume this is a library.
52
+ # TODO: Add dependent charms here.
53
+ :
54
+ fi
55
+ done
56
+ # Remove dups
57
+ components=($(echo "${components[@]}" | tr ' ' '\n' | sort -u))
58
+ fi
59
+ json_output=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${components[@]}")
60
+ echo "Modified parts: $json_output"
61
+ echo "parts=$json_output" >> $GITHUB_OUTPUT
42
62
43
63
build :
44
64
needs : modifiedparts
49
69
matrix :
50
70
part : ${{ fromJson(needs.modifiedparts.outputs.parts) }}
51
71
steps :
52
-
53
72
- name : Checkout
54
73
uses : actions/checkout@v4
55
74
86
105
- build
87
106
name : Functional tests
88
107
runs-on : [self-hosted, linux, amd64, X64, large, noble]
89
- if : ${{ needs.modifiedparts.output .parts != '[]' }}
108
+ if : ${{ needs.modifiedparts.outputs .parts != '[]' }}
90
109
strategy :
91
110
matrix :
92
111
part : ${{ fromJson(needs.modifiedparts.outputs.parts) }}
@@ -135,7 +154,7 @@ jobs:
135
154
if [[ -f "./${{ matrix.part }}/src/tox.ini" ]]; then
136
155
tox -c ${{ matrix.part }}/src -e func-target -- noble-caracal
137
156
else
138
- tox -c ${{ matrix.part}} -e func-target -- noble-caracal
157
+ tox -c ${{ matrix.part }} -e func-target -- noble-caracal
139
158
fi
140
159
141
160
- name : Generate crash dumps
0 commit comments