修复远程终端识别本地操作系统问题并完善工作流配置 #7

Merged
shizi merged 12 commits from fix-bug into main 2026-01-14 08:05:13 +00:00
5 changed files with 95 additions and 97 deletions

View File

@@ -13,12 +13,15 @@
"warn", "warn",
{ {
"selector": "import", "selector": "import",
"format": [ "camelCase", "PascalCase" ] "format": [
"camelCase",
"PascalCase"
]
} }
], ],
"@typescript-eslint/semi": "warn", "@typescript-eslint/semi": "off",
"curly": "warn", "curly": "warn",
"eqeqeq": "warn", "eqeqeq": "off",
"no-throw-literal": "warn", "no-throw-literal": "warn",
"semi": "off" "semi": "off"
}, },

View File

@@ -23,8 +23,8 @@ jobs:
- name: 拉取代码 - name: 拉取代码
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.head_ref }}
- name: 配置 Git - name: 配置 Git
run: | run: |
@@ -33,32 +33,51 @@ jobs:
git config --global --add safe.directory /github/workspace git config --global --add safe.directory /github/workspace
# 配置用户信息 # 配置用户信息
git config --global user.name "github-actions[bot]" git config --global user.name "devstar"
git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.email "devstar@noreply.devstar.cn"
- name: 自动递增版本号 - name: Check and bump version
if: github.event_name == 'push' && github.ref == 'refs/heads/main' if: github.event_name == 'pull_request'
run: | run: |
apk add --no-cache jq apk add --no-cache jq
CURRENT_VERSION=$(jq -r '.version' package.json) # 获取远程 main 分支版本
echo "当前版本: $CURRENT_VERSION" git fetch origin main
MAIN_VERSION=$(git show origin/main:package.json | jq -r '.version')
PR_VERSION=$(jq -r '.version' package.json)
#版本 echo "Main版本: $MAIN_VERSION"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" echo "当前 PR 版本: $PR_VERSION"
# 递增补丁版本号 # 如果版本号相同,则递增
NEW_PATCH=$((PATCH + 1)) if [ "$MAIN_VERSION" = "$PR_VERSION" ]; then
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" echo "版本号未变更,开始递增..."
echo "新版本: $NEW_VERSION"
# 分解版本号
# 更新 package.json MAJOR=$(echo "$PR_VERSION" | cut -d'.' -f1)
jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp MINOR=$(echo "$PR_VERSION" | cut -d'.' -f2)
mv package.json.tmp package.json PATCH=$(echo "$PR_VERSION" | cut -d'.' -f3)
# 提交版本变更 # 递增补丁版本号
git add package.json NEW_PATCH=$((PATCH + 1))
git commit -m "chore: bump version to $NEW_VERSION [skip ci]" NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
git push echo "新版本: $NEW_VERSION"
# 更新 package.json
jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp
mv package.json.tmp package.json
# 提交版本变更
git config user.name "devstar-actions"
git config user.email "devstar-actions@devstar.cn"
git add package.json
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
# 推送到当前分支
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
git push origin $BRANCH_NAME || git push origin HEAD:refs/heads/$BRANCH_NAME
else
echo "版本号已更新,跳过递增"
fi
- name: 安装依赖 - name: 安装依赖
run: | run: |
@@ -73,4 +92,4 @@ jobs:
run: | run: |
npm run publish npm run publish
env: env:
VSCE_PAT: ${{ secrets.VSCE_PAT }} VSCE_PAT: ${{ secrets.VSCE_PAT }}

View File

@@ -2,7 +2,7 @@
"name": "devstar", "name": "devstar",
"displayName": "%displayName%", "displayName": "%displayName%",
"description": "%description%", "description": "%description%",
"version": "0.4.3", "version": "0.5.3",
"keywords": [], "keywords": [],
"publisher": "mengning", "publisher": "mengning",
"engines": { "engines": {
@@ -42,6 +42,10 @@
{ {
"protocol": "vscode", "protocol": "vscode",
"path": "/openProject" "path": "/openProject"
},
{
"protocol": "trae",
"path": "/openProject"
} }
], ],
"views": { "views": {

View File

@@ -25,6 +25,46 @@ export default class RemoteContainer {
this.user = user; this.user = user;
} }
/**
* 构建打开项目的命令
* 根据终端类型生成对应的命令
* 支持 Windows PowerShell/CMD 和 Linux/macOS Bash/Zsh
*/
private buildOpenProjectCommand(
host: string,
hostname: string,
port: number,
username: string,
path: string,
devstarDomain: string | undefined,
terminal: vscode.Terminal
): string {
const baseUrl = `vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}`;
const url = devstarDomain ? `${baseUrl}&devstar_domain=${devstarDomain}` : baseUrl;
// 获取本地操作系统类型
// 在远程环境下os.platform() 返回的是远程系统,但这里我们需要的是本地系统
// 所以通过终端的 shell 路径来推断
const shellPath = (terminal.creationOptions as any)?.shellPath || '';
console.log('终端 shell 路径:', shellPath);
// 检测 WindowsWindows shell 路径包含反斜杠或特定关键字)
const isWindows = shellPath.includes('\\') ||
shellPath.toLowerCase().includes('powershell') ||
shellPath.toLowerCase().includes('pwsh') ||
shellPath.toLowerCase().includes('cmd');
if (isWindows) {
// Windows PowerShell/CMD: 使用分号分隔URL 需要特殊的引号处理
console.log('检测到 Windows 本地系统,使用 PowerShell/CMD 语法');
return `code --new-window; code --open-url '"${url}"'`;
} else {
// macOS/Linux: 使用 && 分隔,标准双引号
console.log('检测到 Unix 本地系统macOS/Linux使用 Bash/Zsh 语法');
return `code --new-window && code --open-url "${url}"`;
}
}
/** /**
* 第一次打开远程项目 * 第一次打开远程项目
*/ */
@@ -40,29 +80,8 @@ export default class RemoteContainer {
devstarDomain = undefined; devstarDomain = undefined;
} }
const semver = require('semver'); // 根据终端类型生成对应的命令
const powershellVersion = context.globalState.get('powershellVersion'); const command = this.buildOpenProjectCommand(host, hostname, port, username, path, devstarDomain, terminal);
const powershell_semver_compatible_version = semver.coerce(powershellVersion);
let command = '';
if (devstarDomain === undefined) {
if (powershellVersion === undefined) {
command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`;
} else if (semver.satisfies(powershell_semver_compatible_version, ">=5.1.26100")) {
command = `code --new-window ; code --% --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`;
} else {
command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`;
}
} else {
if (powershellVersion === undefined) {
command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`;
} else if (semver.satisfies(powershell_semver_compatible_version, ">=5.1.26100")) {
command = `code --new-window ; code --% --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`;
} else {
command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`;
}
}
terminal.sendText(command); terminal.sendText(command);
} else { } else {
vscode.window.showErrorMessage('无法创建终端,请检查终端是否可用。'); vscode.window.showErrorMessage('无法创建终端,请检查终端是否可用。');
@@ -276,18 +295,6 @@ export default class RemoteContainer {
reject(error); reject(error);
}); });
// 由于使用了 stdio: 'ignore',这些事件监听器不再需要
// sshProcess.stdout.on('data', (data: Buffer) => {
// console.log(`[SSH stdout] ${data.toString()}`);
// });
// sshProcess.stderr.on('data', (data: Buffer) => {
// console.error(`[SSH stderr] ${data.toString()}`);
// });
// 注意:由于进程已 detached 和 unref不再需要保存到 sshProcesses Map
// 因为我们无法也不需要控制这些独立进程的生命周期
// 等待 SSH 连接建立 // 等待 SSH 连接建立
setTimeout(() => { setTimeout(() => {
resolve(); resolve();

View File

@@ -1,12 +1,7 @@
import * as http from 'http';
import * as https from 'https';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as os from 'os'; import * as os from 'os';
import { exec } from 'child_process'; import { exec } from 'child_process';
const {
generateKeyPairSync,
} = require('node:crypto')
const axios = require('axios'); const axios = require('axios');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
@@ -23,36 +18,6 @@ export function isMacOS(): boolean {
return os.platform() === 'darwin'; return os.platform() === 'darwin';
} }
export function fetch(url: string): Promise<string> {
// determine the library to use (based on the url protocol)
const lib = url.startsWith('https://') ? https : http;
return new Promise((resolve, reject) => {
lib.get(url, (response) => {
// make sure the status code is 200
if (response.statusCode !== 200) {
reject(new Error(`Failed to load page, status code: ${response.statusCode}`));
return;
}
let data = '';
response.on('data', (chunk) => {
data += chunk;
});
response.on('end', () => {
resolve(data);
});
}).on('error', (err) => {
reject(err);
});
});
}
export const Sleep = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms))
}
export async function getVsCodeCommitId(): Promise<string> { export async function getVsCodeCommitId(): Promise<string> {
if (isLinux() || isMacOS()) { if (isLinux() || isMacOS()) {
return new Promise<string>((resolve) => { return new Promise<string>((resolve) => {