|
5 | 5 | branches: [main] |
6 | 6 | pull_request: |
7 | 7 | branches: [main] |
8 | | - |
| 8 | + |
9 | 9 | permissions: |
10 | 10 | contents: read |
11 | 11 |
|
12 | 12 | env: |
13 | 13 | HEADLAMP_PLUGIN_VERSION: latest |
14 | 14 |
|
15 | 15 | jobs: |
16 | | - # Get list of folders containing headlamp plugins |
| 16 | + # Get list of folders containing changed headlamp plugins |
17 | 17 | # We need a separate step to be able to pass the list to the matrix of the build job |
18 | | - find_plugin_dirs: |
| 18 | + find_changed_plugin_dirs: |
19 | 19 | runs-on: ubuntu-latest |
20 | 20 | outputs: |
21 | 21 | dirs: ${{ steps.dirs.outputs.dirs }} |
22 | 22 | steps: |
23 | | - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # 4.1.7 |
24 | | - - id: dirs |
25 | | - run: echo "dirs=$(grep -m1 -lR @kinvolk/headlamp-plugin ./*/package.json | xargs -n1 dirname | jq --raw-input --slurp --compact-output 'split("\n")[:-1]')" >> ${GITHUB_OUTPUT} |
| 23 | + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 24 | + with: |
| 25 | + fetch-depth: 0 # Fetch all history |
| 26 | + |
| 27 | + - name: Fetch base branch |
| 28 | + run: git fetch origin main |
| 29 | + |
| 30 | + - name: Find changed Headlamp plugin directories |
| 31 | + id: dirs |
| 32 | + run: | |
| 33 | + # Get all top-level directories that had changes |
| 34 | + changed_dirs=$(git diff --name-only origin/main...HEAD | awk -F/ '{print $1}' | sort -u) |
| 35 | + echo "Changed directories: $changed_dirs" |
| 36 | +
|
| 37 | + # If .github/ changed, run all plugins |
| 38 | + if echo "$changed_dirs" | tr ' ' '\n' | grep -q '^\.github$'; then |
| 39 | + echo "Changes detected in .github/ directory, running all plugins." |
| 40 | + changed_dirs=$(grep -lR 'headlamp-plugin' ./*/package.json | xargs -n1 dirname | sort -u) |
| 41 | + echo "Changed directories: $changed_dirs" |
| 42 | + fi |
| 43 | +
|
| 44 | + plugin_dirs=() |
| 45 | + for dir in $changed_dirs; do |
| 46 | + pkg="$dir/package.json" |
| 47 | + if [ -f "$pkg" ] && grep -q 'headlamp-plugin' "$pkg"; then |
| 48 | + plugin_dirs+=("$dir") |
| 49 | + fi |
| 50 | + done |
26 | 51 |
|
| 52 | + # Output as JSON array for matrix |
| 53 | + if [ ${#plugin_dirs[@]} -eq 0 ]; then |
| 54 | + echo "No changed Headlamp plugins found." |
| 55 | + final_json="[]" |
| 56 | + else |
| 57 | + echo "Changed Headlamp plugin directories: ${plugin_dirs[*]}" |
| 58 | + final_json=$(printf '%s\n' "${plugin_dirs[@]}" | jq --raw-input --slurp --compact-output 'split("\n")[:-1]') |
| 59 | + fi |
| 60 | + echo "Final plugin_dirs JSON: $final_json" |
| 61 | + echo "dirs=$final_json" >> "$GITHUB_OUTPUT" |
| 62 | + |
27 | 63 | build: |
28 | | - needs: find_plugin_dirs |
| 64 | + needs: find_changed_plugin_dirs |
| 65 | + if: needs.find_changed_plugin_dirs.outputs.dirs != '[]' |
29 | 66 | runs-on: ubuntu-latest |
30 | 67 |
|
31 | 68 | defaults: |
|
36 | 73 | fail-fast: false |
37 | 74 | matrix: |
38 | 75 | node-version: [18.x] |
39 | | - dir: ${{ fromJson(needs.find_plugin_dirs.outputs.dirs) }} |
| 76 | + dir: ${{ fromJson(needs.find_changed_plugin_dirs.outputs.dirs) }} |
40 | 77 |
|
41 | 78 | steps: |
42 | 79 | - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # 4.1.7 |
|
0 commit comments