Elffuss BraidHub

kikocis/continue public

e3ae9dfc003a · 8.3 KiB · executableRawPermalink
1#!/usr/bin/env bash
2set -e
3
4# oneper - Install Continue VS Code extension from PR builds or latest pre-release
5# Usage:
6# oneper install --pr X - Install VSIX from PR number X
7# oneper install --latest - Install latest pre-release from marketplace
8
9REPO="continuedev/continue"
10ONEPER_DIR="$HOME/.continue/.utils/oneper"
11
12show_help() {
13 echo "oneper - Install Continue VS Code extension from PR builds or latest pre-release"
14 echo ""
15 echo "Usage: oneper <command> [options]"
16 echo " oneper -h | --help"
17 echo ""
18 echo "Commands:"
19 echo " install --pr <number> [--platform <platform>]"
20 echo " Download and install VSIX from specified PR number"
21 echo " Platform options: macos, linux (default: macos)"
22 echo " install --latest Install latest pre-release from VS Code marketplace"
23 echo " clean Remove all downloaded VSIX files from oneper cache"
24 echo ""
25 echo "Options:"
26 echo " -h, --help Show this help message"
27 echo " --platform <platform> Specify platform for PR builds (macos, linux)"
28 echo ""
29 echo "Examples:"
30 echo " oneper install --pr 123 # Install macOS VSIX from PR #123"
31 echo " oneper install --pr 123 --platform linux # Install Linux VSIX from PR #123"
32 echo " oneper install --latest # Install latest pre-release"
33 echo " oneper clean # Clear cached VSIX files"
34 echo " oneper -h # Show help"
35 echo ""
36 echo "VSIX files are cached in: ~/.continue/.utils/oneper/"
37}
38
39check_dependencies() {
40 if ! command -v gh &> /dev/null; then
41 echo "❌ GitHub CLI (gh) is required but not installed."
42 echo " Install with: brew install gh"
43 exit 1
44 fi
45
46 if ! command -v code &> /dev/null; then
47 echo "❌ VS Code CLI (code) is required but not installed."
48 echo " Install VS Code and ensure 'code' command is in PATH"
49 exit 1
50 fi
51
52}
53
54ensure_oneper_dir() {
55 if [ ! -d "$ONEPER_DIR" ]; then
56 echo "📁 Creating oneper directory: $ONEPER_DIR"
57 mkdir -p "$ONEPER_DIR"
58 fi
59}
60
61install_from_pr() {
62 local pr_number=$1
63 local platform=${2:-"macos"} # Default to macOS
64
65 if [ -z "$pr_number" ]; then
66 echo "❌ PR number is required"
67 show_help
68 exit 1
69 fi
70
71 # Map platform names to GitHub runner OS names
72 local artifact_suffix
73 case "$platform" in
74 "macos")
75 artifact_suffix="macOS"
76 ;;
77 "linux")
78 artifact_suffix="Linux"
79 ;;
80 *)
81 echo "❌ Unknown platform: $platform"
82 echo " Supported platforms: macos, linux"
83 exit 1
84 ;;
85 esac
86
87 echo "🔍 Getting branch name for PR #$pr_number..."
88
89 # First get the branch name for the PR
90 local branch_name=$(gh pr view "$pr_number" --repo "$REPO" --json headRefName --jq '.headRefName')
91
92 if [ -z "$branch_name" ]; then
93 echo "❌ Could not find PR #$pr_number"
94 exit 1
95 fi
96
97 echo "🔍 Finding latest workflow run for branch: $branch_name..."
98
99 # Get the latest successful workflow run for the branch
100 local run_id=$(gh run list \
101 --repo "$REPO" \
102 --workflow="pr_checks.yaml" \
103 --branch="$branch_name" \
104 --json databaseId,status,conclusion \
105 --jq ".[] | select(.status == \"completed\" and .conclusion == \"success\") | .databaseId" \
106 | head -1)
107
108 if [ -z "$run_id" ]; then
109 echo "❌ No successful workflow run found for PR #$pr_number"
110 echo " Make sure the PR exists and has a successful CI run"
111 exit 1
112 fi
113
114 echo "✅ Found workflow run: $run_id"
115 echo "📥 Downloading vscode-extension-build-$artifact_suffix artifact..."
116
117 # Create temporary directory for download
118 local temp_dir=$(mktemp -d)
119
120 # Download the artifact
121 if ! gh run download "$run_id" \
122 --repo "$REPO" \
123 --name "vscode-extension-build-$artifact_suffix" \
124 --dir "$temp_dir"; then
125 echo "❌ Failed to download artifact vscode-extension-build-$artifact_suffix"
126 echo " Make sure the workflow run completed successfully for $platform"
127 rm -rf "$temp_dir"
128 exit 1
129 fi
130
131 # Find the VSIX file in the downloaded artifact
132 local vsix_file=$(find "$temp_dir" -name "*.vsix" | head -1)
133
134 if [ -z "$vsix_file" ]; then
135 echo "❌ No VSIX file found in artifact"
136 rm -rf "$temp_dir"
137 exit 1
138 fi
139
140 # Extract version from the original VSIX filename (e.g., continue-1.1.66.vsix -> 1.1.66)
141 local original_filename=$(basename "$vsix_file")
142 local version=$(echo "$original_filename" | sed 's/continue-\(.*\)\.vsix/\1/')
143
144 if [ -z "$version" ]; then
145 echo "⚠️ Could not extract version from filename: $original_filename"
146 version="unknown"
147 fi
148
149 # Create new VSIX name with version and PR number
150 local target_path="$ONEPER_DIR/continue-${version}-${pr_number}.vsix"
151
152 # Check if file already exists and notify about overwrite
153 if [ -f "$target_path" ]; then
154 echo "⚠️ Overwriting existing VSIX: $target_path"
155 fi
156
157 echo "📦 Moving VSIX to: $target_path"
158 mv "$vsix_file" "$target_path"
159
160 # Clean up temp directory
161 rm -rf "$temp_dir"
162
163 # Install the extension
164 echo "🚀 Installing VS Code extension..."
165 if code --install-extension "$target_path"; then
166 echo "✅ Successfully installed Continue extension from PR #$pr_number"
167 echo "📄 VSIX file saved to: $target_path"
168 echo ""
169 echo "💡 To use the new extension version, reload your VS Code window:"
170 echo " • Press Ctrl+Shift+P (Cmd+Shift+P on Mac)"
171 echo " • Type 'Developer: Reload Window' and press Enter"
172 echo " • Or restart VS Code entirely"
173 else
174 echo "❌ Failed to install extension"
175 exit 1
176 fi
177}
178
179install_latest() {
180 echo "🚀 Installing latest pre-release Continue extension..."
181 if code --install-extension --pre-release Continue.continue; then
182 echo "✅ Successfully installed latest pre-release Continue extension"
183 echo ""
184 echo "💡 To use the new extension version, reload your VS Code window:"
185 echo " • Press Ctrl+Shift+P (Cmd+Shift+P on Mac)"
186 echo " • Type 'Developer: Reload Window' and press Enter"
187 echo " • Or restart VS Code entirely"
188 else
189 echo "❌ Failed to install extension"
190 exit 1
191 fi
192}
193
194clean_cache() {
195 if [ ! -d "$ONEPER_DIR" ]; then
196 echo "📁 Oneper cache directory doesn't exist: $ONEPER_DIR"
197 return 0
198 fi
199
200 local file_count=$(find "$ONEPER_DIR" -name "*.vsix" | wc -l | tr -d ' ')
201
202 if [ "$file_count" -eq 0 ]; then
203 echo "✨ Oneper cache is already empty"
204 return 0
205 fi
206
207 echo "🧹 Removing $file_count VSIX file(s) from oneper cache..."
208 rm -f "$ONEPER_DIR"/*.vsix
209
210 echo "✅ Oneper cache cleared successfully"
211 echo "📁 Cache directory: $ONEPER_DIR"
212}
213
214main() {
215 if [ $# -eq 0 ]; then
216 show_help
217 exit 1
218 fi
219
220 # Handle help flags first
221 case "$1" in
222 "-h"|"--help")
223 show_help
224 exit 0
225 ;;
226 esac
227
228 check_dependencies
229 ensure_oneper_dir
230
231 case "$1" in
232 "install")
233 case "$2" in
234 "--pr")
235 # Parse PR number and optional platform
236 local pr_number="$3"
237 local platform="macos" # default
238
239 # Check if --platform is specified
240 if [ "$4" = "--platform" ] && [ -n "$5" ]; then
241 platform="$5"
242 fi
243
244 install_from_pr "$pr_number" "$platform"
245 ;;
246 "--latest")
247 install_latest
248 ;;
249 *)
250 echo "❌ Unknown install option: $2"
251 show_help
252 exit 1
253 ;;
254 esac
255 ;;
256 "clean")
257 clean_cache
258 ;;
259 *)
260 echo "❌ Unknown command: $1"
261 show_help
262 exit 1
263 ;;
264 esac
265}
266
267main "$@"