From eef99899dc522b9a02520bdca3ebca067843ebd6 Mon Sep 17 00:00:00 2001 From: Nicholas McDonnell <50747025+mcdonnnj@users.noreply.github.com> Date: Mon, 28 Feb 2022 00:32:42 -0500 Subject: [PATCH] Add shell script pre-commit hooks Now that software updates are handled by a bash script that is stored in the repository these pre-commit hooks should be re-added to the pre-commit configuration. This also includes re-adding all of the scaffolding that installs the shfmt tool in the build.yml workflow. --- .github/workflows/build.yml | 25 ++++++++++++++++++++++++- .pre-commit-config.yaml | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5031eef..ae62dcc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,23 +15,46 @@ jobs: lint: runs-on: ubuntu-latest steps: + - id: setup-env + uses: cisagov/setup-env-github-action@develop - uses: actions/checkout@v2 - id: setup-python uses: actions/setup-python@v2 with: python-version: "3.10" + # We need the Go version and Go cache location for the actions/cache step, + # so the Go installation must happen before that. + - uses: actions/setup-go@v2 + with: + go-version: '1.16' + - name: Store installed Go version + id: go-version + run: | + echo "::set-output name=version::"\ + "$(go version | sed 's/^go version go\([0-9.]\+\) .*/\1/')" + - name: Lookup Go cache directory + id: go-cache + run: | + echo "::set-output name=dir::$(go env GOCACHE)" - uses: actions/cache@v2 env: BASE_CACHE_KEY: "${{ github.job }}-${{ runner.os }}-\ - py${{ steps.setup-python.outputs.python-version }}" + py${{ steps.setup-python.outputs.python-version }}-\ + go${{ steps.go-version.outputs.version }}-" with: path: | ${{ env.PIP_CACHE_DIR }} ${{ env.PRE_COMMIT_CACHE_DIR }} + ${{ steps.go-cache.outputs.dir }} key: "${{ env.BASE_CACHE_KEY }}\ ${{ hashFiles('**/.pre-commit-config.yaml') }}" restore-keys: | ${{ env.BASE_CACHE_KEY }} + - name: Install shfmt + env: + PACKAGE_URL: mvdan.cc/sh/v3/cmd/shfmt + PACKAGE_VERSION: ${{ steps.setup-env.outputs.shfmt-version }} + run: go install ${PACKAGE_URL}@${PACKAGE_VERSION} - name: Install dependencies run: | python -m pip install --upgrade pip setuptools wheel diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 352bbd2..d4ece83 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,3 +46,23 @@ repos: - id: yamllint args: - --strict + + # Shell script hooks + - repo: https://github.com/cisagov/pre-commit-shfmt + rev: v0.0.2 + hooks: + - id: shfmt + args: + # Indent by two spaces + - -i + - '2' + # Binary operators may start a line + - -bn + # Switch cases are indented + - -ci + # Redirect operators are followed by a space + - -sr + - repo: https://github.com/detailyang/pre-commit-shell + rev: 1.0.5 + hooks: + - id: shell-lint