Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ permissions:
contents: read

jobs:
lint:
check-generated:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Expand All @@ -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:
Expand Down
81 changes: 72 additions & 9 deletions script/test.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
Loading