Skip to main content

ci/ts: add a shortcut for testing Go packages

ID
488cb4f
date
2026-07-21 07:59:32+00:00
author
Alex Chan <alexc@tailscale.com>
parent
0236418
message
ci/ts: add a shortcut for testing Go packages
changed files
1 file, 22 additions, 1 deletion

Changed files

ci/ts (1741 → 2334)

diff --git a/ci/ts b/ci/ts
index 11a60ff..8b338c8 100755
--- a/ci/ts
+++ b/ci/ts
@@ -8,11 +8,32 @@ function run_python_tests() {
   
     pushd "$GIT_ROOT" >/dev/null
       # If there's a `scripts` folder with a test script, run that
-      if find "scripts" -name 'run_*_tests.sh' >/dev/null; then
+      if find "scripts" -name 'run_*_tests.sh' >/dev/null 2>&1; then
           print_info "-> bash scripts/run_*_tests.sh"
           bash scripts/run_*_tests.sh
           return 0
       fi
+      
+      # If there's a `go.mod` in the root, this is a Go project.
+      # Look for changed Go packages, and pass the list to `go test`.
+      if test -e go.mod; then
+        if test -e "./tool/go"; then
+          GO="./tool/go"
+        else
+          GO=$(which go)
+        fi
+        
+        CHANGED_PACKAGES=$(
+          git ls-files --modified \
+            | xargs dirname \
+            | uniq \
+            | xargs -I '{}' echo "./{}" \
+            | tr '\n' ' '
+        )
+        
+        print_info "$GO test $CHANGED_PACKAGES"
+        "$GO" test $CHANGED_PACKAGES
+      fi
     popd >/dev/null
   
     REPO_NAME="$(basename $(pwd))"