diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..8a3a383
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,183 @@
+name: CI/CD
+
+on:
+ pull_request:
+ branches: [ main ]
+ push:
+ tags: [ 'v*' ]
+
+jobs:
+ build-native:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ include:
+ - os: ubuntu-latest
+ rid: linux-x64
+ - os: macos-latest
+ rid: osx-arm64
+ - os: windows-latest
+ rid: win-x64
+
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ submodules: recursive
+
+ - name: Build Native Libraries
+ run: |
+ cd tree-sitter
+ make clean && make
+ shell: bash
+
+ - name: Copy Native Files
+ run: |
+ mkdir -p TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native
+ cp -r tree-sitter/dist/* TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/
+ echo "Files copied for ${{ matrix.rid }}:"
+ shell: bash
+
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: '9.0.x'
+
+ - name: Restore
+ run: dotnet restore
+
+ - name: Build
+ run: dotnet build -c Release --no-restore
+
+ - name: Debug Runtime Files Before Test
+ run: |
+ echo "=== Runtime files structure ==="
+ find ./TypeScriptParser.Native/runtimes/ -type f
+
+ echo "=== Test output directory before testing ==="
+ ls -la TypeScriptParser.Tests/bin/Release/net9.0/ || echo "Test output directory not found"
+ shell: bash
+
+ - name: Test
+ run: dotnet test -c Release --no-build
+
+ - name: Upload Native Artifacts
+ uses: actions/upload-artifact@v4
+ with:
+ name: native-${{ matrix.rid }}
+ path: TypeScriptParser.Native/runtimes/
+ retention-days: 1
+
+ pack-and-publish:
+ needs: build-native
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: '9.0.x'
+
+ - name: Download Native Artifacts
+ uses: actions/download-artifact@v4
+ with:
+ pattern: native-*
+ path: TypeScriptParser.Native/runtimes/
+ merge-multiple: true
+
+ - name: Set Version
+ run: |
+ if [[ $GITHUB_REF == refs/tags/v* ]]; then
+ TAG=${GITHUB_REF#refs/tags/v}
+ VERSION="${TAG}.${{ github.run_number }}"
+ else
+ VERSION="1.0.0-pr${{ github.event.number }}.${{ github.run_number }}"
+ fi
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
+
+ - name: Restore
+ run: dotnet restore
+
+ - name: Build
+ run: dotnet build -c Release -p:Version=$VERSION --no-restore
+
+ - name: Pack
+ run: dotnet pack -c Release -p:Version=$VERSION --no-build -o ./artifacts
+
+ - name: Upload Packages
+ uses: actions/upload-artifact@v4
+ with:
+ name: nuget-packages
+ path: artifacts/*.nupkg
+
+ package-test:
+ needs: pack-and-publish
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ include:
+ - os: ubuntu-latest
+ rid: linux-x64
+ - os: macos-latest
+ rid: osx-arm64
+ - os: windows-latest
+ rid: win-x64
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: '9.0.x'
+
+ - name: Download NuGet Packages
+ uses: actions/download-artifact@v4
+ with:
+ name: nuget-packages
+ path: ./artifacts
+
+ - name: Set Version
+ run: |
+ if [[ $GITHUB_REF == refs/tags/v* ]]; then
+ TAG=${GITHUB_REF#refs/tags/v}
+ VERSION="${TAG}.${{ github.run_number }}"
+ else
+ VERSION="1.0.0-pr${{ github.event.number }}.${{ github.run_number }}"
+ fi
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
+ shell: bash
+
+ - name: Restore Dependencies
+ run: dotnet restore TypeScriptParser.TestPackage/
+ shell: bash
+
+ - name: Update Package Reference
+ run: |
+ dotnet remove TypeScriptParser.TestPackage/TypeScriptParser.TestPackage.csproj package TypeScriptParser
+ dotnet add TypeScriptParser.TestPackage/TypeScriptParser.TestPackage.csproj package TypeScriptParser --version $VERSION --source ./artifacts
+ shell: bash
+
+ - name: Test Package
+ run: dotnet test TypeScriptParser.TestPackage/ -c Release
+ shell: bash
+
+ publish:
+ needs: package-test
+ runs-on: ubuntu-latest
+ if: startsWith(github.ref, 'refs/tags/v')
+
+ steps:
+ - name: Download NuGet Packages
+ uses: actions/download-artifact@v4
+ with:
+ name: nuget-packages
+ path: ./artifacts
+
+ - name: Publish to NuGet
+ run: |
+ dotnet nuget push artifacts/*.nupkg \
+ --api-key ${{ secrets.NUGET_API_KEY }} \
+ --source https://api.nuget.org/v3/index.json \
+ --skip-duplicate
\ No newline at end of file
diff --git a/Directory.Build.props b/Directory.Build.props
index 8717698..16d4d66 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,12 +1,12 @@
-
- 1.0.0
+
+ 0.0.1-dev
1.0.0
1.0.0
-
+
TypeScriptParser Team
TypeScriptParser
Copyright © $(Company) $([System.DateTime]::Now.Year)
@@ -14,12 +14,7 @@
https://github.com/your-org/csharp-tree-sitter
https://github.com/your-org/csharp-tree-sitter
git
-
-基于Tree-sitter的TypeScript解析器
-- 支持跨平台Native库自动管理
-- 零配置用户体验
-- 支持主流平台: Linux-x64, macOS-ARM64, Win-x64
-
+ 基于Tree-sitter的TypeScript解析器 - 支持跨平台Native库自动管理
latest
@@ -27,9 +22,4 @@
true
-
-
- debug
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 4bc156f..9f70615 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,36 @@ dotnet test --configuration Release --no-build
dotnet pack -c Release --no-build -o ./artifacts
```
+## 自动化构建
+
+### 开发流程
+1. 创建功能分支
+2. 提交Pull Request → 自动构建测试
+3. 合并到main分支
+
+### 发布流程
+1. 创建版本标签:`git tag v1.2.0 && git push origin v1.2.0`
+2. 自动构建测试发布到NuGet.org
+3. 版本号格式:`1.2.0.{构建号}`
+
+## 手动构建
+
+```bash
+# 1. 构建native库
+(cd tree-sitter/ && make clean && make)
+
+# 2. 复制运行时文件
+RID=$(dotnet --info | grep "RID:" | awk '{print $2}')
+mkdir -p TypeScriptParser.Native/runtimes/$RID/native
+cp -r tree-sitter/dist/* TypeScriptParser.Native/runtimes/$RID/native/
+
+# 3. .NET构建
+dotnet restore
+dotnet build -c Release
+dotnet test --configuration Release --no-build
+dotnet pack -c Release --no-build -o ./artifacts
+```
+
## 开发构建
```bash
diff --git a/TypeScriptParser.Native/build/TypeScriptParser.Native.props b/TypeScriptParser.Native/build/TypeScriptParser.Native.props
index 62a8acd..648a052 100644
--- a/TypeScriptParser.Native/build/TypeScriptParser.Native.props
+++ b/TypeScriptParser.Native/build/TypeScriptParser.Native.props
@@ -16,8 +16,7 @@
win-x64
win-x86
linux-x64
- osx-x64
- osx-arm64
+ osx-arm64
win-x64
diff --git a/TypeScriptParser.TestPackage/TypeScriptParser.TestPackage.csproj b/TypeScriptParser.TestPackage/TypeScriptParser.TestPackage.csproj
index 6f37c35..b8d1e63 100644
--- a/TypeScriptParser.TestPackage/TypeScriptParser.TestPackage.csproj
+++ b/TypeScriptParser.TestPackage/TypeScriptParser.TestPackage.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/artifacts/.gitkeep b/artifacts/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/tree-sitter/Makefile b/tree-sitter/Makefile
index 2f5386f..9d8f81a 100644
--- a/tree-sitter/Makefile
+++ b/tree-sitter/Makefile
@@ -18,14 +18,17 @@ ifeq ($(UNAME_S),Darwin)
endif
ifeq ($(OS),Windows_NT)
LIB_EXT=.dll
+ LIB_PREFIX=
+else
+ LIB_PREFIX=lib
endif
ifndef LIB_EXT
LIB_EXT=.so
endif
LIBS=\
- $(BIN)/libtree-sitter$(LIB_EXT) \
- $(BIN)/libtree-sitter-typescript$(LIB_EXT) \
+ $(BIN)/$(LIB_PREFIX)tree-sitter$(LIB_EXT) \
+ $(BIN)/$(LIB_PREFIX)tree-sitter-typescript$(LIB_EXT) \
all: dirs $(LIBS)
@@ -56,7 +59,7 @@ $(BIN)/tree-sitter.obj: \
-Itree-sitter/lib/src -Itree-sitter/lib/src/unicode \
-c tree-sitter/lib/src/lib.c
-$(BIN)/libtree-sitter$(LIB_EXT): $(BIN)/tree-sitter.obj
+$(BIN)/$(LIB_PREFIX)tree-sitter$(LIB_EXT): $(BIN)/tree-sitter.obj
gcc $(LFLAGS) $(CFLAGS) -o $@ $^
@@ -70,7 +73,7 @@ $(BIN)/tree-sitter-typescript-parser.obj: tree-sitter-typescript/typescript/src/
$(BIN)/tree-sitter-typescript-scanner.obj: tree-sitter-typescript/typescript/src/scanner.c
gcc $(CFLAGS) -o $@ -Itree-sitter-typescript/typescript/src -c $^
-$(BIN)/libtree-sitter-typescript$(LIB_EXT): $(BIN)/tree-sitter-typescript-parser.obj $(BIN)/tree-sitter-typescript-scanner.obj
+$(BIN)/$(LIB_PREFIX)tree-sitter-typescript$(LIB_EXT): $(BIN)/tree-sitter-typescript-parser.obj $(BIN)/tree-sitter-typescript-scanner.obj
gcc $(LFLAGS) $(CFLAGS) -o $@ $^
########