From 27f666b983a9e2fd8afeefe0ea2220e2801bb8e5 Mon Sep 17 00:00:00 2001 From: Jakub Stejskal Date: Fri, 13 Nov 2026 15:02:05 +0100 Subject: [PATCH] Run ShellCheck on scripts and composite action steps Signed-off-by: Jakub Stejskal --- .../build/deploy-java/push-to-central.sh | 4 +++- .../actions/build/load-containers/action.yml | 2 +- .../dependencies/setup-kind/setup-kind.sh | 8 +++---- .github/tests/setup-nexus.sh | 2 +- .github/tests/shellcheck.sh | 24 +++++++++++++++++++ .github/workflows/lint.yml | 9 +++++++ 6 files changed, 42 insertions(+), 7 deletions(-) create mode 100755 .github/tests/shellcheck.sh diff --git a/.github/actions/build/deploy-java/push-to-central.sh b/.github/actions/build/deploy-java/push-to-central.sh index 433ca65..5aa0493 100755 --- a/.github/actions/build/deploy-java/push-to-central.sh +++ b/.github/actions/build/deploy-java/push-to-central.sh @@ -10,7 +10,9 @@ function cleanup() { # Run the cleanup on failure / exit trap cleanup EXIT -export GPG_TTY=$(tty) +# tty fails without a terminal (as on CI); that must not stop the script +GPG_TTY=$(tty) || true +export GPG_TTY echo $GPG_SIGNING_KEY | base64 -d > signing.gpg gpg --batch --import signing.gpg diff --git a/.github/actions/build/load-containers/action.yml b/.github/actions/build/load-containers/action.yml index 1888cfb..f2187a7 100644 --- a/.github/actions/build/load-containers/action.yml +++ b/.github/actions/build/load-containers/action.yml @@ -41,7 +41,7 @@ runs: shell: bash if: ${{ contains(inputs.registry, 'minikube') }} run: | - eval $(minikube docker-env) + eval "$(minikube docker-env)" make docker_load docker_e2e docker_delete_archive env: DOCKER_ARCHITECTURE: ${{ inputs.architecture }} diff --git a/.github/actions/dependencies/setup-kind/setup-kind.sh b/.github/actions/dependencies/setup-kind/setup-kind.sh index 1f0e010..bf98c57 100755 --- a/.github/actions/dependencies/setup-kind/setup-kind.sh +++ b/.github/actions/dependencies/setup-kind/setup-kind.sh @@ -127,7 +127,7 @@ function load_iptables_modules_for_podman { 4) registry_dns - DNS name for registry @global: IP_FAMILY - Determines whether to configure IPv4 or IPv6 settings -@note: Adjusts the container runtime’s config files (/etc/docker/daemon.json +@note: Adjusts the container runtime config files (/etc/docker/daemon.json or /etc/containers/registries.conf) and restarts the respective service. ' function updateContainerRuntimeConfiguration { @@ -174,7 +174,7 @@ EOF sudo systemctl restart docker else # Ensure the podman_config is inserted correctly after unqualified-search-registries - sudo awk -v config="$podman_config" ' + awk -v config="$podman_config" ' BEGIN { inserted = 0 } /unqualified-search-registries/ && !inserted { print $0 @@ -238,12 +238,12 @@ nodes: EOF # Add control-plane nodes - for i in $(seq 1 "$control_planes"); do + for _ in $(seq 1 "$control_planes"); do echo " - role: control-plane" >> /tmp/kind-config.yaml done # Add worker nodes - for i in $(seq 1 "$worker_nodes"); do + for _ in $(seq 1 "$worker_nodes"); do echo " - role: worker" >> /tmp/kind-config.yaml done diff --git a/.github/tests/setup-nexus.sh b/.github/tests/setup-nexus.sh index f72612a..77d4bfb 100755 --- a/.github/tests/setup-nexus.sh +++ b/.github/tests/setup-nexus.sh @@ -35,7 +35,7 @@ echo ">>> Waiting for Nexus to fully initialize..." sleep 10 echo ">>> Retrieving admin password..." -NEXUS_PASSWORD=$(docker exec $(docker ps -q --filter ancestor=$NEXUS_IMAGE) cat /nexus-data/admin.password 2>/dev/null) +NEXUS_PASSWORD=$(docker exec "$(docker ps -q --filter ancestor="$NEXUS_IMAGE")" cat /nexus-data/admin.password 2>/dev/null) if [ -z "$NEXUS_PASSWORD" ]; then echo "ERROR: Could not retrieve Nexus admin password" diff --git a/.github/tests/shellcheck.sh b/.github/tests/shellcheck.sh new file mode 100755 index 0000000..31fbd2f --- /dev/null +++ b/.github/tests/shellcheck.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Runs ShellCheck on all shell scripts and on the run: steps of composite actions. +# actionlint covers run: steps in workflows only, so composite actions need this. +set -euo pipefail +cd "$(git rev-parse --show-toplevel)" + +status=0 + +find .github -name '*.sh' -print0 | xargs -0 shellcheck -S warning || status=1 + +for action in .github/actions/*/*/action.yml; do + steps=$(yq '.runs.steps | length' "$action") + for ((i = 0; i < steps; i++)); do + [ "$(yq ".runs.steps[$i] | has(\"run\")" "$action")" = "true" ] || continue + # Expressions are evaluated before the shell runs, so replace them like actionlint does + if ! out=$( { echo '#!/bin/bash'; yq ".runs.steps[$i].run" "$action" | sed -E 's/\$\{\{[^}]*\}\}/_expr_/g'; } | shellcheck -S warning -e SC2050,SC2154,SC2157,SC2194 -); then + echo "${action}: step '$(yq ".runs.steps[$i].name" "$action")'" + echo "$out" + status=1 + fi + done +done + +exit $status diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6acc044..6fce371 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,3 +20,12 @@ jobs: - uses: docker://rhysd/actionlint@sha256:b1934ee5f1c509618f2508e6eb47ee0d3520686341fec936f3b79331f9315667 # v1.7.12 with: args: -color + + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: ./.github/actions/dependencies/install-shellcheck + - uses: ./.github/actions/dependencies/install-yq + - name: Run ShellCheck on scripts and composite actions + run: .github/tests/shellcheck.sh