├── .dockerignore
├── .github
├── CODEOWNERS
├── dependabot.yml
└── workflows
│ ├── CRON.yml
│ ├── PUSH-MASTER.yml
│ └── PUSH-OTHER.yml
├── .gitignore
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── action.yml
└── entrypoint.sh
/.dockerignore:
--------------------------------------------------------------------------------
1 | # Exclude
2 | *
3 |
4 | # Include
5 | !LICENSE
6 | !README.md
7 | !entrypoint.sh
8 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Owner of everything
2 | * @ChristophShyper @devops-infra/christophshyper
3 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | # Maintain dependencies for GitHub Actions
4 | - package-ecosystem: github-actions
5 | directory: "/"
6 | schedule:
7 | interval: daily
8 | assignees:
9 | - ChristophShyper
10 | labels:
11 | - automatic
12 |
13 | # Enable version updates for Docker
14 | - package-ecosystem: docker
15 | directory: "/"
16 | schedule:
17 | interval: daily
18 | assignees:
19 | - ChristophShyper
20 | labels:
21 | - automatic
22 |
23 | # # Enable version updates for pip
24 | # - package-ecosystem: pip
25 | # directory: "/"
26 | # schedule:
27 | # interval: daily
28 | # assignees:
29 | # - ChristophShyper
30 | # labels:
31 | # - automatic
32 |
--------------------------------------------------------------------------------
/.github/workflows/CRON.yml:
--------------------------------------------------------------------------------
1 | name: Weekly build
2 |
3 | on:
4 | schedule:
5 | # Run every week at 5.00 AM UTC
6 | - cron: "0 5 */7 * *"
7 |
8 | jobs:
9 | build_and_push:
10 | name: Build and push images
11 | runs-on: ubuntu-latest
12 | steps:
13 | - name: Checkout repository
14 | uses: actions/checkout@v4
15 |
16 | - name: Build Docker image and push to registry
17 | env:
18 | DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
19 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 | TERM: xterm-256color
21 | run: make build
22 |
--------------------------------------------------------------------------------
/.github/workflows/PUSH-MASTER.yml:
--------------------------------------------------------------------------------
1 | name: Push to master
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 |
8 | jobs:
9 | labels:
10 | name: Update repo labels
11 | runs-on: ubuntu-latest
12 | steps:
13 | - name: Checkout repository
14 | uses: actions/checkout@v4
15 |
16 | - name: Download labels' config
17 | shell: bash
18 | run: |
19 | mkdir -p .tmp
20 | curl -LsS https://raw.githubusercontent.com/devops-infra/.github/master/.github/labels.yml -o .tmp/labels.yml
21 |
22 | - name: Update labels
23 | uses: crazy-max/ghaction-github-labeler@v5.3.0
24 | with:
25 | github-token: ${{ secrets.GITHUB_TOKEN }}
26 | yaml-file: .tmp/labels.yml
27 |
28 | lint:
29 | name: Run linters
30 | runs-on: ubuntu-latest
31 | steps:
32 | - name: Checkout repository
33 | uses: actions/checkout@v4
34 |
35 | - name: Docker Lint
36 | uses: luke142367/Docker-Lint-Action@v1.1.1
37 | env:
38 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 |
40 | - name: Haskell Dockerfile Linter (Hadolint)
41 | uses: brpaz/hadolint-action@v1.5.0
42 | with:
43 | dockerfile: Dockerfile
44 |
45 | build_and_push:
46 | name: Build and push images
47 | needs: lint
48 | runs-on: ubuntu-latest
49 | steps:
50 | - name: Checkout repository
51 | uses: actions/checkout@v4
52 |
53 | - name: Build Docker image and push to registry
54 | env:
55 | DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
56 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 | TERM: xterm-256color
58 | run: make build push
59 |
--------------------------------------------------------------------------------
/.github/workflows/PUSH-OTHER.yml:
--------------------------------------------------------------------------------
1 | name: Push to other branches
2 |
3 | on:
4 | push:
5 | branches-ignore:
6 | - master
7 | - release/*
8 |
9 | jobs:
10 | labels:
11 | name: Update repo labels
12 | runs-on: ubuntu-latest
13 | steps:
14 | - name: Checkout repository
15 | uses: actions/checkout@v4
16 |
17 | - name: Download labels' config
18 | shell: bash
19 | run: |
20 | mkdir -p .tmp
21 | curl -LsS https://raw.githubusercontent.com/devops-infra/.github/master/.github/labels.yml -o .tmp/labels.yml
22 |
23 | - name: Update labels - dry run
24 | uses: crazy-max/ghaction-github-labeler@v5.3.0
25 | with:
26 | github-token: ${{ secrets.GITHUB_TOKEN }}
27 | yaml-file: .tmp/labels.yml
28 | dry-run: true
29 |
30 | lint:
31 | name: Run linters
32 | if: "!startsWith(github.ref, 'refs/heads/dependabot')"
33 | runs-on: ubuntu-latest
34 | steps:
35 | - name: Checkout repository
36 | uses: actions/checkout@v4
37 |
38 | - name: Docker Lint
39 | uses: luke142367/Docker-Lint-Action@v1.1.1
40 | env:
41 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42 |
43 | - name: Haskell Dockerfile Linter (Hadolint)
44 | uses: brpaz/hadolint-action@v1.5.0
45 | with:
46 | dockerfile: Dockerfile
47 |
48 | build:
49 | name: Build image
50 | runs-on: ubuntu-latest
51 | steps:
52 | - name: Checkout repository
53 | uses: actions/checkout@v4
54 |
55 | - name: Build Docker image
56 | env:
57 | TERM: xterm-256color
58 | run: make build
59 |
60 | pull_request:
61 | name: Create Pull Request
62 | runs-on: ubuntu-latest
63 | steps:
64 | - name: Checkout repository
65 | uses: actions/checkout@v4
66 | with:
67 | fetch-depth: 0
68 |
69 | - name: Download Pull Request template
70 | shell: bash
71 | run: |
72 | mkdir -p .tmp
73 | curl -LsS https://raw.githubusercontent.com/devops-infra/.github/master/PULL_REQUEST_TEMPLATE.md -o .tmp/PULL_REQUEST_TEMPLATE.md
74 |
75 | - name: Create pull request - bugfix (conditional)
76 | if: startsWith(github.ref, 'refs/heads/bugfix')
77 | uses: devops-infra/action-pull-request@v0.6.0
78 | with:
79 | github_token: ${{ secrets.GITHUB_TOKEN }}
80 | assignee: ${{ github.actor }}
81 | label: bugfix
82 | template: .tmp/PULL_REQUEST_TEMPLATE.md
83 | get_diff: true
84 |
85 | - name: Create pull request - dependency (conditional)
86 | if: startsWith(github.ref, 'refs/heads/dependency')
87 | uses: devops-infra/action-pull-request@v0.6.0
88 | with:
89 | github_token: ${{ secrets.GITHUB_TOKEN }}
90 | assignee: ${{ github.actor }}
91 | label: dependency
92 | template: .tmp/PULL_REQUEST_TEMPLATE.md
93 | get_diff: true
94 |
95 | - name: Create pull request - documentation (conditional)
96 | if: startsWith(github.ref, 'refs/heads/documentation')
97 | uses: devops-infra/action-pull-request@v0.6.0
98 | with:
99 | github_token: ${{ secrets.GITHUB_TOKEN }}
100 | assignee: ${{ github.actor }}
101 | label: documentation
102 | template: .tmp/PULL_REQUEST_TEMPLATE.md
103 | get_diff: true
104 |
105 | - name: Create pull request - feature (conditional)
106 | if: startsWith(github.ref, 'refs/heads/feature')
107 | uses: devops-infra/action-pull-request@v0.6.0
108 | with:
109 | github_token: ${{ secrets.GITHUB_TOKEN }}
110 | assignee: ${{ github.actor }}
111 | label: feature
112 | template: .tmp/PULL_REQUEST_TEMPLATE.md
113 | get_diff: true
114 |
115 | - name: Create pull request - test (conditional)
116 | if: startsWith(github.ref, 'refs/heads/test')
117 | uses: devops-infra/action-pull-request@v0.6.0
118 | with:
119 | github_token: ${{ secrets.GITHUB_TOKEN }}
120 | assignee: ${{ github.actor }}
121 | reviewer: ${{ github.actor }}
122 | label: test
123 | template: .tmp/PULL_REQUEST_TEMPLATE.md
124 | draft: true
125 | get_diff: true
126 |
127 | - name: Create pull request - other (conditional)
128 | if: "!startsWith(github.ref, 'refs/heads/bugfix') && !startsWith(github.ref, 'refs/heads/dependabot') && !startsWith(github.ref, 'refs/heads/dependency') && !startsWith(github.ref, 'refs/heads/documentation') && !startsWith(github.ref, 'refs/heads/feature') && !startsWith(github.ref, 'refs/heads/test')"
129 | uses: devops-infra/action-pull-request@v0.6.0
130 | with:
131 | github_token: ${{ secrets.GITHUB_TOKEN }}
132 | assignee: ${{ github.actor }}
133 | label: feature
134 | template: .tmp/PULL_REQUEST_TEMPLATE.md
135 | get_diff: true
136 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Intellij
2 | /.idea/
3 | *.iml
4 |
5 | # Custom
6 | .tmp/
7 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Instead of building from scratch pull my other docker image
2 | FROM devopsinfra/docker-terragrunt:slim-latest as builder
3 |
4 | # Use a clean tiny image to store artifacts in
5 | FROM ubuntu:24.04
6 |
7 | # Labels for http://label-schema.org/rc1/#build-time-labels
8 | # And for https://github.com/opencontainers/image-spec/blob/master/annotations.md
9 | # And for https://help.github.com/en/actions/building-actions/metadata-syntax-for-github-actions
10 | ARG NAME="GitHub Action for formating HCL files"
11 | ARG DESCRIPTION="GitHub Action automatically formatting all HCL and TF files."
12 | ARG REPO_URL="https://github.com/devops-infra/action-format-hcl"
13 | ARG AUTHOR="Krzysztof Szyper / ChristophShyper / biotyk@mail.com"
14 | ARG HOMEPAGE="https://christophshyper.github.io/"
15 | ARG BUILD_DATE=2020-04-01T00:00:00Z
16 | ARG VCS_REF=abcdef1
17 | ARG VERSION=v0.0
18 | LABEL \
19 | com.github.actions.name="${NAME}" \
20 | com.github.actions.author="${AUTHOR}" \
21 | com.github.actions.description="${DESCRIPTION}" \
22 | com.github.actions.color="purple" \
23 | com.github.actions.icon="upload-cloud" \
24 | org.label-schema.build-date="${BUILD_DATE}" \
25 | org.label-schema.name="${NAME}" \
26 | org.label-schema.description="${DESCRIPTION}" \
27 | org.label-schema.usage="README.md" \
28 | org.label-schema.url="${HOMEPAGE}" \
29 | org.label-schema.vcs-url="${REPO_URL}" \
30 | org.label-schema.vcs-ref="${VCS_REF}" \
31 | org.label-schema.vendor="${AUTHOR}" \
32 | org.label-schema.version="${VERSION}" \
33 | org.label-schema.schema-version="1.0" \
34 | org.opencontainers.image.created="${BUILD_DATE}" \
35 | org.opencontainers.image.authors="${AUTHOR}" \
36 | org.opencontainers.image.url="${HOMEPAGE}" \
37 | org.opencontainers.image.documentation="${REPO_URL}/blob/master/README.md" \
38 | org.opencontainers.image.source="${REPO_URL}" \
39 | org.opencontainers.image.version="${VERSION}" \
40 | org.opencontainers.image.revision="${VCS_REF}" \
41 | org.opencontainers.image.vendor="${AUTHOR}" \
42 | org.opencontainers.image.licenses="MIT" \
43 | org.opencontainers.image.title="${NAME}" \
44 | org.opencontainers.image.description="${DESCRIPTION}" \
45 | maintainer="${AUTHOR}" \
46 | repository="${REPO_URL}"
47 |
48 | # Copy all needed files
49 | COPY --from=builder /usr/bin/terraform /usr/bin/format-hcl /usr/bin/fmt.sh /usr/bin/terragrunt-fmt.sh /usr/bin/
50 | COPY entrypoint.sh /
51 |
52 | # Install needed packages
53 | # hadolint ignore=DL3008
54 | RUN set -eux ;\
55 | apt-get update -y ;\
56 | chmod +x /entrypoint.sh /usr/bin/format-hcl /usr/bin/fmt.sh /usr/bin/terragrunt-fmt.sh ;\
57 | apt-get clean ;\
58 | rm -rf /var/lib/apt/lists/*
59 |
60 | # Finish up
61 | CMD ["terraform --version"]
62 | WORKDIR /github/workspace
63 | ENTRYPOINT ["/entrypoint.sh"]
64 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Krzysztof Szyper (https://christophshyper.github.io/)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: help build push
2 | phony: help
3 |
4 | # Release tag for the action
5 | VERSION := v0.3.7
6 |
7 | # GitHub Actions bogus variables
8 | GITHUB_REF ?= refs/heads/null
9 | GITHUB_SHA ?= aabbccddeeff
10 |
11 | # Other variables and constants
12 | CURRENT_BRANCH := $(shell echo $(GITHUB_REF) | sed 's/refs\/heads\///')
13 | GITHUB_SHORT_SHA := $(shell echo $(GITHUB_SHA) | cut -c1-7)
14 | DOCKER_USER_ID := christophshyper
15 | DOCKER_ORG_NAME := devopsinfra
16 | DOCKER_IMAGE := action-format-hcl
17 | DOCKER_NAME := $(DOCKER_ORG_NAME)/$(DOCKER_IMAGE)
18 | BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
19 |
20 | # Some cosmetics
21 | SHELL := bash
22 | TXT_RED := $(shell tput setaf 1)
23 | TXT_GREEN := $(shell tput setaf 2)
24 | TXT_YELLOW := $(shell tput setaf 3)
25 | TXT_RESET := $(shell tput sgr0)
26 | define NL
27 |
28 |
29 | endef
30 |
31 | # Main actions
32 | help: ## Display help prompt
33 | $(info Available options:)
34 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(TXT_YELLOW)%-25s $(TXT_RESET) %s\n", $$1, $$2}'
35 |
36 | build: ## Build Docker image
37 | $(info $(NL)$(TXT_GREEN) == STARTING BUILD ==$(TXT_RESET))
38 | $(info $(TXT_GREEN)Release tag:$(TXT_YELLOW) $(VERSION)$(TXT_RESET))
39 | $(info $(TXT_GREEN)Current branch:$(TXT_YELLOW) $(CURRENT_BRANCH)$(TXT_RESET))
40 | $(info $(TXT_GREEN)Commit hash:$(TXT_YELLOW) $(GITHUB_SHORT_SHA)$(TXT_RESET))
41 | $(info $(TXT_GREEN)Build date:$(TXT_YELLOW) $(BUILD_DATE)$(TXT_RESET))
42 | $(info $(NL)$(TXT_GREEN)Building Docker image:$(TXT_YELLOW) $(DOCKER_NAME):$(VERSION)$(TXT_RESET))
43 | @docker build \
44 | --build-arg BUILD_DATE=$(BUILD_DATE) \
45 | --build-arg VCS_REF=$(GITHUB_SHORT_SHA) \
46 | --build-arg VERSION=$(VERSION) \
47 | --file=Dockerfile \
48 | --tag=$(DOCKER_NAME):$(VERSION) .
49 |
50 | push: ## Push to DockerHub
51 | $(info $(NL)$(TXT_GREEN) == STARTING DEPLOYMENT == $(TXT_RESET))
52 | $(info $(NL)$(TXT_GREEN)Logging-in to DockerHub$(TXT_RESET))
53 | @echo $(DOCKER_TOKEN) | docker login -u $(DOCKER_USER_ID) --password-stdin
54 | $(info $(NL)$(TXT_GREEN)Pushing Docker image:$(TXT_YELLOW) $(DOCKER_NAME):$(VERSION)$(TXT_RESET))
55 | @docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):latest
56 | @docker push $(DOCKER_NAME):$(VERSION)
57 | @docker push $(DOCKER_NAME):latest
58 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GitHub Action for formating HCL files
2 |
3 | **GitHub Action automatically formatting all [HCL](https://github.com/hashicorp/hcl) and [TF](https://www.terraform.io/docs/configuration/index.html) files (.hcl, .tf, .tfvars).**
4 |
5 | Dockerized as [devopsinfra/action-format-hcl](https://hub.docker.com/repository/docker/devopsinfra/action-format-hcl).
6 |
7 | Features:
8 | * Container is a stripped down image of my other creation - [devopsinfra/docker-terragrunt](https://github.com/devopsinfra/docker-terragrunt) - framework for managing Infrastructure-as-a-Code.
9 | * Main use will be everywhere where [Terraform](https://github.com/hashicorp/terraform) or [Terragrunt](https://github.com/gruntwork-io/terragrunt) is used.
10 | * Using combination of my wrapper for [cytopia](https://github.com/cytopia)'s [docker-terragrunt-fmt](https://github.com/cytopia/docker-terragrunt-fmt).
11 |
12 |
13 | ## Badge swag
14 | [](https://github.com/devops-infra/action-format-hcl/actions?query=workflow%3A%22Master+branch%22)
15 | [](https://github.com/devops-infra/action-format-hcl/actions?query=workflow%3A%22Other+branches%22)
16 |
17 | [
18 | 
19 | 
20 | 
21 | 
22 | ](https://github.com/devops-infra/action-format-hcl "shields.io")
23 |
24 | [
25 | 
26 | 
27 | 
28 | 
29 | ](https://hub.docker.com/r/devopsinfra/action-format-hcl "shields.io")
30 |
31 |
32 | ## Reference
33 |
34 | ```yaml
35 | - name: Fail on malformatted files
36 | uses: devops-infra/action-format-hcl@v0.3.6
37 | with:
38 | list: false
39 | write: true
40 | ignore: "config"
41 | diff: false
42 | check: false
43 | recursive: true
44 | dir: "modules"
45 | ```
46 |
47 | | Input Variable | Required | Default | Description |
48 | | -------------- | -------- | ------- |---------------------------------------------------------------|
49 | | list | No | `false` | List files containing formatting inconsistencies. |
50 | | write | No | `true` | Overwrite input files. Should be disabled if using check. |
51 | | ignore | No | `""` | Comma separated list of paths to ignore. Only for .hcl files. |
52 | | diff | No | `false` | Display diffs of formatting changes. |
53 | | check | No | `false` | Check if files are malformatted. |
54 | | recursive | No | `true` | Also process files in subdirectories. |
55 | | dir | No | `""` | Path to be checked. Current dir as default. |
56 |
57 |
58 | ## Examples
59 |
60 | Action can fail if malformed files will be found.
61 | ```yaml
62 | name: Check HCL
63 | on:
64 | push
65 | jobs:
66 | format-hcl:
67 | runs-on: ubuntu-latest
68 | steps:
69 | - name: Checkout
70 | uses: actions/checkout@v2
71 | - name: Fail on malformatted files
72 | uses: devops-infra/action-format-hcl@v0.3.6
73 | with:
74 | check: true
75 | ```
76 |
77 | Action can automatically format all HCL files and commit updated files back to the repository using my other action [action-commit-push](https://github.com/devops-infra/action-commit-push).
78 | ```yaml
79 | name: Format HCL
80 | on:
81 | push
82 | jobs:
83 | format-hcl:
84 | runs-on: ubuntu-latest
85 | steps:
86 | - name: Checkout
87 | uses: actions/checkout@v2
88 | - name: Format HCL files
89 | uses: devops-infra/action-format-hcl@v0.3.6
90 | - name: Commit changes to repo
91 | uses: devops-infra/action-commit-push@master
92 | with:
93 | github_token: ${{ secrets.GITHUB_TOKEN }}
94 | commit_prefix: "[AUTO-FORMAT-HCL]"
95 | ```
96 |
--------------------------------------------------------------------------------
/action.yml:
--------------------------------------------------------------------------------
1 | name: GitHub Action for formating HCL files
2 | author: Krzysztof Szyper / ChristophShyper / biotyk@mail.com
3 | description: GitHub Action automatically formatting all HCL and TF files
4 | inputs:
5 | list:
6 | description: List files containing formatting inconsistencies.
7 | required: false
8 | default: "false"
9 | write:
10 | description: Overwrite input files. Disabled if using check.
11 | required: false
12 | default: "true"
13 | ignore:
14 | description: Comma separated list of paths to ignore. Only for .hcl files.
15 | required: false
16 | default: ""
17 | diff:
18 | description: Display diffs of formatting changes.
19 | required: false
20 | default: "false"
21 | check:
22 | description: Check if files are malformatted.
23 | required: false
24 | default: "false"
25 | recursive:
26 | description: Also process files in subdirectories.
27 | required: false
28 | default: "true"
29 | dir:
30 | description: Path to be checked. Current dir as default.
31 | required: false
32 | default: ""
33 | outputs:
34 | files_changed:
35 | description: List of formatted files
36 | runs:
37 | using: docker
38 | image: docker://devopsinfra/action-format-hcl:v0.3.6
39 | branding:
40 | color: purple
41 | icon: upload-cloud
42 |
--------------------------------------------------------------------------------
/entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Return code
4 | RET_CODE=0
5 |
6 | # Print input variables
7 | echo "Inputs:"
8 | echo " list: ${INPUT_LIST}"
9 | echo " write: ${INPUT_WRITE}"
10 | echo " ignore: ${INPUT_IGNORE}"
11 | echo " diff: ${INPUT_DIFF}"
12 | echo " check: ${INPUT_CHECK}"
13 | echo " recursive: ${INPUT_RECURSIVE}"
14 | echo " dir: ${INPUT_DIR}"
15 |
16 | # Remap input variables as parameters for format-hcl
17 | LIST="-list=${INPUT_LIST}"
18 | WRITE="-write=${INPUT_WRITE}"
19 |
20 | if [[ -n "${INPUT_IGNORE}" ]]; then
21 | IGNORE="-ignore=${INPUT_IGNORE}"
22 | else
23 | IGNORE=""
24 | fi
25 |
26 | if [[ "${INPUT_DIFF}" == "true" ]]; then
27 | DIFF="-diff"
28 | else
29 | DIFF=""
30 | fi
31 |
32 | if [[ "${INPUT_CHECK}" == "true" ]]; then
33 | CHECK="-check"
34 | else
35 | CHECK=""
36 | fi
37 |
38 | if [[ "${INPUT_RECURSIVE}" == "true" ]]; then
39 | RECURSIVE="-recursive"
40 | else
41 | RECURSIVE=""
42 | fi
43 |
44 | if [[ -n "${INPUT_DIR}" ]]; then
45 | DIR="${INPUT_DIR}"
46 | else
47 | DIR=""
48 | fi
49 |
50 | # Run main action
51 | touch /tmp/time_compare
52 | /usr/bin/format-hcl ${LIST} ${WRITE} ${IGNORE} ${DIFF} ${CHECK} ${RECURSIVE} ${DIR}
53 | RET_CODE=$?
54 |
55 | # List of changed files
56 | FILES_CHANGED=$(find . -newer /tmp/time_compare -type f)
57 |
58 | # Info about changed files
59 | if [[ -n ${FILES_CHANGED} ]]; then
60 | echo -e "\n[INFO] Updated files:"
61 | for FILE in ${FILES_CHANGED}; do
62 | echo "${FILE}"
63 | done
64 | else
65 | echo -e "\n[INFO] No files updated."
66 | fi
67 |
68 | # Finish
69 | if [[ ${RET_CODE} != "0" ]]; then
70 | echo -e "\n[ERROR] Check log for errors."
71 | exit 1
72 | else
73 | # Pass in other cases
74 | echo -e "\n[INFO] No errors found."
75 | exit 0
76 | fi
77 |
--------------------------------------------------------------------------------