Skip to content

Commit

Permalink
feat: Auto determine OS and Architecture (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
zahornyak authored Sep 9, 2024
1 parent 906f098 commit 58f4fa2
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions pre-commit/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ inputs:
description: Version of terraform-docs to use when evaluating checks
required: false
default: v0.16.0
terraform-architecture:
description: Terraform architecture to use when evaluating checks
required: false
default: amd64
tflint-version:
description: Version of tflint to use when evaluating checks
required: false
Expand Down Expand Up @@ -40,40 +36,63 @@ inputs:
runs:
using: composite
steps:
- name: Determine OS and Architecture
id: os_arch
shell: bash
run: |
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case $arch in
"x86_64")
arch="amd64"
;;
"i386" | "i686")
arch="386"
;;
"aarch64")
arch="arm64"
;;
"armv7l")
arch="arm"
;;
esac
echo "OS=$os" >> $GITHUB_ENV
echo "ARCH=$arch" >> $GITHUB_ENV
- name: Install Terraform v${{ inputs.terraform-version }}
shell: bash
run: |
rm -rf $(which terraform)
curl --retry 3 --retry-all-errors --retry-delay 3 -sSO https://releases.hashicorp.com/terraform/${{ inputs.terraform-version }}/terraform_${{ inputs.terraform-version }}_linux_${{ inputs.terraform-architecture }}.zip
sudo unzip -qq terraform_${{ inputs.terraform-version }}_linux_${{ inputs.terraform-architecture }}.zip terraform -d /usr/bin/
rm terraform_${{ inputs.terraform-version }}_linux_${{ inputs.terraform-architecture }}.zip 2> /dev/null
curl --retry 3 --retry-all-errors --retry-delay 3 -sSO https://releases.hashicorp.com/terraform/${{ inputs.terraform-version }}/terraform_${{ inputs.terraform-version }}_${{ env.OS }}_${{ env.ARCH }}.zip
sudo unzip -qq terraform_${{ inputs.terraform-version }}_${{ env.OS }}_${{ env.ARCH }}.zip terraform -d /usr/bin/
rm terraform_${{ inputs.terraform-version }}_${{ env.OS }}_${{ env.ARCH }}.zip 2> /dev/null
- name: Install pre-commit dependencies
shell: bash
run: |
pip install -q pre-commit
curl --retry 3 --retry-all-errors --retry-delay 3 -sSLo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/${{ inputs.terraform-docs-version }}/terraform-docs-${{ inputs.terraform-docs-version }}-$(uname)-${{ inputs.terraform-architecture }}.tar.gz
curl --retry 3 --retry-all-errors --retry-delay 3 -sSLo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/${{ inputs.terraform-docs-version }}/terraform-docs-${{ inputs.terraform-docs-version }}-${{ env.OS }}-${{ env.ARCH }}.tar.gz
sudo tar -xzf terraform-docs.tar.gz -C /usr/bin/ terraform-docs
rm terraform-docs.tar.gz 2> /dev/null
rm -rf $(which tflint)
if [[ "${{ inputs.tflint-version }}" == "latest" ]]; then
curl --retry 3 --retry-all-errors --retry-delay 3 -sSL "$(curl --retry 3 --retry-all-errors --retry-delay 3 -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_${{ inputs.terraform-architecture }}.zip")" > tflint.zip
curl --retry 3 --retry-all-errors --retry-delay 3 -sSL "$(curl --retry 3 --retry-all-errors --retry-delay 3 -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_${{ env.OS }}_${{ env.ARCH }}.zip")" > tflint.zip
else
curl --retry 3 --retry-all-errors --retry-delay 3 -sSLo ./tflint.zip https://github.com/terraform-linters/tflint/releases/download/${{ inputs.tflint-version }}/tflint_linux_${{ inputs.terraform-architecture }}.zip
curl --retry 3 --retry-all-errors --retry-delay 3 -sSLo ./tflint.zip https://github.com/terraform-linters/tflint/releases/download/${{ inputs.tflint-version }}/tflint_${{ env.OS }}_${{ env.ARCH }}.zip
fi
sudo unzip -qq tflint.zip tflint -d /usr/bin/
rm tflint.zip 2> /dev/null
if [[ "${{ inputs.install-hcledit }}" == "true" ]]; then
curl --retry 3 --retry-all-errors --retry-delay 3 -sSLo ./hcledit.tar.gz https://github.com/minamijoyo/hcledit/releases/download/v${{ inputs.hcledit-version }}/hcledit_${{ inputs.hcledit-version }}_$(uname)_${{ inputs.terraform-architecture }}.tar.gz
curl --retry 3 --retry-all-errors --retry-delay 3 -sSLo ./hcledit.tar.gz https://github.com/minamijoyo/hcledit/releases/download/v${{ inputs.hcledit-version }}/hcledit_${{ inputs.hcledit-version }}_${{ env.OS }}_${{ env.ARCH }}.tar.gz
sudo tar -xzf hcledit.tar.gz -C /usr/bin/ hcledit
rm hcledit.tar.gz 2> /dev/null
fi
if [[ "${{ inputs.install-tfsec }}" == "true" ]]; then
curl --retry 3 --retry-all-errors --retry-delay 3 -sSLo ./tfsec.tar.gz https://github.com/aquasecurity/tfsec/releases/download/v${{ inputs.tfsec-version }}/tfsec_${{ inputs.tfsec-version }}_$(uname)_${{ inputs.terraform-architecture }}.tar.gz
curl --retry 3 --retry-all-errors --retry-delay 3 -sSLo ./tfsec.tar.gz https://github.com/aquasecurity/tfsec/releases/download/v${{ inputs.tfsec-version }}/tfsec_${{ inputs.tfsec-version }}_${{ env.OS }}_${{ env.ARCH }}.tar.gz
sudo tar -xzf tfsec.tar.gz -C /usr/bin/ tfsec tfsec-checkgen
rm tfsec.tar.gz 2> /dev/null
fi
Expand Down

0 comments on commit 58f4fa2

Please sign in to comment.