-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (95 loc) · 2.89 KB
/
branch.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Branch Checks
on:
push:
branches-ignore:
- main
jobs:
find-modules:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Find all terraform modules
id: find
uses: bendrucker/find-terraform-modules@v1
with:
working-directory: tofu
- name: Show all matching modules
shell: bash
run: |
mods=(${{ join(fromJSON(steps.find.outputs.modules), ' ') }})
printf "%s\n" "${mods[@]}"
- name: Find all changed files
id: diff
uses: technote-space/get-diff-action@v6
with:
FORMAT: json
- name: Show changed files
run: |
echo "${{ steps.diff.outputs.diff }}"
- name: Get the modified modules
id: modified
uses: actions/github-script@v7
with:
script: |
const modules = ${{ steps.find.outputs.modules }}
const diff = ${{ steps.diff.outputs.diff }}
const modifiedModules = modules.filter(
(module) => {
return !!diff.find(file => new RegExp(`^${module}/.+`).test(file))
}
)
core.setOutput('modules', modifiedModules)
- name: Show modified modules
run: |
echo "${{ steps.modified.outputs.modules }}"
outputs:
modules: ${{ steps.modified.outputs.modules }}
lint:
runs-on: ubuntu-latest
needs: find-modules
steps:
- name: Checkout source code
uses: actions/checkout@v4
- uses: actions/cache@v4
name: Cache plugin directory
with:
path: ~/.tflint.d/plugins
key: tflint-${{ hashFiles('.tflint.hcl') }}
- uses: terraform-linters/setup-tflint@v4
name: Setup TFLint
- name: Show version
run: tflint --version
- name: Init TFLint
run: tflint --init
# Use a bash script to run tflint on each modified module.
- name: Run TFLint
shell: bash
run: |
set +e
exit_code=0
modules=(${{ join(fromJSON(needs.find-modules.outputs.modules), ' ') }})
for module in ${modules[@]}
do
echo "Linting module $module"
tflint --format compact --chdir $module
exit_code=$(( $? > exit_code ? $? : exit_code ))
done
exit $exit_code
trivy:
name: trivy
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Run Trivy vulnarability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: config
format: sarif
output: 'trivy-results.sarif'
- name: Parse SARIF file
if: always()
uses: Ayrx/[email protected]
with:
sarif_file: 'trivy-results.sarif'