Skip to content

Commit e73eba5

Browse files
authored
Merge pull request #9 from sabaini/workflow-manual-trigger
Workflow: add manual trigger
2 parents 10237bf + 7dae34f commit e73eba5

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

.github/workflows/build-and-test.yml

+44-25
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,63 @@ name: Build/Test
22

33
on:
44
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: ''
511

612
jobs:
713
modifiedparts:
814
runs-on: ubuntu-latest
915
outputs:
10-
parts: ${{steps.changed-parts.outputs.parts }}
16+
parts: ${{ steps.determine-parts.outputs.parts }}
1117
steps:
1218
- name: Checkout repository
1319
uses: actions/checkout@v4
1420

21+
# For non-manual triggered runs
1522
- name: Get modified files
1623
id: changed-files
24+
if: ${{ github.event_name != 'workflow_dispatch' }}
1725
uses: tj-actions/changed-files@v35
1826

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 }}
2132
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))
3340
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
4262
4363
build:
4464
needs: modifiedparts
@@ -49,7 +69,6 @@ jobs:
4969
matrix:
5070
part: ${{ fromJson(needs.modifiedparts.outputs.parts) }}
5171
steps:
52-
5372
- name: Checkout
5473
uses: actions/checkout@v4
5574

@@ -86,7 +105,7 @@ jobs:
86105
- build
87106
name: Functional tests
88107
runs-on: [self-hosted, linux, amd64, X64, large, noble]
89-
if: ${{ needs.modifiedparts.output.parts != '[]' }}
108+
if: ${{ needs.modifiedparts.outputs.parts != '[]' }}
90109
strategy:
91110
matrix:
92111
part: ${{ fromJson(needs.modifiedparts.outputs.parts) }}
@@ -135,7 +154,7 @@ jobs:
135154
if [[ -f "./${{ matrix.part }}/src/tox.ini" ]]; then
136155
tox -c ${{ matrix.part }}/src -e func-target -- noble-caracal
137156
else
138-
tox -c ${{ matrix.part}} -e func-target -- noble-caracal
157+
tox -c ${{ matrix.part }} -e func-target -- noble-caracal
139158
fi
140159
141160
- name: Generate crash dumps

0 commit comments

Comments
 (0)