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