Elffuss BraidHub

kikocis/continue public

Merge pull request #6787 from continuedev/tingwai/oneper-auto-pick-os

fix: oneper script to auto detect os
Changesetf326d567c4338f87402f4819e5bbf259f2e21a48fa761b33daf4457d235afa15
AuthorTing-Wai <40179554+tingwai@users.noreply.github.com> · 2025-07-24 17:05 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-24 17:05 -07:00
Parentse3ae9dfc003a, ca9d977da515

Browse the files at this changeset

1 file changed

modified scripts/oneper +42 −26
@@ -2,7 +2,7 @@
22 set -e
33
44 # oneper - Install Continue VS Code extension from PR builds or latest pre-release
5-# Usage:
5+# Usage:
66 # oneper install --pr X - Install VSIX from PR number X
77 # oneper install --latest - Install latest pre-release from marketplace
88
@@ -18,7 +18,7 @@
1818 echo "Commands:"
1919 echo " install --pr <number> [--platform <platform>]"
2020 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)"
2222 echo " install --latest Install latest pre-release from VS Code marketplace"
2323 echo " clean Remove all downloaded VSIX files from oneper cache"
2424 echo ""
@@ -27,7 +27,7 @@
2727 echo " --platform <platform> Specify platform for PR builds (macos, linux)"
2828 echo ""
2929 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"
3131 echo " oneper install --pr 123 --platform linux # Install Linux VSIX from PR #123"
3232 echo " oneper install --latest # Install latest pre-release"
3333 echo " oneper clean # Clear cached VSIX files"
@@ -36,6 +36,22 @@
3636 echo "VSIX files are cached in: ~/.continue/.utils/oneper/"
3737 }
3838
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+
3955 check_dependencies() {
4056 if ! command -v gh &> /dev/null; then
4157 echo "❌ GitHub CLI (gh) is required but not installed."
@@ -60,8 +76,8 @@
6076
6177 install_from_pr() {
6278 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+
6581 if [ -z "$pr_number" ]; then
6682 echo "❌ PR number is required"
6783 show_help
@@ -85,17 +101,17 @@
85101 esac
86102
87103 echo "🔍 Getting branch name for PR #$pr_number..."
88-
104+
89105 # First get the branch name for the PR
90106 local branch_name=$(gh pr view "$pr_number" --repo "$REPO" --json headRefName --jq '.headRefName')
91-
107+
92108 if [ -z "$branch_name" ]; then
93109 echo "❌ Could not find PR #$pr_number"
94110 exit 1
95111 fi
96-
112+
97113 echo "🔍 Finding latest workflow run for branch: $branch_name..."
98-
114+
99115 # Get the latest successful workflow run for the branch
100116 local run_id=$(gh run list \
101117 --repo "$REPO" \
@@ -104,7 +120,7 @@
104120 --json databaseId,status,conclusion \
105121 --jq ".[] | select(.status == \"completed\" and .conclusion == \"success\") | .databaseId" \
106122 | head -1)
107-
123+
108124 if [ -z "$run_id" ]; then
109125 echo "❌ No successful workflow run found for PR #$pr_number"
110126 echo " Make sure the PR exists and has a successful CI run"
@@ -113,10 +129,10 @@
113129
114130 echo "✅ Found workflow run: $run_id"
115131 echo "📥 Downloading vscode-extension-build-$artifact_suffix artifact..."
116-
132+
117133 # Create temporary directory for download
118134 local temp_dir=$(mktemp -d)
119-
135+
120136 # Download the artifact
121137 if ! gh run download "$run_id" \
122138 --repo "$REPO" \
@@ -130,7 +146,7 @@
130146
131147 # Find the VSIX file in the downloaded artifact
132148 local vsix_file=$(find "$temp_dir" -name "*.vsix" | head -1)
133-
149+
134150 if [ -z "$vsix_file" ]; then
135151 echo "❌ No VSIX file found in artifact"
136152 rm -rf "$temp_dir"
@@ -140,7 +156,7 @@
140156 # Extract version from the original VSIX filename (e.g., continue-1.1.66.vsix -> 1.1.66)
141157 local original_filename=$(basename "$vsix_file")
142158 local version=$(echo "$original_filename" | sed 's/continue-\(.*\)\.vsix/\1/')
143-
159+
144160 if [ -z "$version" ]; then
145161 echo "⚠️ Could not extract version from filename: $original_filename"
146162 version="unknown"
@@ -148,18 +164,18 @@
148164
149165 # Create new VSIX name with version and PR number
150166 local target_path="$ONEPER_DIR/continue-${version}-${pr_number}.vsix"
151-
167+
152168 # Check if file already exists and notify about overwrite
153169 if [ -f "$target_path" ]; then
154170 echo "⚠️ Overwriting existing VSIX: $target_path"
155171 fi
156-
172+
157173 echo "📦 Moving VSIX to: $target_path"
158174 mv "$vsix_file" "$target_path"
159-
175+
160176 # Clean up temp directory
161177 rm -rf "$temp_dir"
162-
178+
163179 # Install the extension
164180 echo "🚀 Installing VS Code extension..."
165181 if code --install-extension "$target_path"; then
@@ -196,17 +212,17 @@
196212 echo "📁 Oneper cache directory doesn't exist: $ONEPER_DIR"
197213 return 0
198214 fi
199-
215+
200216 local file_count=$(find "$ONEPER_DIR" -name "*.vsix" | wc -l | tr -d ' ')
201-
217+
202218 if [ "$file_count" -eq 0 ]; then
203219 echo "✨ Oneper cache is already empty"
204220 return 0
205221 fi
206-
222+
207223 echo "🧹 Removing $file_count VSIX file(s) from oneper cache..."
208224 rm -f "$ONEPER_DIR"/*.vsix
209-
225+
210226 echo "✅ Oneper cache cleared successfully"
211227 echo "📁 Cache directory: $ONEPER_DIR"
212228 }
@@ -234,13 +250,13 @@
234250 "--pr")
235251 # Parse PR number and optional platform
236252 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
240256 if [ "$4" = "--platform" ] && [ -n "$5" ]; then
241257 platform="$5"
242258 fi
243-
259+
244260 install_from_pr "$pr_number" "$platform"
245261 ;;
246262 "--latest")