enos: add shfmt formatting to enos module scripts (#28142)

Signed-off-by: Ryan Cragun <me@ryan.ec>
This commit is contained in:
Ryan Cragun
2024-08-23 13:45:30 -06:00
committed by GitHub
parent 438fae0952
commit b5d32b7bec
42 changed files with 156 additions and 111 deletions

View File

@@ -18,6 +18,7 @@ runs:
- uses: ./.github/actions/set-up-gosimports
- uses: ./.github/actions/set-up-gotestsum
- uses: ./.github/actions/set-up-misspell
- uses: ./.github/actions/set-up-shfmt
- uses: ./.github/actions/set-up-staticcheck
# We assume that the Go toolchain will be managed by the caller workflow so we don't set one
# up here.

61
.github/actions/set-up-shfmt/action.yml vendored Normal file
View File

@@ -0,0 +1,61 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
---
name: Set up shfmt from Github releases
description: Set up shfmt from Github releases
inputs:
destination:
description: "Where to install the shfmt binary (default: $HOME/bin/shfmt)"
type: boolean
default: "$HOME/bin/shfmt"
version:
description: "The version to install (default: latest)"
type: string
default: Latest
outputs:
destination:
description: Where the installed shfmt binary is
value: ${{ steps.install.outputs.destination }}
destination-dir:
description: The directory where the installed shfmt binary is
value: ${{ steps.install.outputs.destination-dir }}
version:
description: The installed version of shfmt
value: ${{ steps.install.outputs.version }}
runs:
using: composite
steps:
- id: install
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION=$(./.github/scripts/retry-command.sh gh release list -R mvdan/sh --exclude-drafts --exclude-pre-releases | grep ${{ inputs.version }} | cut -f1)
mkdir -p $(dirname ${{ inputs.destination }})
DESTINATION="$(readlink -f "${{ inputs.destination }}")"
DESTINATION_DIR="$(dirname "$DESTINATION")"
echo "$DESTINATION_DIR" >> "$GITHUB_PATH"
{
echo "destination=$DESTINATION"
echo "destination-dir=$DESTINATION_DIR"
echo "version=$VERSION"
} | tee -a "$GITHUB_OUTPUT"
ARCH="$(echo "$RUNNER_ARCH" | tr '[:upper:]' '[:lower:]')"
OS="$(echo "$RUNNER_OS" | tr '[:upper:]' '[:lower:]')"
if [ "$ARCH" = "x64" ]; then
export ARCH="amd64"
fi
if [ "$OS" = "macos" ]; then
export OS="darwin"
fi
./.github/scripts/retry-command.sh gh release download "$VERSION" --clobber -p "shfmt_*_${OS}_${ARCH}" -O shfmt -R mvdan/sh
chmod +x shfmt
mv shfmt "$DESTINATION"

View File

@@ -38,6 +38,7 @@ jobs:
ENOS_VAR_tfc_api_token: ${{ secrets.TF_API_TOKEN }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: ./.github/actions/install-external-tools
- uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false