Skip to content

Commit 6302052

Browse files
committed
ci: Updated pull request workflow to run plan on changed config.
1 parent 7a5d22c commit 6302052

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/pull-request.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,61 @@ on:
44
pull_request:
55

66
jobs:
7+
configs:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout source code
11+
uses: actions/checkout@v4
12+
- name: Find all configs
13+
id: find
14+
uses: bendrucker/find-terraform-modules@v1
15+
with:
16+
working-directory: tofu/config
17+
- name: Show all matching configs
18+
shell: bash
19+
run: |
20+
mods=(${{ join(fromJSON(steps.find.outputs.modules), ' ') }})
21+
printf "%s\n" "${mods[@]}"
22+
- name: Find all changed files
23+
id: diff
24+
uses: technote-space/get-diff-action@v6
25+
with:
26+
FORMAT: json
27+
- name: Show changed files
28+
run: |
29+
echo "${{ steps.diff.outputs.diff }}"
30+
- name: Get the modified configs
31+
id: modified
32+
uses: actions/github-script@v7
33+
with:
34+
script: |
35+
const configs = ${{ steps.find.outputs.modules }}
36+
const diff = ${{ steps.diff.outputs.diff }}
37+
const modifiedConfigs = configs.filter(
38+
(config) => {
39+
return !!diff.find(file => new RegExp(`^${config}/.+`).test(file))
40+
}
41+
)
42+
43+
core.setOutput('configs', modifiedConfigs)
44+
- name: Show modified configs
45+
run: |
46+
echo "${{ steps.modified.outputs.configs }}"
47+
outputs:
48+
configs: ${{ steps.modified.outputs.configs }}
49+
750
plan:
851
uses: ./.github/workflows/plan.yaml
52+
needs: configs
953
permissions:
1054
contents: read
1155
id-token: write
56+
strategy:
57+
matrix:
58+
config: [ ${{ fromJson(needs.configs.outputs.configs) }} ]
1259
with:
1360
environment: development
61+
config: ${{ matrix.config }}
1462
secrets:
1563
AWS_REGION: ${{ secrets.AWS_REGION }}
1664
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}

0 commit comments

Comments
 (0)