-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (88 loc) · 2.83 KB
/
pull-request.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
name: Pull request
on:
- pull_request
jobs:
collectInputs:
name: Collect workflow inputs
runs-on: ubuntu-latest
outputs:
directories: ${{ steps.dirs.outputs.matrix }}
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
# Find all subdirectories within "modules/" and "examples/"
- name: Get root directories
id: dirs
run: echo "matrix=$(ls -d {modules,examples}/* | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
validatePR:
name: Validate PR
runs-on: ubuntu-latest
needs: collectInputs
strategy:
matrix:
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
# Install the latest version of Terraform
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
# Initialize terraform and validate submodules
- name: Terraform validate
working-directory: ${{ matrix.directory }}
run: |
if [[ -d ".terraform" ]]; then echo "removing exisiting .terraform directory"; rm -rf .terraform; fi
terraform workspace new ${{ github.run_id }}
terraform init
terraform validate
updateDocumentation:
name: Update READMEs
needs: validatePR
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
# Update READMEs using terraform-docs
- name: Render terraform docs inside the README.md and push changes back to PR branch
uses: terraform-docs/[email protected]
with:
args: --recursive-include-main=false --read-comments=false
working-dir: modules,examples
recursive: true
recursive-path: .
output-file: README.md
output-method: inject
git-push: "true"
formatConfig:
name: Fix Terraform file formatting
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
# Format Terraform modules
- name: Terraform fmt modules
uses: dflook/terraform-fmt@v1
with:
path: modules/
# Format Terraform examples
- name: Terraform fmt examples
uses: dflook/terraform-fmt@v1
with:
path: examples/
# Push changes to PR
- name: Commit changes to PR
uses: stefanzweifel/git-auto-commit-action@v5