Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ENG-593: Improve linting in Github Action #3

Merged
merged 10 commits into from
Aug 13, 2024
13 changes: 7 additions & 6 deletions .github/workflows/yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
---
name: YAML Syntax Check

on: [push, pull_request]
on: [push, pull_request] # yamllint disable-line rule:truthy

jobs:
lint-yaml:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
- name: "Checkout repository"
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install yamllint
- name: "Install yamllint"
run: |
python -m pip install --upgrade pip
pip install yamllint

- name: Run yamllint
- name: "Run yamllint"
run: yamllint .
5 changes: 5 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
rules:
comments:
require-starting-space: true
min-spaces-from-content: 1 # Changed this to stop a mess between linters from Prettier (vscode) to yamllint - https://github.com/prettier/prettier/pull/10926
30 changes: 26 additions & 4 deletions actions/terraform-checks/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: "Terraform Checks"
description: "Perform common Terraform checks"

runs:
using: "composite"
steps:
Expand All @@ -10,17 +9,40 @@ runs:
with:
terraform_version: ${{ inputs.terraform_version }}

- name: "INFO: Ascertain Terraform Version"
- name: Cache plugin dir
uses: actions/cache@v4
with:
path: ~/.tflint.d/plugins
key: tflint-${{ hashFiles('.tflint.hcl') }}

- name: "Setup TFLint"
uses: terraform-linters/setup-tflint@v4
with:
tflint_version: v0.52.0

- name: "Print version of tflint"
shell: bash
run: tflint --version

- name: "Init TFLint"
shell: bash
run: tflint --init

- name: "Run TFLint"
shell: bash
run: tflint --chdir infrastructure/ --recursive

- name: "Ascertain Terraform Version"
shell: bash
run: terraform --version

- name: "INFO: Linting Terraform Files"
- name: "Checking Terraform Format of Files"
shell: bash
run: |
cd infrastructure
terraform fmt -check $(find . -name '*tf')

- name: "INFO: Validate Terraform Configs"
- name: "Validate Terraform Configs"
shell: bash
run: |
cd infrastructure
Expand Down
3 changes: 2 additions & 1 deletion examples/general-use/terraform-checks.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
# Example Github Workflow file to run Terraform Check action
name: Terraform Checks

on: [push, pull_request]
on: [push, pull_request] # yamllint disable-line rule:truthy

jobs:
example-job:
Expand Down