Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add TF_VAR check and conventional commit lint workflows #663

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/conventional-commit-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Conventional commit lint

on:
pull_request:

jobs:
conventional-commit-lint:
runs-on: ubuntu-latest
steps:
- name: Get all PR commits
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"

- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: ${{ env.PR_FETCH_DEPTH }}

- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '20.x'

- name: Setup commitlint
run: |
npm install -g @commitlint/config-conventional @commitlint/cli

- name: Validate all PR commits
run: |
npx commitlint \
--extends '@commitlint/config-conventional' \
--from HEAD~${{ github.event.pull_request.commits }} \
--to HEAD \
--verbose
19 changes: 19 additions & 0 deletions .github/workflows/scripts/terraform-variable-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

#
# This script checks that all the GitHub workflow Terraform variables defined as `TF_VAR_` prefixed
# environment variables have a matching `variable` definition in the codebase. This is being done
# to prevent accidental mismatches between the GitHub workflow and the Terraform codebase.
#


SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
WORKFLOW_VARS="$(grep -r "^\s*TF_VAR" $SCRIPT_DIR/../ | awk -F ':' '{print $2}' | sort | uniq | sed 's/^[[:blank:]]*TF_VAR_//')"

# Loop through all the variables in the workflow and check if they are defined in the *.tf code
for VAR in $WORKFLOW_VARS; do
echo "🔎 Checking variable: \"$VAR\""
grep -r --include="*.tf" "variable \"$VAR\"" "$SCRIPT_DIR/../../../" || (echo "❌ Variable \"$VAR\" is not defined as a Terraform variable" && exit 1)
done
21 changes: 21 additions & 0 deletions .github/workflows/terraform-variable-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Terraform variable check

on:
pull_request:
branches:
- "develop"
paths:
- "aws/**"
- "env/**"
- ".github/workflows/**"

jobs:
terraform-variable-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Check Terraform variables are defined correctly
run: |
./.github/workflows/scripts/terraform-variable-check.sh
Loading