GithubHelp home page GithubHelp logo

devops-infra / action-format-hcl Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 174 KB

GitHub Action automatically formatting all HCL and TF files

Home Page: https://christophshyper.github.io/

License: MIT License

Dockerfile 41.94% Makefile 34.72% Shell 23.35%
hcl hcl2 hclfmt terraform terragrunt github-action github-actions github-action-docker github-actions-docker docker

action-format-hcl's Introduction

GitHub Action for formating HCL files

GitHub Action automatically formatting all HCL and TF files (.hcl, .tf, .tfvars).

Dockerized as devopsinfra/action-format-hcl.

Features:

Badge swag

Master branch Other branches
GitHub repo GitHub code size in bytes GitHub last commit GitHub license
DockerHub Docker version Image size Docker Pulls

Reference

    - name: Fail on malformatted files
      uses: devops-infra/[email protected]
      with:
        list: false
        write: true
        ignore: "config"
        diff: false
        check: false
        recursive: true
        dir: "modules"
Input Variable Required Default Description
list No false List files containing formatting inconsistencies.
write No true Overwrite input files. Disabled if using check.
ignore No "" Comma separated list of paths to ignore. Only for .hcl files.
diff No false Display diffs of formatting changes.
check No false Check if files are malformatted.
recursive No true Also process files in subdirectories.
dir No "" Path to be checked. Current dir as default.

Examples

Action can fail if malformed files will be found.

name: Check HCL
on:
  push
jobs:
  format-hcl:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Fail on malformatted files
      uses: devops-infra/[email protected]
      with:
        check: true

Action can automatically format all HCL files and commit updated files back to the repository using my other action action-commit-push.

name: Format HCL
on:
  push
jobs:
  format-hcl:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Format HCL files
      uses: devops-infra/[email protected]
    - name: Commit changes to repo
      uses: devops-infra/action-commit-push@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        commit_prefix: "[AUTO-FORMAT-HCL]"

action-format-hcl's People

Contributors

christophshyper avatar dependabot[bot] avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

brucebentley

action-format-hcl's Issues

git not handling unchanged files properly

I tested the Github action against HachiCorp Vault policy files, since it detects the formatting errors in the policies, then it failed because doesn't find tf and tfvars.

=> Searching for .tf and .tfvars files
error: unknown option `staged'

Wanted to see if you can include HCL Vault policies in the action or see if I can omit the step about searching .tf and .tfvars files in order to work with Vault.

git diff: unknow option 'staged'

Brief description

I tried to integration action-format-hcl within my CI phase.

Here is he workflow I've used : https://github.com/Xat59/githubactionstest/blob/main/.github/workflows/main.yml
And here is the output where you can see the error : https://github.com/Xat59/githubactionstest/pull/1/checks?check_run_id=1420263439

As you can see, I get the unknow option 'staged' when the workflow runs git diff.

Maybe the ubuntu:latest runner does contain a git version that allows --staged option on git diff command ?
I also tried ubuntu-16.04 and ubuntu-20.04 for the runner, instead of ubuntu-latest, but I get the same result.

Thanks

`check: true` requires `write: false`

๐Ÿ“ Brief description

The docs for write say "Disabled if using check", but if you pass check: true without write: false you will end up with something like this:

Inputs:
  list: false
  write: true
  ignore: 
  diff: true
  check: true
  recursive: true
  dir: 

=> Searching for .hcl files
Error, -check and -write=true cannot be used together

because the default write:true gets passed down to the script.

I would expect based on the README that it would be fine to specify check: true without mentioning write.

Error trying to lint one hcl file

Hi there,

I am getting an error once I try to lint only one .hcl file. According to the error looks like the recursive flag is enabled once a single file is passed in the dir parameter. Can you add support to lint only one .hcl file?

image

Thanks,

check input error.

I've set up the linter with the following settings:

- name: Fail on malformatted files
        uses: devops-infra/[email protected]
        with:
          check: true
          write: false

I am getting the error attached in the screenshot.
Despite I set up 'write:false'. Looks like it's ignoring it, then I get the error:

=> Searching for .hcl files
Error, -check and -write=true cannot be used together

check_error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.