From 25fba973692eec531b13315bd33d1b4d741c282b Mon Sep 17 00:00:00 2001 From: "Peter J. Jones" Date: Fri, 17 Apr 2026 14:42:05 +0200 Subject: [PATCH 1/2] lib: Extract common code to a library Also, have the tool checker exit with 100 like the authors checker. --- lib/ci-tools.sh | 49 +++++++++++++++++++++++++++++++++++ scripts/authors.sh | 48 ++-------------------------------- scripts/check-tool-handler.sh | 10 ++++--- 3 files changed, 58 insertions(+), 49 deletions(-) create mode 100755 lib/ci-tools.sh diff --git a/lib/ci-tools.sh b/lib/ci-tools.sh new file mode 100755 index 0000000..b55d951 --- /dev/null +++ b/lib/ci-tools.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +################################################################################ +# Because GitHub runners don't set these: +export LANG=en_US.UTF-8 +export LC_ALL=$LANG +export LC_COLLATE=$LANG + +################################################################################ +# Strip whitespace and delete blank lines from STDIN to STDOUT. +function strip_space() { + sed -E \ + -e 's/^[[:space:]]+//' \ + -e 's/[[:space:]]+$//' \ + -e 's/[[:space:]]+/ /' \ + -e '/^[[:space:]]*$/d' +} + +################################################################################ +# Resolve a `git` commit name given on the command line. +# +# When a repository is cloned in a GitHub action the main branch isn't +# available directly, even though `$GITHUB_BASE_REF` references it. +# So we need to fully qualify any symbolic revision name we are given. +function resolve_git_commit() { + local name=$1 + local commit + + local possible=( + "$name" + "origin/$name" + "remotes/origin/$name" + ) + + for rev in "${possible[@]}"; do + commit=$(git rev-parse --verify --quiet "$rev" || :) + + if [ -n "$commit" ]; then + break + fi + done + + if [ -z "$commit" ]; then + echo >&2 "ERROR: invalid revision: $name" + exit 1 + fi + + echo "$commit" +} diff --git a/scripts/authors.sh b/scripts/authors.sh index 571bb71..fec9cd4 100755 --- a/scripts/authors.sh +++ b/scripts/authors.sh @@ -5,10 +5,8 @@ set -eu set -o pipefail ################################################################################ -# Because GitHub runners don't set these: -export LANG=en_US.UTF-8 -export LC_ALL=$LANG -export LC_COLLATE=$LANG +script_dir=$(realpath "$(dirname "$0")") +source "$script_dir/../lib/ci-tools.sh" ################################################################################ option_from="HEAD^" @@ -32,48 +30,6 @@ NOTE: Must be exeucted from within a git repository. EOF } -################################################################################ -# Strip whitespace and delete blank lines from STDIN to STDOUT. -function strip_space() { - sed -E \ - -e 's/^[[:space:]]+//' \ - -e 's/[[:space:]]+$//' \ - -e 's/[[:space:]]+/ /' \ - -e '/^[[:space:]]*$/d' -} - -################################################################################ -# Resolve a `git` commit name given on the command line. -# -# When a repository is cloned in a GitHub action the main branch isn't -# available directly, even though `$GITHUB_BASE_REF` references it. -# So we need to fully qualify any symbolic revision name we are given. -function resolve_git_commit() { - local name=$1 - local commit - - local possible=( - "$name" - "origin/$name" - "remotes/origin/$name" - ) - - for rev in "${possible[@]}"; do - commit=$(git rev-parse --verify --quiet "$rev" || :) - - if [ -n "$commit" ]; then - break - fi - done - - if [ -z "$commit" ]; then - echo >&2 "ERROR: invalid revision: $name" - exit 1 - fi - - echo "$commit" -} - ################################################################################ # Ask `git` for a list of authors. function authors_from_git() { diff --git a/scripts/check-tool-handler.sh b/scripts/check-tool-handler.sh index b367725..0e98e39 100755 --- a/scripts/check-tool-handler.sh +++ b/scripts/check-tool-handler.sh @@ -4,6 +4,10 @@ set -eu set -o pipefail +################################################################################ +script_dir=$(realpath "$(dirname "$0")") +source "$script_dir/../lib/ci-tools.sh" + ################################################################################ declare -A topp_exceptions=( ["FeatureLinkerBase.cpp"]=1 @@ -60,7 +64,7 @@ function topp_files_in_map() { if [ "${topp_exceptions[$base]:-0}" -ne 1 ] && ! is_in_tools_map_cpp "$base"; then echo >&2 "ERROR: $base is not listed in $option_tool_handler_cpp" - exit 1 + exit 100 fi done < <(find "$option_topp_dir" -type f -name '*.cpp' -print0) } @@ -121,8 +125,8 @@ function main() { if [ $# -gt 0 ]; then if [ $# -eq 2 ]; then - option_from=$1 - option_to=$2 + option_from=$(resolve_git_commit "$1") + option_to=$(resolve_git_commit "$2") else echo >&2 "ERROR: provide exactly two commits" exit 1 From 0ac7f4b5324d0324838eddc4c28ea4c6234d1d84 Mon Sep 17 00:00:00 2001 From: "Peter J. Jones" Date: Fri, 17 Apr 2026 15:14:50 +0200 Subject: [PATCH 2/2] ci: Verify the shell scripts don't have obvious errors --- .github/workflows/test.yml | 12 ++++++++++++ .shellcheckrc | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 .shellcheckrc diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6c6d913 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,12 @@ +name: "Test" + +on: + pull_request: + +jobs: + shell-scripts: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: luizm/action-sh-checker@883217215b11c1fabbf00eb1a9a041f62d74c744 + env: { SHFMT_OPTS: -i 2 -d } diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..e546b5a --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,4 @@ +external-sources=true +check-sourced=true +source-path=lib +enable=avoid-nullary-conditions,check-unassigned-uppercase,deprecate-which,quote-safe-variables,useless-use-of-cat