feature-open-with-vscode #4
@@ -7,17 +7,59 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: node:20-alpine
|
image: node:20-alpine
|
||||||
steps:
|
steps:
|
||||||
|
- name: 安装 Git
|
||||||
|
run: |
|
||||||
|
apk add --no-cache git
|
||||||
|
|
||||||
- name: 拉取代码
|
- name: 拉取代码
|
||||||
uses: https://devstar.cn/actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: 配置 Git
|
||||||
|
run: |
|
||||||
|
# 添加工作目录为安全目录
|
||||||
|
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.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
|||||||
|
|
||||||
|
- name: 自动递增版本号
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
run: |
|
||||||
|
apk add --no-cache jq
|
||||||
|
CURRENT_VERSION=$(jq -r '.version' package.json)
|
||||||
|
echo "当前版本: $CURRENT_VERSION"
|
||||||
|
|
||||||
|
# 分解版本号
|
||||||
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
|
||||||
|
|
||||||
|
# 递增补丁版本号
|
||||||
|
NEW_PATCH=$((PATCH + 1))
|
||||||
|
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
|
||||||
|
echo "新版本: $NEW_VERSION"
|
||||||
|
|
||||||
|
# 更新 package.json
|
||||||
|
jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp
|
||||||
|
mv package.json.tmp package.json
|
||||||
|
|
||||||
|
# 提交版本变更
|
||||||
|
git add package.json
|
||||||
|
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
|
||||||
|
git push
|
||||||
|
|
||||||
- name: 安装依赖
|
- name: 安装依赖
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
@@ -27,7 +69,7 @@ jobs:
|
|||||||
npm run package
|
npm run package
|
||||||
|
|
||||||
- name: 发布插件
|
- name: 发布插件
|
||||||
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
mengning
commented
目前main分支是保护分支不能直接push,所以这个CI脚本在线上应该不能运行 目前main分支是保护分支不能直接push,所以这个CI脚本在线上应该不能运行
|
|||||||
run: |
|
run: |
|
||||||
npm run publish
|
npm run publish
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "devstar",
|
"name": "devstar",
|
||||||
"displayName": "%displayName%",
|
"displayName": "%displayName%",
|
||||||
"description": "%description%",
|
"description": "%description%",
|
||||||
"version": "0.4.1",
|
"version": "0.4.3",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"publisher": "mengning",
|
"publisher": "mengning",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
40
src/home.ts
40
src/home.ts
@@ -79,7 +79,33 @@ export default class DSHome {
|
|||||||
async (message) => {
|
async (message) => {
|
||||||
const data = message.data;
|
const data = message.data;
|
||||||
const need_return = message.need_return;
|
const need_return = message.need_return;
|
||||||
if (!need_return) {
|
|
||||||
|
if (need_return) {
|
||||||
|
// 处理需要返回结果的消息
|
||||||
|
switch (message.command) {
|
||||||
|
case 'getUserToken':
|
||||||
|
panel.webview.postMessage({
|
||||||
|
command: 'getUserToken',
|
||||||
|
data: { userToken: this.user.getUserTokenFromLocal() }
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'getUsername':
|
||||||
|
panel.webview.postMessage({
|
||||||
|
command: 'getUsername',
|
||||||
|
data: { username: this.user.getUsernameFromLocal() }
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'getDevstarDomain':
|
||||||
|
panel.webview.postMessage({
|
||||||
|
command: 'getDevstarDomain',
|
||||||
|
data: { devstarDomain: this.devstarDomain }
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 处理不需要返回结果的消息
|
||||||
switch (message.command) {
|
switch (message.command) {
|
||||||
case 'openExternalUrl':
|
case 'openExternalUrl':
|
||||||
const url = message.url || (data && data.url);
|
const url = message.url || (data && data.url);
|
||||||
@@ -96,6 +122,18 @@ export default class DSHome {
|
|||||||
vscode.window.showErrorMessage('打开链接失败: 链接地址无效');
|
vscode.window.showErrorMessage('打开链接失败: 链接地址无效');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'showInformationNotification':
|
||||||
|
if (data && data.message) {
|
||||||
|
vscode.window.showInformationMessage(data.message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'showErrorNotification':
|
||||||
|
if (data && data.message) {
|
||||||
|
vscode.window.showErrorMessage(data.message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
32
src/main.ts
32
src/main.ts
@@ -66,31 +66,17 @@ export class DevStarExtension {
|
|||||||
const path = params.get('path');
|
const path = params.get('path');
|
||||||
const accessToken = params.get('access_token');
|
const accessToken = params.get('access_token');
|
||||||
const devstarUsername = params.get('devstar_username');
|
const devstarUsername = params.get('devstar_username');
|
||||||
const rawDevstarDomain = params.get('devstar_domain');
|
const devstarDomain = params.get('devstar_domain');
|
||||||
let devstarDomain = rawDevstarDomain;
|
const forwardPortsParam = params.get('forwardPorts');
|
||||||
if (rawDevstarDomain) {
|
|
||||||
try {
|
|
||||||
const url = new URL(rawDevstarDomain);
|
|
||||||
devstarDomain = `${url.protocol}//${url.hostname}`;
|
|
||||||
|
|
||||||
// 从 rawDevstarDomain 的查询参数中提取 forwardPorts
|
// 处理 forwardPorts 参数
|
||||||
const forwardPortsParam = url.searchParams.get('forwardPorts');
|
if (forwardPortsParam) {
|
||||||
if (forwardPortsParam) {
|
const ports = forwardPortsParam.split(',').map(port => parseInt(port, 10)).filter(port => !isNaN(port));
|
||||||
const ports = forwardPortsParam.split(',').map(port => parseInt(port, 10)).filter(port => !isNaN(port));
|
context.globalState.update('forwardPorts', ports);
|
||||||
console.log('解析到的 forwardPorts 参数:', ports);
|
} else {
|
||||||
context.globalState.update('forwardPorts', ports);
|
// 如果没有 forwardPorts 参数,清除 globalState 中的旧值
|
||||||
} else {
|
context.globalState.update('forwardPorts', undefined);
|
||||||
// 如果没有 forwardPorts 参数,清除 globalState 中的旧值
|
|
||||||
console.log('未找到 forwardPorts 参数,清除旧的 forwardPorts 配置');
|
|
||||||
context.globalState.update('forwardPorts', undefined);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Invalid devstar_domain URL:', error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
console.log('sanitized_devstar_domain:', devstarDomain);
|
|
||||||
|
|
||||||
// 使用修正后的 devstar_domain
|
|
||||||
if (devstarDomain) {
|
if (devstarDomain) {
|
||||||
this.user.setDevstarDomain(devstarDomain);
|
this.user.setDevstarDomain(devstarDomain);
|
||||||
this.remoteContainer.setUser(this.user);
|
this.remoteContainer.setUser(this.user);
|
||||||
|
|||||||
@@ -263,24 +263,32 @@ export default class RemoteContainer {
|
|||||||
`root@${hostname}`
|
`root@${hostname}`
|
||||||
];
|
];
|
||||||
|
|
||||||
const sshProcess = spawn('ssh', sshArgs);
|
// 使用 detached 选项让 SSH 进程独立运行,不随父进程退出
|
||||||
|
const sshProcess = spawn('ssh', sshArgs, {
|
||||||
|
detached: true, // 让进程在后台独立运行
|
||||||
|
stdio: 'ignore' // 忽略输入输出,避免进程挂起
|
||||||
|
});
|
||||||
|
|
||||||
|
// 解除父进程对子进程的引用,使其真正独立
|
||||||
|
sshProcess.unref();
|
||||||
|
|
||||||
sshProcess.on('error', (error: Error) => {
|
sshProcess.on('error', (error: Error) => {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
sshProcess.stdout.on('data', (_data: Buffer) => {
|
// 由于使用了 stdio: 'ignore',这些事件监听器不再需要
|
||||||
});
|
// sshProcess.stdout.on('data', (data: Buffer) => {
|
||||||
|
// console.log(`[SSH stdout] ${data.toString()}`);
|
||||||
|
// });
|
||||||
|
|
||||||
sshProcess.stderr.on('data', (_data: Buffer) => {
|
// sshProcess.stderr.on('data', (data: Buffer) => {
|
||||||
});
|
// console.error(`[SSH stderr] ${data.toString()}`);
|
||||||
|
// });
|
||||||
|
|
||||||
if (!this.sshProcesses) {
|
// 注意:由于进程已 detached 和 unref,不再需要保存到 sshProcesses Map
|
||||||
this.sshProcesses = new Map();
|
// 因为我们无法也不需要控制这些独立进程的生命周期
|
||||||
}
|
|
||||||
const key = `${hostname}:${sshPort}:${containerPort}`;
|
|
||||||
this.sshProcesses.set(key, sshProcess);
|
|
||||||
|
|
||||||
|
// 等待 SSH 连接建立
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve();
|
resolve();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
@@ -355,6 +363,7 @@ export default class RemoteContainer {
|
|||||||
async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext): Promise<void> {
|
async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const sshConfig = await this.getSSHConfig(host);
|
const sshConfig = await this.getSSHConfig(host);
|
||||||
|
|
||||||
if (sshConfig) {
|
if (sshConfig) {
|
||||||
try {
|
try {
|
||||||
// 调用 setupPortForwardingFromGlobalState 方法
|
// 调用 setupPortForwardingFromGlobalState 方法
|
||||||
|
|||||||
Reference in New Issue
Block a user
这里没有必要命名上使用github,应该使用devstar吧