Skip to content

Commit a98d7ea

Browse files
authored
checkout-preview should also use sdk preview branch (#12)
1 parent 7a633ef commit a98d7ea

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,23 @@ When developing features in the main [hypeman](https://github.com/onkernel/hypem
8282
./scripts/checkout-preview -b preview/my-feature
8383
```
8484

85-
The script automatically adds the `stainless` remote if it doesn't exist.
85+
The script automatically adds the `stainless` remote if needed and also updates `go.mod` to point the `hypeman-go` SDK dependency to the corresponding preview branch in `stainless-sdks/hypeman-go`.
86+
87+
> **Warning:** The `go.mod` and `go.sum` changes from `checkout-preview` are for local testing only. Do not commit these changes.
8688
8789
After checking out a preview branch, you can build and test the CLI:
8890

8991
```bash
9092
go build -o hypeman ./cmd/hypeman
9193
./hypeman --help
9294
```
95+
96+
You can also point the SDK dependency independently:
97+
98+
```bash
99+
# Point hypeman-go to a specific branch
100+
./scripts/use-sdk-preview preview/my-feature
101+
102+
# Point to a specific commit
103+
./scripts/use-sdk-preview abc1234def567
104+
```

scripts/checkout-preview

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ git checkout -B "${BRANCH}" "stainless/${BRANCH}"
6565

6666
echo ""
6767
echo "Switched to branch '${BRANCH}' tracking stainless/${BRANCH}"
68+
69+
# Point the hypeman-go SDK dependency to the corresponding preview branch
70+
echo ""
71+
SCRIPT_DIR="$(dirname "$0")"
72+
"${SCRIPT_DIR}/use-sdk-preview" "${BRANCH}"

scripts/use-sdk-preview

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Point the onkernel/hypeman-go dependency to stainless-sdks/hypeman-go at a specific branch.
6+
#
7+
# Usage:
8+
# ./scripts/use-sdk-preview <branch-name>
9+
# ./scripts/use-sdk-preview <commit-hash>
10+
#
11+
# This modifies go.mod with a replace directive. Do not commit this change.
12+
13+
cd "$(dirname "$0")/.."
14+
15+
STAINLESS_SDK_REPO="github.com/stainless-sdks/hypeman-go"
16+
PUBLIC_SDK_REPO="github.com/onkernel/hypeman-go"
17+
18+
# Ensure the Go toolchain can access the private SDK repository.
19+
if [[ -z "${GOPRIVATE:-}" ]]; then
20+
export GOPRIVATE="$STAINLESS_SDK_REPO"
21+
elif [[ "$GOPRIVATE" != *"$STAINLESS_SDK_REPO"* ]]; then
22+
export GOPRIVATE="${GOPRIVATE},${STAINLESS_SDK_REPO}"
23+
fi
24+
25+
# Ensure git rewrites GitHub HTTPS URLs to SSH for private repo access.
26+
if ! git config --global --get-all url."[email protected]:".insteadOf | grep -q "https://github.com/"; then
27+
echo "Your git configuration is missing the rewrite from HTTPS to SSH for GitHub repositories." >&2
28+
echo "Run the following command and try again:" >&2
29+
echo " git config --global url.\"[email protected]:\".insteadOf \"https://github.com/\"" >&2
30+
exit 1
31+
fi
32+
33+
usage() {
34+
echo "Usage: $(basename "$0") <commit-hash|branch-name>" >&2
35+
echo "" >&2
36+
echo "Point the hypeman-go SDK dependency to stainless-sdks/hypeman-go at a specific ref." >&2
37+
echo "" >&2
38+
echo "Examples:" >&2
39+
echo " $(basename "$0") preview/devices # Use preview/devices branch" >&2
40+
echo " $(basename "$0") main # Use main branch" >&2
41+
echo " $(basename "$0") abc1234 # Use specific commit" >&2
42+
exit 1
43+
}
44+
45+
if [ "$#" -ne 1 ]; then
46+
usage
47+
fi
48+
49+
ref="$1"
50+
commit=""
51+
tmp_dir="/tmp/hypeman-go"
52+
53+
# Clone the stainless-sdks/hypeman-go repo (shallow clone for speed)
54+
rm -rf "$tmp_dir"
55+
echo "==> Cloning stainless-sdks/hypeman-go..."
56+
git clone --filter=blob:none --quiet [email protected]:stainless-sdks/hypeman-go "$tmp_dir"
57+
58+
# Determine the commit hash corresponding to the provided ref
59+
pushd "$tmp_dir" >/dev/null
60+
61+
# If the ref looks like a commit SHA (7-40 hex chars), use it directly; otherwise treat it as a branch
62+
if [[ "$ref" =~ ^[0-9a-f]{7,40}$ ]]; then
63+
commit="$ref"
64+
else
65+
# Fetch the branch and resolve its HEAD commit hash
66+
git fetch --depth=1 origin "$ref" >/dev/null 2>&1 || {
67+
echo "Error: failed to fetch branch '$ref' from stainless-sdks/hypeman-go." >&2
68+
popd >/dev/null
69+
exit 1
70+
}
71+
commit=$(git rev-parse FETCH_HEAD)
72+
fi
73+
74+
# Compute the Go pseudo-version for the resolved commit
75+
gomod_version=$(git show -s --abbrev=12 \
76+
--date=format:%Y%m%d%H%M%S \
77+
--format='v0.0.0-%cd-%h' "$commit")
78+
79+
popd >/dev/null
80+
81+
# Verify we're in the CLI module directory
82+
if [ ! -f go.mod ]; then
83+
echo "go.mod not found. Please run this script from the hypeman-cli repository root." >&2
84+
exit 1
85+
fi
86+
87+
echo "==> Updating go.mod to use stainless-sdks/hypeman-go @ $gomod_version..."
88+
89+
# Remove any existing replace directive for the SDK, then add the new one
90+
go mod edit -dropreplace="$PUBLIC_SDK_REPO" 2>/dev/null || true
91+
go mod edit -replace="$PUBLIC_SDK_REPO"="$STAINLESS_SDK_REPO"@"$gomod_version"
92+
go mod tidy
93+
94+
echo ""
95+
echo "go.mod updated to use $STAINLESS_SDK_REPO @ $gomod_version"
96+
echo ""
97+
echo "WARNING: Do not commit this change to go.mod/go.sum!"
98+

0 commit comments

Comments
 (0)