Skip to content

Commit e4e97f1

Browse files
authored
ci: 重构 GitHub Actions 工作流 (#15)
* ci: 重构 GitHub Actions 工作流 - 新增 pnpm-cache.yml 工作流,用于设置 pnpm 缓存 - 更新 CI、nightly、pr-check 等工作流,使用新的 pnpm 缓存设置 - 优化工作流中的步骤,减少重复代码 - 更新 release-please 配置,移除不必要的设置 - 新增 .release-please-config.json 文件,详细配置 release-please * ci: 重构 GitHub Actions 工作流 - 新增 build-test.yml、code-quality.yml 和 setup.yml 工作流文件 - 重构 ci.yml、nightly.yml 和 pr-check.yml,使用新的工作流文件 - 移除 env.yml 和 pnpm-cache.yml 工作流文件 - 更新工作流调用,使用新的输入参数和输出值 * ci: 重构 GitHub Actions 工作流 - 移除各工作流中的重复 setup 步骤 - 新增单独的 setup 工作流,统一处理环境配置 - 更新工作流之间的依赖关系,确保按顺序执行 - 为发布到 Marketplace 添加新的工作流 * ci: 重构 GitHub Actions 工作流 - 在 build-test.yml 和 code-quality.yml 中添加 setup 作业 - 使用 workflow_call 方式调用 setup.yml - 优化工作流结构,提高可维护性 * ci: 重构 GitHub Actions 工作流 - 新增 Setup Node.js and pnpm 复合操作,用于统一配置 Node.js 和 pnpm - 更新所有工作流文件,使用新的 Setup Node.js and pnpm 复合操作 - 移除单独的 setup 任务,直接在每个工作流中配置环境 - 优化工作流结构,提高可维护性和可读性
1 parent 0a4a033 commit e4e97f1

File tree

13 files changed

+323
-423
lines changed

13 files changed

+323
-423
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Setup Node.js and pnpm'
2+
description: 'Setup Node.js, pnpm, and install dependencies'
3+
4+
inputs:
5+
node_version:
6+
description: 'Node.js version'
7+
required: false
8+
default: '22.13.0'
9+
pnpm_version:
10+
description: 'pnpm version'
11+
required: false
12+
default: '9.15.0'
13+
14+
outputs:
15+
store_path:
16+
description: 'pnpm store path'
17+
value: ${{ steps.get-store-path.outputs.STORE_PATH }}
18+
19+
runs:
20+
using: 'composite'
21+
steps:
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ inputs.node_version }}
26+
27+
- name: Setup pnpm
28+
uses: pnpm/action-setup@v4
29+
with:
30+
version: ${{ inputs.pnpm_version }}
31+
32+
- name: Get pnpm store directory
33+
id: get-store-path
34+
shell: bash
35+
run: |
36+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
37+
38+
- name: Setup pnpm cache
39+
uses: actions/cache@v4
40+
with:
41+
path: ${{ steps.get-store-path.outputs.STORE_PATH }}
42+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
43+
restore-keys: |
44+
${{ runner.os }}-pnpm-store-
45+
46+
- name: Install dependencies
47+
shell: bash
48+
run: pnpm install --frozen-lockfile

.github/workflows/build-test.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Build and Test
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
test_matrix:
7+
required: false
8+
type: string
9+
default: '["ubuntu-latest"]' # 默认只在ubuntu上测试以节省资源
10+
outputs:
11+
vsix_file:
12+
value: ${{ jobs.build-test.outputs.vsix_file }}
13+
14+
jobs:
15+
build-test:
16+
name: Build and Test
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: ${{ fromJSON(inputs.test_matrix) }}
21+
outputs:
22+
vsix_file: ${{ steps.verify-vsix.outputs.vsix_file }}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Node.js and pnpm
28+
uses: ./.github/actions/setup-node-pnpm
29+
30+
- name: Compile
31+
run: pnpm run compile
32+
33+
- name: Run tests
34+
run: pnpm run test
35+
36+
- name: Package extension
37+
run: pnpm run package:vsix
38+
39+
- name: Verify VSIX on Linux/macOS
40+
if: runner.os != 'Windows'
41+
id: verify-vsix
42+
shell: bash
43+
run: |
44+
set -e
45+
VSIX_FILE=$(ls *.vsix 2>/dev/null || true)
46+
if [ -z "$VSIX_FILE" ]; then
47+
echo "❌ VSIX file not found"
48+
exit 1
49+
fi
50+
51+
echo "✅ VSIX file created: $VSIX_FILE"
52+
ls -lh $VSIX_FILE
53+
echo "vsix_file=$VSIX_FILE" >> $GITHUB_OUTPUT
54+
55+
- name: Verify VSIX on Windows
56+
if: runner.os == 'Windows'
57+
id: verify-vsix-win
58+
shell: pwsh
59+
run: |
60+
$vsix = Get-ChildItem -Filter *.vsix
61+
if (-not $vsix) {
62+
Write-Error "❌ VSIX file not found"
63+
exit 1
64+
}
65+
Write-Host "✅ VSIX file created: $($vsix.Name)"
66+
Get-ChildItem *.vsix | Format-List
67+
echo "vsix_file=$($vsix.Name)" >> $env:GITHUB_OUTPUT

.github/workflows/ci.yml

Lines changed: 21 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,108 +2,39 @@ name: CI
22

33
on:
44
pull_request:
5-
branches: [ main, master ]
5+
branches: [main, master]
66
push:
7-
branches: [ main, master ]
7+
branches: [main, master]
88

99
jobs:
10-
get-env:
11-
uses: ./.github/workflows/env.yml
10+
code-quality:
11+
name: Code Quality
12+
uses: ./.github/workflows/code-quality.yml
1213

1314
test:
1415
name: Test
15-
runs-on: ${{ matrix.os }}
16-
needs: get-env
17-
18-
strategy:
19-
matrix:
20-
os: [ubuntu-latest, windows-latest, macos-latest]
21-
22-
steps:
23-
24-
- name: Checkout
25-
uses: actions/checkout@v4
26-
27-
- name: Setup Node.js ${{ needs.get-env.outputs.node_version }}
28-
uses: actions/setup-node@v4
29-
with:
30-
node-version: ${{ needs.get-env.outputs.node_version }}
31-
32-
- name: Setup pnpm
33-
uses: pnpm/action-setup@v4
34-
with:
35-
version: ${{ needs.get-env.outputs.pnpm_version }}
36-
37-
- name: Get pnpm store directory
38-
shell: bash
39-
run: |
40-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
41-
42-
- name: Setup pnpm cache
43-
uses: actions/cache@v4
44-
with:
45-
path: ${{ env.STORE_PATH }}
46-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
47-
restore-keys: |
48-
${{ runner.os }}-pnpm-store-
49-
50-
- name: Install dependencies
51-
run: pnpm install --frozen-lockfile
52-
53-
- name: Check types
54-
run: pnpm run check-types
55-
56-
- name: Lint
57-
run: pnpm run lint
58-
59-
- name: Compile
60-
run: pnpm run compile
61-
62-
- name: Run tests
63-
run: pnpm run test
64-
65-
- name: Package extension
66-
run: pnpm run package:vsix
67-
68-
- name: Upload build artifacts
69-
uses: actions/upload-artifact@v4
70-
with:
71-
name: vscode-syncing-${{ matrix.os }}-${{ needs.get-env.outputs.node_version }}
72-
path: |
73-
*.vsix
74-
dist/
75-
retention-days: 7
16+
uses: ./.github/workflows/build-test.yml
17+
with:
18+
test_matrix: '["ubuntu-latest", "windows-latest", "macos-latest"]'
19+
secrets: inherit
7620

7721
security:
7822
name: Security Check
7923
runs-on: ubuntu-latest
80-
needs: get-env
8124
if: github.event_name == 'pull_request'
82-
8325
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
8428

85-
- name: Checkout
86-
uses: actions/checkout@v4
87-
88-
- name: Setup Node.js
89-
uses: actions/setup-node@v4
90-
with:
91-
node-version: ${{ needs.get-env.outputs.node_version }}
92-
93-
- name: Setup pnpm
94-
uses: pnpm/action-setup@v4
95-
with:
96-
version: ${{ needs.get-env.outputs.pnpm_version }}
97-
98-
- name: Install dependencies
99-
run: pnpm install --frozen-lockfile
29+
- name: Setup Node.js and pnpm
30+
uses: ./.github/actions/setup-node-pnpm
10031

101-
- name: Run security audit
102-
run: pnpm audit --audit-level moderate
32+
- name: Run security audit
33+
run: pnpm audit --audit-level moderate
10334

104-
- name: Check for secrets
105-
uses: trufflesecurity/trufflehog@main
106-
with:
107-
path: .
108-
base: ${{ github.event.pull_request.base.sha }}
109-
head: ${{ github.event.pull_request.head.sha }}
35+
- name: Check for secrets
36+
uses: trufflesecurity/trufflehog@main
37+
with:
38+
path: .
39+
base: ${{ github.event.pull_request.base.sha }}
40+
head: ${{ github.event.pull_request.head.sha }}

.github/workflows/code-quality.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Code Quality
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
code-quality:
8+
name: Code Quality
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Node.js and pnpm
15+
uses: ./.github/actions/setup-node-pnpm
16+
17+
- name: Check types
18+
run: pnpm run check-types
19+
20+
- name: Lint
21+
run: pnpm run lint
22+
23+
- name: Check package.json
24+
run: |
25+
# 检查package.json格式
26+
node -e "JSON.parse(require('fs').readFileSync('package.json', 'utf8'))"
27+
echo "✅ package.json is valid JSON"
28+
29+
- name: Check for console.log statements
30+
run: |
31+
if grep -r "console\.log" src/; then
32+
echo "❌ Found console.log statements in source code"
33+
exit 1
34+
else
35+
echo "✅ No console.log statements found"
36+
fi
37+
38+
- name: Check for TODO comments
39+
run: |
40+
if grep -r "TODO" src/; then
41+
echo "⚠️ Found TODO comments in source code"
42+
else
43+
echo "✅ No TODO comments found"
44+
fi
45+
46+
- name: Check file sizes
47+
run: |
48+
echo "📊 Checking file sizes..."
49+
find src/ -name "*.ts" -exec wc -l {} + | sort -nr | head -10

.github/workflows/env.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/github-release.yml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,25 @@ name: GitHub Release
33
on:
44
push:
55
tags:
6-
- "v*"
6+
- 'v*'
77
workflow_dispatch:
88
inputs:
99
tag_name:
10-
description: "Tag name to use for the release"
10+
description: 'Tag name to use for the release'
1111
required: false
1212

1313
jobs:
14-
get-env:
15-
uses: ./.github/workflows/env.yml
16-
1714
release:
1815
name: GitHub Release
1916
runs-on: ubuntu-latest
20-
needs: get-env
2117
outputs:
2218
version: ${{ steps.version.outputs.version }}
23-
2419
steps:
2520
- name: Checkout
2621
uses: actions/checkout@v4
2722

28-
- name: Setup Node.js
29-
uses: actions/setup-node@v4
30-
with:
31-
node-version: ${{ needs.get-env.outputs.node_version }}
32-
33-
- name: Setup pnpm
34-
uses: pnpm/action-setup@v4
35-
with:
36-
version: ${{ needs.get-env.outputs.pnpm_version }}
37-
38-
- name: Install dependencies
39-
run: pnpm install --frozen-lockfile
23+
- name: Setup Node.js and pnpm
24+
uses: ./.github/actions/setup-node-pnpm
4025

4126
- name: Compile
4227
run: pnpm run compile
@@ -56,7 +41,7 @@ jobs:
5641
- name: Upload Release
5742
uses: ncipollo/release-action@v1
5843
with:
59-
artifacts: "*.vsix"
44+
artifacts: '*.vsix'
6045
token: ${{ secrets.GITHUB_TOKEN }}
6146
tag: ${{ steps.version.outputs.version }}
6247
name: Release ${{ steps.version.outputs.version }}

0 commit comments

Comments
 (0)