-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbump.sh
More file actions
executable file
·169 lines (140 loc) · 3.94 KB
/
bump.sh
File metadata and controls
executable file
·169 lines (140 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
#
# Bumps the version of the SDK by comparing the current API
# against a snapshot of the API from a previous commit.
#
# Usage:
#
# $ ./scripts/bump.sh --from HEAD~1 --group ts-sdk
set -uo pipefail
FROM_COMMIT=""
GROUP=""
log() {
echo "$@" >&2
}
ensure_fern_cli() {
if ! command -v fern &> /dev/null; then
log "Installing Fern CLI..."
if ! npm install -g fern-api@latest; then
log "Failed to install Fern CLI"
exit 1
fi
else
log "Fern CLI is already installed"
fi
}
usage() {
echo "Usage: $0 --from <commit> --group <group>"
echo " --from Previous commit reference (e.g., HEAD~1, 8475a09)"
echo " --group Group to use for version detection (e.g., ts-sdk, java-sdk)"
exit 1
}
fern() {
FERN_NO_VERSION_REDIRECTION=true command fern "$@"
}
get_latest_version() {
local group=$1
local version=""
case $group in
ts-sdk)
version=$(npm view intercom-client version 2>/dev/null)
;;
java-sdk)
version=$(curl -s "https://repo1.maven.org/maven2/io/intercom/intercom-java/maven-metadata.xml" | grep -oP '<version>\K[^<]+' | sort -V | tail -n1)
;;
*)
log "Unknown group: $group"
exit 1
;;
esac
if [[ -z "$version" ]]; then
log "Could not determine latest version for group $group"
exit 1
fi
echo "$version"
}
while [[ $# -gt 0 ]]; do
case $1 in
--from)
FROM_COMMIT="$2"
shift 2
;;
--group)
GROUP="$2"
shift 2
;;
-h|--help)
usage
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done
if [[ -z "$FROM_COMMIT" || -z "$GROUP" ]]; then
usage
fi
# Ensure Fern CLI is installed
ensure_fern_cli
# Get working directory and reset temp dir
WORK_DIR="$(git rev-parse --show-toplevel)"
WORKTREE_DIR="$WORK_DIR/.tmp_worktree"
rm -rf "$WORKTREE_DIR"
# Ensure the FROM_COMMIT exists
log "Verifying that commit $FROM_COMMIT exists..."
if ! git rev-parse "$FROM_COMMIT" &>/dev/null; then
log "Commit $FROM_COMMIT not found. Did you fetch full history?"
exit 1
fi
# Get the latest version
FROM_VERSION=$(get_latest_version "$GROUP")
log "Using current version: $FROM_VERSION"
# Ensure cleanup on exit
cleanup() {
if [[ -d "$WORKTREE_DIR" ]]; then
(cd "$WORKTREE_DIR" && git submodule deinit --all --force >/dev/null 2>&1 || true)
git worktree remove --force "$WORKTREE_DIR" >/dev/null 2>&1 || true
fi
rm -f "$WORK_DIR/from.json" "$WORK_DIR/to.json" >/dev/null 2>&1
popd >/dev/null 2>&1 || true
}
trap cleanup EXIT
# Navigate to project root
pushd "$WORK_DIR" >/dev/null
# Generate IR from current commit
log "Generating IR from current commit..."
fern ir to.json
# Generate IR from previous commit in worktree
log "Creating worktree in $WORKTREE_DIR..."
if ! git worktree add "$WORKTREE_DIR" "$FROM_COMMIT"; then
log "Failed to create worktree"
exit 1
fi
(
cd "$WORKTREE_DIR" || {
log "Cannot access worktree directory"
exit 1
}
log "Updating submodules..."
git submodule update --init --recursive
log "Running fern ir for previous commit..."
fern ir from.json
if [ ! -f "from.json" ]; then
log "from.json was not generated in worktree"
exit 1
fi
)
# Copy from.json back to root
log "Copying from.json to working directory..."
cp "$WORKTREE_DIR/from.json" "$WORK_DIR/from.json"
# Diff and get next version
log "Running fern diff..."
DIFF_OUTPUT=$(fern diff --from from.json --to to.json --from-version "$FROM_VERSION")
log "Diff output: $DIFF_OUTPUT"
NEXT_VERSION=$(echo "$DIFF_OUTPUT" | jq -r '.nextVersion')
if [[ -z "$NEXT_VERSION" || "$NEXT_VERSION" == "null" ]]; then
log "Could not determine next version from fern diff output"
exit 1
fi
echo "$NEXT_VERSION"