Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 4 additions & 14 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
<Project>

<PropertyGroup>
<!-- 版本信息 -->
<Version>1.0.0</Version>
<!-- 版本管理 -->
<Version Condition="'$(Version)' == ''">0.0.1-dev</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>

<!-- 共同的包信息 -->
<!-- 包信息 -->
<Authors>TypeScriptParser Team</Authors>
<Company>TypeScriptParser</Company>
<Copyright>Copyright © $(Company) $([System.DateTime]::Now.Year)</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/your-org/csharp-tree-sitter</PackageProjectUrl>
<RepositoryUrl>https://github.com/your-org/csharp-tree-sitter</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>
基于Tree-sitter的TypeScript解析器
- 支持跨平台Native库自动管理
- 零配置用户体验
- 支持主流平台: Linux-x64, macOS-ARM64, Win-x64
</PackageReleaseNotes>
<PackageReleaseNotes>基于Tree-sitter的TypeScript解析器 - 支持跨平台Native库自动管理</PackageReleaseNotes>

<!-- 构建配置 -->
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<!-- Debug版本后缀 -->
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<VersionSuffix Condition="'$(VersionSuffix)' == ''">debug</VersionSuffix>
</PropertyGroup>

</Project>
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions TypeScriptParser.Native/build/TypeScriptParser.Native.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<TypeScriptParserRuntimeIdentifier Condition="'$(TypeScriptParserRuntimeIdentifier)' == '' AND '$(PlatformTarget)' == 'x64' AND $([MSBuild]::IsOSPlatform('Windows'))">win-x64</TypeScriptParserRuntimeIdentifier>
<TypeScriptParserRuntimeIdentifier Condition="'$(TypeScriptParserRuntimeIdentifier)' == '' AND '$(PlatformTarget)' == 'x86' AND $([MSBuild]::IsOSPlatform('Windows'))">win-x86</TypeScriptParserRuntimeIdentifier>
<TypeScriptParserRuntimeIdentifier Condition="'$(TypeScriptParserRuntimeIdentifier)' == '' AND $([MSBuild]::IsOSPlatform('Linux'))">linux-x64</TypeScriptParserRuntimeIdentifier>
<TypeScriptParserRuntimeIdentifier Condition="'$(TypeScriptParserRuntimeIdentifier)' == '' AND $([MSBuild]::IsOSPlatform('OSX')) AND '$(RuntimeInformation.ProcessArchitecture)' != 'Arm64'">osx-x64</TypeScriptParserRuntimeIdentifier>
<TypeScriptParserRuntimeIdentifier Condition="'$(TypeScriptParserRuntimeIdentifier)' == '' AND $([MSBuild]::IsOSPlatform('OSX')) AND '$(RuntimeInformation.ProcessArchitecture)' == 'Arm64'">osx-arm64</TypeScriptParserRuntimeIdentifier>
<TypeScriptParserRuntimeIdentifier Condition="'$(TypeScriptParserRuntimeIdentifier)' == '' AND $([MSBuild]::IsOSPlatform('OSX'))">osx-arm64</TypeScriptParserRuntimeIdentifier>

<!-- 默认回退到win-x64 -->
<TypeScriptParserRuntimeIdentifier Condition="'$(TypeScriptParserRuntimeIdentifier)' == ''">win-x64</TypeScriptParserRuntimeIdentifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="TypeScriptParser" Version="1.0.0" />
<PackageReference Include="TypeScriptParser" Version="0.0.1-dev" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
Expand Down
Empty file added artifacts/.gitkeep
Empty file.
11 changes: 7 additions & 4 deletions tree-sitter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 $@ $^


Expand All @@ -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 $@ $^

########
Expand Down
Loading