Skip to content

Commit 65ab1ec

Browse files
committed
Update scripts
1 parent 6352e9f commit 65ab1ec

File tree

2 files changed

+58
-33
lines changed

2 files changed

+58
-33
lines changed

.github/workflows/ts-sdk.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
steps:
2020
- name: Checkout repo
2121
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
2224

2325
- name: Setup node
2426
uses: actions/setup-node@v4
@@ -42,4 +44,5 @@ jobs:
4244
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
4345
FERN_NPM_TOKEN: ${{ secrets.FERN_NPM_TOKEN }}
4446
run: |
47+
echo "Releasing SDK version: ${{ steps.bump.outputs.version }}"
4548
fern generate --group ts-sdk --version ${{ steps.bump.outputs.version }} --log-level debug

scripts/fern/bump.sh

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,28 @@
66
# Usage:
77
#
88
# $ ./scripts/bump.sh --from HEAD~1 --group ts-sdk
9+
910
set -uo pipefail
1011

11-
# The previous commit to compare against.
1212
FROM_COMMIT=""
13-
14-
# The group to use for version detection
1513
GROUP=""
1614

1715
log() {
18-
# Logs are written to stderr.
1916
echo "$@" >&2
2017
}
2118

19+
ensure_fern_cli() {
20+
if ! command -v fern &> /dev/null; then
21+
log "Installing Fern CLI..."
22+
if ! npm install -g fern-api@latest; then
23+
log "Failed to install Fern CLI"
24+
exit 1
25+
fi
26+
else
27+
log "Fern CLI is already installed"
28+
fi
29+
}
30+
2231
usage() {
2332
echo "Usage: $0 --from <commit> --group <group>"
2433
echo " --from Previous commit reference (e.g., HEAD~1, 8475a09)"
@@ -27,7 +36,6 @@ usage() {
2736
}
2837

2938
fern() {
30-
# Use the version of the fern CLI installed in the user's environment.
3139
FERN_NO_VERSION_REDIRECTION=true command fern "$@"
3240
}
3341

@@ -37,11 +45,9 @@ get_latest_version() {
3745

3846
case $group in
3947
ts-sdk)
40-
# Get latest version from npm
4148
version=$(npm view intercom-client version 2>/dev/null)
4249
;;
4350
java-sdk)
44-
# Get latest version from maven
4551
version=$(curl -s "https://repo1.maven.org/maven2/io/intercom/intercom-java/maven-metadata.xml" | grep -oP '<version>\K[^<]+' | sort -V | tail -n1)
4652
;;
4753
*)
@@ -82,65 +88,81 @@ if [[ -z "$FROM_COMMIT" || -z "$GROUP" ]]; then
8288
usage
8389
fi
8490

85-
# Get the latest version from the registry
91+
# Ensure Fern CLI is installed
92+
ensure_fern_cli
93+
94+
# Get working directory and reset temp dir
95+
WORK_DIR="$(git rev-parse --show-toplevel)"
96+
WORKTREE_DIR="$WORK_DIR/.tmp_worktree"
97+
rm -rf "$WORKTREE_DIR"
98+
99+
# Ensure the FROM_COMMIT exists
100+
log "Verifying that commit $FROM_COMMIT exists..."
101+
if ! git rev-parse "$FROM_COMMIT" &>/dev/null; then
102+
log "Commit $FROM_COMMIT not found. Did you fetch full history?"
103+
exit 1
104+
fi
105+
106+
# Get the latest version
86107
FROM_VERSION=$(get_latest_version "$GROUP")
87108
log "Using current version: $FROM_VERSION"
88109

110+
# Ensure cleanup on exit
89111
cleanup() {
90-
# Remove the temporary worktree, if any.
91-
if [[ -n "${WORKTREE_DIR:-}" ]] && [[ -d "$WORKTREE_DIR" ]]; then
112+
if [[ -d "$WORKTREE_DIR" ]]; then
92113
(cd "$WORKTREE_DIR" && git submodule deinit --all --force >/dev/null 2>&1 || true)
93114
git worktree remove --force "$WORKTREE_DIR" >/dev/null 2>&1 || true
94115
fi
95-
96-
# Remove the from.json and to.json files, if any.
97116
rm -f "$WORK_DIR/from.json" "$WORK_DIR/to.json" >/dev/null 2>&1
98-
99-
# Pop back to the user's original directory.
100-
popd >/dev/null 2>&1
117+
popd >/dev/null 2>&1 || true
101118
}
102-
103119
trap cleanup EXIT
104120

105-
# Step 0: Navigate to the fern root directory, if not already.
106-
WORK_DIR="$(git rev-parse --show-toplevel)"
107-
pushd "$WORK_DIR" >/dev/null 2>&1
121+
# Navigate to project root
122+
pushd "$WORK_DIR" >/dev/null
108123

109-
# Step 1: Generate IR from current commit.
124+
# Generate IR from current commit
110125
log "Generating IR from current commit..."
111126
fern ir to.json
112127

113-
# Step 2: Create worktree and generate IR from previous commit.
114-
WORKTREE_DIR=$(mktemp -d)
115-
log "Generating IR from previous commit..."
116-
git worktree add "$WORKTREE_DIR" "$FROM_COMMIT" >/dev/null 2>&1
128+
# Generate IR from previous commit in worktree
129+
log "Creating worktree in $WORKTREE_DIR..."
130+
if ! git worktree add "$WORKTREE_DIR" "$FROM_COMMIT"; then
131+
log "Failed to create worktree"
132+
exit 1
133+
fi
134+
117135
(
118136
cd "$WORKTREE_DIR" || {
119137
log "Cannot access worktree directory"
120138
exit 1
121139
}
122140

123-
# Initialize and update git submodules, if any.
124-
git submodule update --init --recursive >/dev/null 2>&1
141+
log "Updating submodules..."
142+
git submodule update --init --recursive
125143

144+
log "Running fern ir for previous commit..."
126145
fern ir from.json
146+
147+
if [ ! -f "from.json" ]; then
148+
log "from.json was not generated in worktree"
149+
exit 1
150+
fi
127151
)
128152

129-
# Step 3: Copy the from.json to the current working directory
153+
# Copy from.json back to root
154+
log "Copying from.json to working directory..."
130155
cp "$WORKTREE_DIR/from.json" "$WORK_DIR/from.json"
131156

132-
# Step 4: Run fern diff.
157+
# Diff and get next version
133158
log "Running fern diff..."
134159
DIFF_OUTPUT=$(fern diff --from from.json --to to.json --from-version "$FROM_VERSION")
135-
136-
# Debug: Print the full diff output
137160
log "Diff output: $DIFF_OUTPUT"
138161

139-
# Step 5: Extract next version using jq.
140162
NEXT_VERSION=$(echo "$DIFF_OUTPUT" | jq -r '.nextVersion')
141163

142-
if [[ -z "$NEXT_VERSION" ]]; then
143-
log "Could not determine next version from 'fern diff' output: $DIFF_OUTPUT"
164+
if [[ -z "$NEXT_VERSION" || "$NEXT_VERSION" == "null" ]]; then
165+
log "Could not determine next version from fern diff output"
144166
exit 1
145167
fi
146168

0 commit comments

Comments
 (0)