Skip to content

Commit

Permalink
Changes to update-rules workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bensonce committed May 24, 2024
1 parent db0fcdc commit 28ec90b
Showing 1 changed file with 39 additions and 94 deletions.
133 changes: 39 additions & 94 deletions .github/workflows/update-rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,115 +9,60 @@ jobs:
update-rules:
name: Update Rules
runs-on: ubuntu-latest
outputs:
any_changed: ${{ steps.changed-files.outputs.any_changed }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Update rules
id: update-rules
run: |
cd scripts
pip install -r requirements.txt
python index.py
get-changes:
name: Get Changed Files
runs-on: ubuntu-latest
needs:
- update-rules
outputs:
any_changed: ${{ steps.changed-files.outputs.any_changed }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: "*.tf"

- name: List all changed files
run: echo '${{ steps.changed-files.outputs.all_changed_files }}'

tflint:
name: Run TFLint
runs-on: ubuntu-latest
needs:
- get-changes
if: ${{ needs.get-changes.outputs.any_changed == 'true' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1

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

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

- name: Show version
run: tflint --version

- name: Init TFLint
run: tflint --init

- name: Run TFLint
run: tflint --disable-rule=terraform_required_version

terraform-fmt:
name: Terraform Format
runs-on: ubuntu-latest
needs:
- get-changes
permissions:
contents: write
pull-requests: read
if: ${{ needs.get-changes.outputs.any_changed == 'true' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.6.0

- name: Terraform Format
run: terraform fmt --recursive .
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
managed_rules_locals.tf
managed_rules_variables.tf
- uses: dorny/paths-filter@v3
id: filter
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: HEAD
filters: |
terraform:
- '*.tf'
- name: List all changed files
run: echo '${{ steps.changed-files.outputs.all_changed_files }}'

create-pull-request:
name: Create/update pull request
runs-on: ubuntu-latest
needs:
- get-changes
- tflint
- terraform-fmt
if: ${{ needs.get-changes.outputs.any_changed == 'true' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/cache@v4
name: Cache plugin dir
with:
path: ~/.tflint.d/plugins
key: tflint-${{ hashFiles('.tflint.hcl') }}

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

- name: Show version
run: tflint --version

- name: Init TFLint
run: tflint --init

- name: Run TFLint
run: tflint --disable-rule=terraform_required_version

- uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.6.0

- name: Terraform Format
run: terraform fmt --recursive .

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main
Expand Down

0 comments on commit 28ec90b

Please sign in to comment.