|
4 | 4 | pull_request: |
5 | 5 |
|
6 | 6 | 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 | + |
7 | 50 | plan: |
8 | 51 | uses: ./.github/workflows/plan.yaml |
| 52 | + needs: configs |
9 | 53 | permissions: |
10 | 54 | contents: read |
11 | 55 | id-token: write |
| 56 | + strategy: |
| 57 | + matrix: |
| 58 | + config: [ ${{ fromJson(needs.configs.outputs.configs) }} ] |
12 | 59 | with: |
13 | 60 | environment: development |
| 61 | + config: ${{ matrix.config }} |
14 | 62 | secrets: |
15 | 63 | AWS_REGION: ${{ secrets.AWS_REGION }} |
16 | 64 | AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }} |
|
0 commit comments