Changesets · Branches · Tags · Compare
| Changeset | f326d567c4338f87402f4819e5bbf259f2e21a48fa761b33daf4457d235afa15 |
|---|---|
| Author | Ting-Wai <40179554+tingwai@users.noreply.github.com> · 2025-07-24 17:05 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-24 17:05 -07:00 |
| Parents | e3ae9dfc003a, ca9d977da515 |
1 file changed
modified scripts/oneper +42 −26
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | set -e |
| 3 | 3 | |
| 4 | 4 | # oneper - Install Continue VS Code extension from PR builds or latest pre-release |
| 5 | -# Usage: | |
| 5 | +# Usage: | |
| 6 | 6 | # oneper install --pr X - Install VSIX from PR number X |
| 7 | 7 | # oneper install --latest - Install latest pre-release from marketplace |
| 8 | 8 | |
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | echo "Commands:" |
| 19 | 19 | echo " install --pr <number> [--platform <platform>]" |
| 20 | 20 | echo " Download and install VSIX from specified PR number" |
| 21 | - echo " Platform options: macos, linux (default: macos)" | |
| 21 | + echo " Platform options: macos, linux (auto-detected by default)" | |
| 22 | 22 | echo " install --latest Install latest pre-release from VS Code marketplace" |
| 23 | 23 | echo " clean Remove all downloaded VSIX files from oneper cache" |
| 24 | 24 | echo "" |
| @@ -27,7 +27,7 @@ | ||
| 27 | 27 | echo " --platform <platform> Specify platform for PR builds (macos, linux)" |
| 28 | 28 | echo "" |
| 29 | 29 | echo "Examples:" |
| 30 | - echo " oneper install --pr 123 # Install macOS VSIX from PR #123" | |
| 30 | + echo " oneper install --pr 123 # Install VSIX from PR #123" | |
| 31 | 31 | echo " oneper install --pr 123 --platform linux # Install Linux VSIX from PR #123" |
| 32 | 32 | echo " oneper install --latest # Install latest pre-release" |
| 33 | 33 | echo " oneper clean # Clear cached VSIX files" |
| @@ -36,6 +36,22 @@ | ||
| 36 | 36 | echo "VSIX files are cached in: ~/.continue/.utils/oneper/" |
| 37 | 37 | } |
| 38 | 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 | + | |
| 39 | 55 | check_dependencies() { |
| 40 | 56 | if ! command -v gh &> /dev/null; then |
| 41 | 57 | echo "❌ GitHub CLI (gh) is required but not installed." |
| @@ -60,8 +76,8 @@ | ||
| 60 | 76 | |
| 61 | 77 | install_from_pr() { |
| 62 | 78 | local pr_number=$1 |
| 63 | - local platform=${2:-"macos"} # Default to macOS | |
| 64 | - | |
| 79 | + local platform=${2:-$(detect_os)} # Auto-detect OS if not specified | |
| 80 | + | |
| 65 | 81 | if [ -z "$pr_number" ]; then |
| 66 | 82 | echo "❌ PR number is required" |
| 67 | 83 | show_help |
| @@ -85,17 +101,17 @@ | ||
| 85 | 101 | esac |
| 86 | 102 | |
| 87 | 103 | echo "🔍 Getting branch name for PR #$pr_number..." |
| 88 | - | |
| 104 | + | |
| 89 | 105 | # First get the branch name for the PR |
| 90 | 106 | local branch_name=$(gh pr view "$pr_number" --repo "$REPO" --json headRefName --jq '.headRefName') |
| 91 | - | |
| 107 | + | |
| 92 | 108 | if [ -z "$branch_name" ]; then |
| 93 | 109 | echo "❌ Could not find PR #$pr_number" |
| 94 | 110 | exit 1 |
| 95 | 111 | fi |
| 96 | - | |
| 112 | + | |
| 97 | 113 | echo "🔍 Finding latest workflow run for branch: $branch_name..." |
| 98 | - | |
| 114 | + | |
| 99 | 115 | # Get the latest successful workflow run for the branch |
| 100 | 116 | local run_id=$(gh run list \ |
| 101 | 117 | --repo "$REPO" \ |
| @@ -104,7 +120,7 @@ | ||
| 104 | 120 | --json databaseId,status,conclusion \ |
| 105 | 121 | --jq ".[] | select(.status == \"completed\" and .conclusion == \"success\") | .databaseId" \ |
| 106 | 122 | | head -1) |
| 107 | - | |
| 123 | + | |
| 108 | 124 | if [ -z "$run_id" ]; then |
| 109 | 125 | echo "❌ No successful workflow run found for PR #$pr_number" |
| 110 | 126 | echo " Make sure the PR exists and has a successful CI run" |
| @@ -113,10 +129,10 @@ | ||
| 113 | 129 | |
| 114 | 130 | echo "✅ Found workflow run: $run_id" |
| 115 | 131 | echo "📥 Downloading vscode-extension-build-$artifact_suffix artifact..." |
| 116 | - | |
| 132 | + | |
| 117 | 133 | # Create temporary directory for download |
| 118 | 134 | local temp_dir=$(mktemp -d) |
| 119 | - | |
| 135 | + | |
| 120 | 136 | # Download the artifact |
| 121 | 137 | if ! gh run download "$run_id" \ |
| 122 | 138 | --repo "$REPO" \ |
| @@ -130,7 +146,7 @@ | ||
| 130 | 146 | |
| 131 | 147 | # Find the VSIX file in the downloaded artifact |
| 132 | 148 | local vsix_file=$(find "$temp_dir" -name "*.vsix" | head -1) |
| 133 | - | |
| 149 | + | |
| 134 | 150 | if [ -z "$vsix_file" ]; then |
| 135 | 151 | echo "❌ No VSIX file found in artifact" |
| 136 | 152 | rm -rf "$temp_dir" |
| @@ -140,7 +156,7 @@ | ||
| 140 | 156 | # Extract version from the original VSIX filename (e.g., continue-1.1.66.vsix -> 1.1.66) |
| 141 | 157 | local original_filename=$(basename "$vsix_file") |
| 142 | 158 | local version=$(echo "$original_filename" | sed 's/continue-\(.*\)\.vsix/\1/') |
| 143 | - | |
| 159 | + | |
| 144 | 160 | if [ -z "$version" ]; then |
| 145 | 161 | echo "⚠️ Could not extract version from filename: $original_filename" |
| 146 | 162 | version="unknown" |
| @@ -148,18 +164,18 @@ | ||
| 148 | 164 | |
| 149 | 165 | # Create new VSIX name with version and PR number |
| 150 | 166 | local target_path="$ONEPER_DIR/continue-${version}-${pr_number}.vsix" |
| 151 | - | |
| 167 | + | |
| 152 | 168 | # Check if file already exists and notify about overwrite |
| 153 | 169 | if [ -f "$target_path" ]; then |
| 154 | 170 | echo "⚠️ Overwriting existing VSIX: $target_path" |
| 155 | 171 | fi |
| 156 | - | |
| 172 | + | |
| 157 | 173 | echo "📦 Moving VSIX to: $target_path" |
| 158 | 174 | mv "$vsix_file" "$target_path" |
| 159 | - | |
| 175 | + | |
| 160 | 176 | # Clean up temp directory |
| 161 | 177 | rm -rf "$temp_dir" |
| 162 | - | |
| 178 | + | |
| 163 | 179 | # Install the extension |
| 164 | 180 | echo "🚀 Installing VS Code extension..." |
| 165 | 181 | if code --install-extension "$target_path"; then |
| @@ -196,17 +212,17 @@ | ||
| 196 | 212 | echo "📁 Oneper cache directory doesn't exist: $ONEPER_DIR" |
| 197 | 213 | return 0 |
| 198 | 214 | fi |
| 199 | - | |
| 215 | + | |
| 200 | 216 | local file_count=$(find "$ONEPER_DIR" -name "*.vsix" | wc -l | tr -d ' ') |
| 201 | - | |
| 217 | + | |
| 202 | 218 | if [ "$file_count" -eq 0 ]; then |
| 203 | 219 | echo "✨ Oneper cache is already empty" |
| 204 | 220 | return 0 |
| 205 | 221 | fi |
| 206 | - | |
| 222 | + | |
| 207 | 223 | echo "🧹 Removing $file_count VSIX file(s) from oneper cache..." |
| 208 | 224 | rm -f "$ONEPER_DIR"/*.vsix |
| 209 | - | |
| 225 | + | |
| 210 | 226 | echo "✅ Oneper cache cleared successfully" |
| 211 | 227 | echo "📁 Cache directory: $ONEPER_DIR" |
| 212 | 228 | } |
| @@ -234,13 +250,13 @@ | ||
| 234 | 250 | "--pr") |
| 235 | 251 | # Parse PR number and optional platform |
| 236 | 252 | local pr_number="$3" |
| 237 | - local platform="macos" # default | |
| 238 | - | |
| 239 | - # Check if --platform is specified | |
| 253 | + local platform=$(detect_os) # auto-detect OS | |
| 254 | + | |
| 255 | + # Check if --platform is specified to override auto-detection | |
| 240 | 256 | if [ "$4" = "--platform" ] && [ -n "$5" ]; then |
| 241 | 257 | platform="$5" |
| 242 | 258 | fi |
| 243 | - | |
| 259 | + | |
| 244 | 260 | install_from_pr "$pr_number" "$platform" |
| 245 | 261 | ;; |
| 246 | 262 | "--latest") |