Skip to content
Closed
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
112 changes: 112 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Build and Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build-native:
strategy:
matrix:
include:
- os: ubuntu-latest
rid: linux-x64
- os: macos-latest
rid: osx-arm64
- os: windows-latest
rid: win-x64

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Build Tools (Windows)
if: matrix.os == 'windows-latest'
run: choco install make

- name: Cache Native Build
uses: actions/cache@v3
with:
path: tree-sitter/dist
key: native-${{ matrix.os }}-${{ hashFiles('tree-sitter/**/*.c', 'tree-sitter/**/*.h', 'tree-sitter/Makefile') }}
restore-keys: |
native-${{ matrix.os }}-

- name: Build Native Libraries
working-directory: tree-sitter
run: make clean && make all

- name: Copy Native Libraries
shell: bash
run: |
mkdir -p TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/
cp tree-sitter/dist/* TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/

- name: Upload Native Libraries
uses: actions/upload-artifact@v4
with:
name: native-${{ matrix.rid }}
path: TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/

build-dotnet:
needs: build-native
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.0.x'

- name: Download Native Libraries
uses: actions/download-artifact@v4
with:
pattern: native-*
path: TypeScriptParser.Native/runtimes/

- name: Cache NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj') }}
restore-keys: |
nuget-${{ runner.os }}-

- name: Generate Version
id: version
run: |
BASE_VERSION=$(grep '<Version>' Directory.Build.props | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/')
BUILD_NUMBER=${{ github.run_number }}
VERSION="${BASE_VERSION}.${BUILD_NUMBER}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT

- name: Restore Dependencies
run: dotnet restore

- name: Build Projects
run: dotnet build --no-restore --configuration Release -p:Version=${{ steps.version.outputs.version }}

- name: Run Unit Tests
run: dotnet test TypeScriptParser.Tests --no-build --configuration Release --logger trx --results-directory TestResults/

- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: TestResults/

- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
*/bin/Release/
*/obj/Release/
128 changes: 128 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Release to NuGet

on:
push:
tags:
- 'v*'

jobs:
build-native:
strategy:
matrix:
include:
- os: ubuntu-latest
rid: linux-x64
- os: macos-latest
rid: osx-arm64
- os: windows-latest
rid: win-x64

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Build Tools (Windows)
if: matrix.os == 'windows-latest'
run: choco install make

- name: Build Native Libraries
working-directory: tree-sitter
run: make clean && make all

- name: Copy Native Libraries
shell: bash
run: |
mkdir -p TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/
cp tree-sitter/dist/* TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/

- name: Upload Native Libraries
uses: actions/upload-artifact@v4
with:
name: native-${{ matrix.rid }}
path: TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/

release:
needs: build-native
runs-on: ubuntu-latest
environment: production

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.0.x'

- name: Parse Version from Tag
id: version
run: |
TAG=${GITHUB_REF#refs/tags/v}
echo "version=${TAG}" >> $GITHUB_OUTPUT

- name: Download Native Libraries
uses: actions/download-artifact@v4
with:
pattern: native-*
path: TypeScriptParser.Native/runtimes/

- name: Cache NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj') }}
restore-keys: |
nuget-${{ runner.os }}-

- name: Build .NET Projects
run: |
dotnet restore
dotnet build --configuration Release -p:Version=${{ steps.version.outputs.version }}

- name: Pack NuGet Packages
run: |
dotnet pack --no-build --configuration Release --output ./artifacts -p:Version=${{ steps.version.outputs.version }}

- name: Run Integration Tests
run: |
dotnet test TypeScriptParser.TestPackage --configuration Release --logger trx --results-directory TestResults/

- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: release-test-results
path: TestResults/

- name: Publish to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push ./artifacts/*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ steps.version.outputs.version }}
body: |
## TypeScript Parser v${{ steps.version.outputs.version }}

### 🚀 Features
- 跨平台Native库自动构建
- .NET 9.0 支持
- NuGet包自动发布

### 📦 NuGet包
- [TypeScriptParser v${{ steps.version.outputs.version }}](https://www.nuget.org/packages/TypeScriptParser/${{ steps.version.outputs.version }})
- [TypeScriptParser.Native v${{ steps.version.outputs.version }}](https://www.nuget.org/packages/TypeScriptParser.Native/${{ steps.version.outputs.version }})

### 🔧 安装方式
```bash
dotnet add package TypeScriptParser --version ${{ steps.version.outputs.version }}
```
draft: false
prerelease: false
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@
## 构建步骤

```bash
# 1. 恢复依赖
dotnet restore
# 1. 初始化子模块
git submodule update --init --recursive

# 2. 构建Native库
(cd tree-sitter && make clean && make all)

# 2. 构建项目
# 3. 恢复依赖和构建
dotnet restore
dotnet build -c Release

# 3. 运行测试
# 4. 运行测试
dotnet test --configuration Release --no-build

# 4. 打包NuGet包
# 5. 打包NuGet包
dotnet pack -c Release --no-build -o ./artifacts
```

## 开发构建
## 🔄 自动化发布

- **推送main分支** → 自动构建和测试
- **创建tag** → 自动发布到NuGet

```bash
# Debug模式构建和测试
dotnet build -c Debug
dotnet test --configuration Debug --no-build
git tag v1.2.0
git push origin v1.2.0
```

## 项目结构
Expand Down
4 changes: 2 additions & 2 deletions TypeScriptParser/TypeScriptParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<!-- Native库依赖 -->
<!-- Native库项目引用 -->
<ItemGroup>
<PackageReference Include="TypeScriptParser.Native" Version="$(Version)" />
<ProjectReference Include="../TypeScriptParser.Native/TypeScriptParser.Native.csproj" />
</ItemGroup>

</Project>
Empty file added artifacts/.gitkeep
Empty file.
Loading