Skip to content

Commit 8d44951

Browse files
committed
Add CI workflow to validate and lint modules (closes #74)
1 parent 5dc682c commit 8d44951

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

.github/workflows/ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
env:
9+
DEFAULT_BRANCH: origin/main
10+
11+
jobs:
12+
changes:
13+
runs-on: ubuntu-latest
14+
15+
outputs:
16+
modules: ${{ steps.get-changed-modules.outputs.modules}}
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Get branch name
25+
id: branch-name
26+
uses: tj-actions/branch-names@v7
27+
28+
- name: Get changed terraform modules
29+
id: get-changed-modules
30+
run: |
31+
echo "modules=$(git diff --name-only \
32+
origin/${{ steps.branch-name.outputs.current_branch }} \
33+
${{ env.DEFAULT_BRANCH }} | \
34+
grep '.tf' | \
35+
xargs dirname | \
36+
sort -u | \
37+
jq -R -s -c 'split("\n")[:-1]')" >> "$GITHUB_OUTPUT"
38+
39+
validate-fmt-check:
40+
needs: [changes]
41+
if: ${{ needs.changes.outputs.modules != '[]' && needs.changes.outputs.modules != '' }}
42+
runs-on: ubuntu-latest
43+
44+
strategy:
45+
matrix:
46+
module: ${{fromJson(needs.changes.outputs.modules)}}
47+
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v3
51+
52+
- name: terraform validate
53+
uses: dflook/terraform-validate@v1
54+
with:
55+
path: "${{ matrix.module }}"
56+
57+
- name: terraform fmt
58+
uses: dflook/terraform-fmt-check@v1
59+
with:
60+
path: "${{ matrix.module }}"

0 commit comments

Comments
 (0)