-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate-package.sh
More file actions
executable file
·173 lines (150 loc) · 6.68 KB
/
update-package.sh
File metadata and controls
executable file
·173 lines (150 loc) · 6.68 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
170
171
172
173
#!/bin/bash
# Script to update the forge npm package with new binary versions
# Exit on any error, undefined variable, or pipe failure
set -euo pipefail
# Enable debug mode if DEBUG is set
if [ "${DEBUG:-}" = "true" ]; then
set -x
fi
VERSION=$1
if [ -z "$VERSION" ]; then
echo "Usage: ./update-package.sh <version>"
echo ""
echo "Environment variables:"
echo " NPM_TOKEN - If set, publishes the package to npm"
echo " AUTO_PUSH - If set to 'true', automatically pushes changes without confirmation (recommended for CI)"
echo " CI - If set to 'true', ensures the script runs in non-interactive mode"
echo " DEBUG - If set to 'true', enables bash debug mode (set -x)"
exit 1
fi
# Set CI mode if running in CI environment
if [ "${CI:-}" = "true" ]; then
export AUTO_PUSH="true"
echo "CI environment detected, enabling AUTO_PUSH"
fi
# Update version in package.json
echo "Updating package.json version to $VERSION..."
npm version $VERSION --no-git-tag-version --allow-same-version || {
echo "ERROR: Failed to update npm version" >&2
exit 1
}
# Create bin directories if they don't exist
mkdir -p bin/darwin/arm64
mkdir -p bin/darwin/x64
mkdir -p bin/linux/arm64
mkdir -p bin/linux/x64
mkdir -p bin/win32/arm64
mkdir -p bin/win32/x64
mkdir -p bin/android/arm64
# Download binaries from GitHub release
echo "Downloading binaries for version $VERSION..."
# Function to download with proper error handling
download_binary() {
local url="$1"
local output="$2"
echo "Downloading ${output}..."
curl -L -f -S --retry 3 "$url" -o "$output" || {
echo "ERROR: Failed to download $url" >&2
return 1
}
echo "✓ Downloaded $output"
}
# macOS
download_binary "https://github.com/antinomyhq/forge/releases/download/$VERSION/forge-aarch64-apple-darwin" "bin/darwin/arm64/forge-aarch64-apple-darwin"
download_binary "https://github.com/antinomyhq/forge/releases/download/$VERSION/forge-x86_64-apple-darwin" "bin/darwin/x64/forge-x86_64-apple-darwin"
# Linux (glibc)
download_binary "https://github.com/antinomyhq/forge/releases/download/$VERSION/forge-aarch64-unknown-linux-gnu" "bin/linux/arm64/forge-aarch64-unknown-linux-gnu"
download_binary "https://github.com/antinomyhq/forge/releases/download/$VERSION/forge-x86_64-unknown-linux-gnu" "bin/linux/x64/forge-x86_64-unknown-linux-gnu"
# Linux (musl)
download_binary "https://github.com/antinomyhq/forge/releases/download/$VERSION/forge-aarch64-unknown-linux-musl" "bin/linux/arm64/forge-aarch64-unknown-linux-musl" || echo "Warning: musl variant for ARM64 not available"
download_binary "https://github.com/antinomyhq/forge/releases/download/$VERSION/forge-x86_64-unknown-linux-musl" "bin/linux/x64/forge-x86_64-unknown-linux-musl" || echo "Warning: musl variant for x64 not available"
# Windows
download_binary "https://github.com/antinomyhq/forge/releases/download/$VERSION/forge-aarch64-pc-windows-msvc.exe" "bin/win32/arm64/forge-aarch64-pc-windows-msvc.exe"
download_binary "https://github.com/antinomyhq/forge/releases/download/$VERSION/forge-x86_64-pc-windows-msvc.exe" "bin/win32/x64/forge-x86_64-pc-windows-msvc.exe"
# Android
download_binary "https://github.com/antinomyhq/forge/releases/download/$VERSION/forge-aarch64-linux-android" "bin/android/arm64/forge-aarch64-linux-android"
# Make binaries executable
chmod +x bin/darwin/arm64/forge-aarch64-apple-darwin
chmod +x bin/darwin/arm64/forge-aarch64-linux-android
chmod +x bin/darwin/x64/forge-x86_64-apple-darwin
chmod +x bin/linux/arm64/forge-aarch64-unknown-linux-gnu
chmod +x bin/linux/x64/forge-x86_64-unknown-linux-gnu
# Make Android binaries executable
chmod +x bin/android/arm64/forge-aarch64-linux-android
# Make musl binaries executable if they exist
if [ -f bin/linux/arm64/forge-aarch64-unknown-linux-musl ]; then
chmod +x bin/linux/arm64/forge-aarch64-unknown-linux-musl
fi
if [ -f bin/linux/x64/forge-x86_64-unknown-linux-musl ]; then
chmod +x bin/linux/x64/forge-x86_64-unknown-linux-musl
fi
echo "Binaries downloaded and prepared for npm package"
# Publish to npm if NPM_TOKEN is available
if [ -n "${NPM_TOKEN:-}" ]; then
echo "Publishing to npm..."
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
npm publish --access public || {
echo "ERROR: Failed to publish to npm" >&2
rm -f .npmrc
exit 1
}
rm -f .npmrc
echo "✓ Package published to npm"
else
echo "NPM_TOKEN not set, skipping publish"
fi
# Configure git for CI if needed
if [ "${CI:-}" = "true" ]; then
# Setup git identity for CI
git config --global user.name "CI Bot" || echo "Warning: Could not set git user name"
git config --global user.email "ci@example.com" || echo "Warning: Could not set git user email"
# Disable interactive prompts
git config --global core.editor "cat"
fi
# Commit changes and push to git
echo "Committing changes to git..."
git add package.json bin/ || { echo "ERROR: Failed to stage files for commit" >&2; exit 1; }
git commit -m "Update package to version $VERSION" || { echo "ERROR: Failed to commit changes" >&2; exit 1; }
git tag -a "v$VERSION" -m "Release v$VERSION" || { echo "ERROR: Failed to create tag" >&2; exit 1; }
# Determine current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) || {
echo "ERROR: Failed to determine current branch" >&2
exit 1
}
# Check if we should automatically push (useful for CI/CD)
if [ "${AUTO_PUSH:-}" == "true" ]; then
echo "AUTO_PUSH is enabled. Pushing changes to origin/$CURRENT_BRANCH..."
git push origin "$CURRENT_BRANCH" || {
echo "ERROR: Failed to push commits to origin/$CURRENT_BRANCH" >&2
exit 1
}
git push origin --tags || {
echo "ERROR: Failed to push tags to origin" >&2
exit 1
}
echo "✓ Changes committed and pushed to git"
else
# Ask for confirmation before pushing (only in interactive mode)
if [ "${CI:-}" = "true" ]; then
echo "CI environment detected but AUTO_PUSH not enabled. Skipping push."
echo "Changes committed locally. Remember to push manually."
else
read -p "Push changes to origin/$CURRENT_BRANCH? (y/n): " PUSH_CONFIRM
if [ "$PUSH_CONFIRM" == "y" ] || [ "$PUSH_CONFIRM" == "Y" ]; then
echo "Pushing changes to origin/$CURRENT_BRANCH..."
git push origin "$CURRENT_BRANCH" || {
echo "ERROR: Failed to push commits to origin/$CURRENT_BRANCH" >&2
exit 1
}
git push origin --tags || {
echo "ERROR: Failed to push tags to origin" >&2
exit 1
}
echo "✓ Changes committed and pushed to git"
else
echo "Changes committed locally. Use git push when ready."
fi
fi
fi
echo "✓ All operations completed successfully for version $VERSION"
exit 0