From 207230ab032bd0801e0168f8872f8bff48d5ac7d Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Fri, 17 Apr 2026 11:16:33 -0400 Subject: [PATCH 1/2] chore: Improve GitHub Actions workflows lint and testing Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- .github/workflows/linter.yml | 20 ++++++++- script/test.sh | 81 ++++++++++++++++++++++++++++++++---- 2 files changed, 91 insertions(+), 10 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 0251ef37f69..eca48c9ef1c 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -5,7 +5,7 @@ permissions: contents: read jobs: - lint: + check-generated: runs-on: ubuntu-latest steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -15,10 +15,28 @@ jobs: cache-dependency-path: "**/go.sum" - name: Check generated code run: ./script/generate.sh --check + + golangci-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 + with: + go-version: stable + cache-dependency-path: "**/go.sum" - uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 with: version: v2.10.1 # sync with version in .custom-gcl.yml experimental: "automatic-module-directories" + + check-openapi: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 + with: + go-version: stable + cache-dependency-path: "**/go.sum" - name: Check OpenAPI run: ./script/metadata.sh update-openapi --validate env: diff --git a/script/test.sh b/script/test.sh index e195888bbb8..224397b2b91 100755 --- a/script/test.sh +++ b/script/test.sh @@ -1,8 +1,11 @@ #!/bin/sh -#/ script/test.sh runs tests on each go module in go-github. Arguments are passed to each go test invocation. +#/ script/test.sh runs tests on each go module in go-github in parallel. +#/ Arguments are passed to each go test invocation. #/ "-race -covermode atomic ./..." is used when no arguments are given. #/ #/ When UPDATE_GOLDEN is set, all directories named "golden" are removed before running tests. +#/ +#/ TEST_JOBS can be set to control parallelism (defaults to detected CPU count). set -e @@ -16,16 +19,76 @@ if [ -n "$UPDATE_GOLDEN" ]; then find . -name golden -type d -exec rm -rf {} + fi -MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" +MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort -u)" + +GREEN='\033[0;32m' +RED='\033[0;31m' +BOLD='\033[1m' +NC='\033[0m' + +EXIT_CODE=0 +FAILED_COUNT=0 +RUNNING=0 +PIDS="" +DIRS_IN_FLIGHT="" + +LOG_DIR="$(mktemp -d)" +trap 'rm -rf "$LOG_DIR"' EXIT + +: "${TEST_JOBS:=$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)}" + +print_header() { + printf "${BOLD}%s${NC}\n\n" "$1" +} + +wait_pids() { + i=1 + for pid in $PIDS; do + dir=$(echo "$DIRS_IN_FLIGHT" | awk -v i="$i" '{print $i}') + log_file="$LOG_DIR/$(echo "$dir" | tr '/' '_').log" + + if wait "$pid"; then + printf "${GREEN}✔ %-40s [ PASS ]${NC}\n" "$dir" + else + printf "${RED}✘ %-40s [ FAIL ]${NC}\n" "$dir" + if [ -f "$log_file" ]; then + sed 's/^/ /' "$log_file" + fi + FAILED_COUNT=$((FAILED_COUNT + 1)) + EXIT_CODE=1 + fi + i=$((i + 1)) + done + PIDS="" + DIRS_IN_FLIGHT="" + RUNNING=0 +} + +print_header "Testing modules" for dir in $MOD_DIRS; do - echo "testing $dir" - ( - cd "$dir" - go test "$@" - ) || FAILED=1 + log_file="$LOG_DIR/$(echo "$dir" | tr '/' '_').log" + + (cd "$dir" && go test "$@" > "$log_file" 2>&1) & + + PIDS="$PIDS $!" + DIRS_IN_FLIGHT="$DIRS_IN_FLIGHT $dir" + RUNNING=$((RUNNING + 1)) + + if [ "$RUNNING" -ge "$TEST_JOBS" ]; then + wait_pids + fi done -if [ -n "$FAILED" ]; then - exit 1 +wait_pids + +printf -- "----------------------------\n" +SUMMARY_COLOR="$GREEN" +if [ "$FAILED_COUNT" -gt 0 ]; then + SUMMARY_COLOR="$RED" fi + +printf "%bTesting: issues found in %d module directories.%b\n" "$SUMMARY_COLOR" "$FAILED_COUNT" "$NC" +printf -- "--------------------------------------------\n" + +exit "$EXIT_CODE" \ No newline at end of file From 3524e9af18f7c60ff4815c02be773bfd81608d6b Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Fri, 17 Apr 2026 11:20:52 -0400 Subject: [PATCH 2/2] Add trailing newline Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- script/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/test.sh b/script/test.sh index 224397b2b91..5d42097b90b 100755 --- a/script/test.sh +++ b/script/test.sh @@ -91,4 +91,4 @@ fi printf "%bTesting: issues found in %d module directories.%b\n" "$SUMMARY_COLOR" "$FAILED_COUNT" "$NC" printf -- "--------------------------------------------\n" -exit "$EXIT_CODE" \ No newline at end of file +exit "$EXIT_CODE"