Skip to content

Commit 5858b72

Browse files
committed
github: run tests against custom cockroach Go
Add a script and a nightly target that runs tests with the custom Go runtime and the `cockroach_go` tag. The script is lifted from crlib.
1 parent ff0eb69 commit 5858b72

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

.github/workflows/nightlies.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,34 @@ jobs:
4949
sha: ${{ github.sha }}
5050
file_issue_branch: 'master'
5151
go_version: ${{ matrix.go }}
52+
53+
linux-cockroach-go:
54+
runs-on: ubuntu-latest
55+
env:
56+
GO_BRANCH: cockroach-go1.23.12
57+
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
# Step 1: Fetch the branch tip SHA for cache key
62+
- name: Get cockroachdb/go commit hash
63+
id: go-sha
64+
run: |
65+
SHA=$(git ls-remote https://github.com/cockroachdb/go.git refs/heads/$GO_BRANCH | cut -f1)
66+
echo "GO_SHA=$SHA" >> $GITHUB_ENV
67+
68+
# Step 2: Restore cache (per branch + commit SHA)
69+
- name: Cache custom Go toolchain
70+
uses: actions/cache@v4
71+
with:
72+
path: ~/.cache/cockroachdb-go/${{ env.GO_SHA }}
73+
key: cockroachdb-${{ env.GO_SHA }}
74+
75+
# Step 3: Install bootstrap Go (needed to build fork)
76+
- name: Install bootstrap Go
77+
uses: actions/setup-go@v5
78+
with:
79+
go-version: "1.23.x"
80+
81+
# Step 4: Run tests with custom Go
82+
- run: ./scripts/run-tests-with-custom-go.sh -tags invariants ./...
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
# run-tests-with-custom-go.sh
3+
#
4+
# Downloads and builds a custom Go toolchain from cockcroachdb/go (specific
5+
# branch), caches it in ~/.cache/cockcroachdb-go/<branch>/<sha>, and runs
6+
# `go test`.
7+
#
8+
# Works in GitHub Actions or when run manually.
9+
# In CI: pass GO_SHA to pin an exact commit.
10+
# Locally: if GO_SHA is unset, script fetches the latest branch tip.
11+
12+
set -euo pipefail
13+
14+
GO_REPO="https://github.com/cockroachdb/go.git"
15+
GO_SHA="${GO_SHA:-}"
16+
17+
if [ -z "$GO_SHA" ]; then
18+
GO_BRANCH="${GO_BRANCH:-cockroach-go1.23.12}"
19+
echo "==> Resolving latest SHA for branch $GO_BRANCH..."
20+
GO_SHA=$(git ls-remote "$GO_REPO" "refs/heads/$GO_BRANCH" | cut -f1)
21+
fi
22+
23+
# Use GITHUB_WORKSPACE if present (GitHub Actions), else current dir
24+
REPO_ROOT="${GITHUB_WORKSPACE:-$(pwd)}"
25+
26+
# Cache location (works locally and in CI)
27+
CACHE_BASE="${XDG_CACHE_HOME:-$HOME/.cache}/cockroachdb-go"
28+
CACHE_DIR="$CACHE_BASE/$GO_SHA"
29+
SRC_DIR="$CACHE_DIR/src"
30+
31+
echo "==> Commit SHA: $GO_SHA"
32+
echo "==> Repository root: $REPO_ROOT"
33+
echo "==> Cache directory: $CACHE_DIR"
34+
35+
if [ ! -x "$SRC_DIR/go/bin/go" ]; then
36+
echo "==> Building new Go toolchain..."
37+
mkdir -p "$SRC_DIR"
38+
rm -rf "$SRC_DIR/go" # in case of partial/incomplete build
39+
40+
git clone "$GO_REPO" "$SRC_DIR/go"
41+
cd "$SRC_DIR/go"
42+
git checkout "$GO_SHA"
43+
44+
cd "$SRC_DIR/go/src"
45+
./make.bash
46+
else
47+
echo "==> Reusing cached Go toolchain"
48+
fi
49+
50+
# Point environment to new Go
51+
export GOROOT="$SRC_DIR/go"
52+
export PATH="$GOROOT/bin:$PATH"
53+
54+
echo "==> Custom Go version:"
55+
go version
56+
57+
echo "==> Running tests in $REPO_ROOT"
58+
cd "$REPO_ROOT"
59+
echo go test -tags cockroach_go "$@"
60+
go test -tags cockroach_go "$@"

0 commit comments

Comments
 (0)