-
Notifications
You must be signed in to change notification settings - Fork 4
55 lines (54 loc) · 2.2 KB
/
test-tf-plan.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
on:
pull_request:
types:
- edited
- opened
- synchronize
- reopened
jobs:
find-changed-dirs:
runs-on: [ARM64,self-hosted,Linux]
outputs:
allChanges: ${{ steps.changedDirs.outputs.allChanges }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v3
id: filter
with:
initial-fetch-depth: '1'
list-files: json
filters: |
changed:
- added|modified: 'terraform/**'
- uses: actions/github-script@v6
id: changedDirs
with:
script: |
const path = require("path")
const changedFiles = ${{ steps.filter.outputs.changed_files }}
const changedDirs = changedFiles.map(f => path.dirname(f))
console.log(`Found the following changed dirs: ${JSON.stringify(changedDirs, null, 2)}\n OG: ${JSON.stringify(changedFiles, null, 2)} `)
const changedModules = [... new Set(changedDirs.filter(d => d.indexOf("modules") !== -1 && d.split("/").length === 3))]
const changedAccounts = [... new Set(changedDirs.filter(d => d.indexOf("accounts") !== -1 && d.split("/").length === 3))]
const changedEnvs = [... new Set(changedDirs.filter(d => d.indexOf("envs") !== -1 && d.split("/").length === 4))]
const allChanges = [...changedAccounts,...changedEnvs, ...changedModules]
console.log(`changedModules: ${JSON.stringify(changedModules)}`)
console.log(`changedAccounts: ${JSON.stringify(changedAccounts)}`)
console.log(`changedEnvs: ${JSON.stringify(changedEnvs)}`)
core.setOutput("allChanges", allChanges)
tf-test-changed-dirs:
runs-on: [ARM64,self-hosted,Linux]
needs: find-changed-dirs
strategy:
matrix:
workspace: ${{ fromJson(needs.find-changed-dirs.outputs.allChanges) }}
if: ${{ needs.find-changed-dirs.outputs.allChanges != '[]' }}
steps:
- uses: actions/checkout@v3
- name: Terraform plan
uses: ./.github/actions/tf-plan
with:
ssh-private-key: ${{secrets.SHARED_INFRA_DEPLOY_KEY}}
working-dir: ${{matrix.workspace}}
tf-version: 1.3.0
tfe-token: ${{secrets.TFE_TOKEN}}