Skip to content

Commit bf44015

Browse files
authored
feat: add TF_VAR check and conventional commit lint workflows (#663)
Adds the following two workflows: 1. `conventional-commit-lint`: check all commits follow the conventional commit style. This will help ensure that the Release Please changelog contains all PRs. 2. `terraform-variable-check`: checks that the GitHub workflow Terraform variables defined as TF_VAR_ prefixed environment variables have a matching variable definition in the codebase. This will help prevent accidental misconfigurations between the workflows and Terraform code.
1 parent 0a3baea commit bf44015

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Conventional commit lint
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
conventional-commit-lint:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Get all PR commits
11+
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
12+
13+
- name: Checkout
14+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
15+
with:
16+
ref: ${{ github.event.pull_request.head.ref }}
17+
fetch-depth: ${{ env.PR_FETCH_DEPTH }}
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
21+
with:
22+
node-version: '20.x'
23+
24+
- name: Setup commitlint
25+
run: |
26+
npm install -g @commitlint/config-conventional @commitlint/cli
27+
28+
- name: Validate all PR commits
29+
run: |
30+
npx commitlint \
31+
--extends '@commitlint/config-conventional' \
32+
--from HEAD~${{ github.event.pull_request.commits }} \
33+
--to HEAD \
34+
--verbose
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
#
6+
# This script checks that all the GitHub workflow Terraform variables defined as `TF_VAR_` prefixed
7+
# environment variables have a matching `variable` definition in the codebase. This is being done
8+
# to prevent accidental mismatches between the GitHub workflow and the Terraform codebase.
9+
#
10+
11+
12+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
13+
WORKFLOW_VARS="$(grep -r "^\s*TF_VAR" $SCRIPT_DIR/../ | awk -F ':' '{print $2}' | sort | uniq | sed 's/^[[:blank:]]*TF_VAR_//')"
14+
15+
# Loop through all the variables in the workflow and check if they are defined in the *.tf code
16+
for VAR in $WORKFLOW_VARS; do
17+
echo "🔎 Checking variable: \"$VAR\""
18+
grep -r --include="*.tf" "variable \"$VAR\"" "$SCRIPT_DIR/../../../" || (echo "❌ Variable \"$VAR\" is not defined as a Terraform variable" && exit 1)
19+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Terraform variable check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "develop"
7+
paths:
8+
- "aws/**"
9+
- "env/**"
10+
- ".github/workflows/**"
11+
12+
jobs:
13+
terraform-variable-check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
18+
19+
- name: Check Terraform variables are defined correctly
20+
run: |
21+
./.github/workflows/scripts/terraform-variable-check.sh

0 commit comments

Comments
 (0)