From 9567929cfb3f5a3c21202f3893328278bf585fd7 Mon Sep 17 00:00:00 2001 From: s97712 Date: Sat, 23 Aug 2025 22:26:09 +0800 Subject: [PATCH 1/4] Update build process to include tree-sitter submodule and add automated release workflow - Add git submodule initialization step for tree-sitter - Include native library build step using make - Add automated CI/CD workflow documentation - Reorganize build steps with clearer numbering - Document tag-based release process --- .github/workflows/build.yml | 111 +++++++++++++++++++++++++++++ .github/workflows/release.yml | 129 ++++++++++++++++++++++++++++++++++ README.md | 24 ++++--- 3 files changed, 255 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..68ded0f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,111 @@ +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@v3 + 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@v3 + with: + 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 '' Directory.Build.props | sed 's/.*\(.*\)<\/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@v3 + if: always() + with: + name: test-results + path: TestResults/ + + - name: Upload Build Artifacts + uses: actions/upload-artifact@v3 + with: + name: build-artifacts + path: | + */bin/Release/ + */obj/Release/ \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3bda310 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,129 @@ +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@v3 + 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@v3 + with: + 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@v3 + 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: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_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 \ No newline at end of file diff --git a/README.md b/README.md index 7445a28..9a7c31d 100644 --- a/README.md +++ b/README.md @@ -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 ``` ## 项目结构 From ce96178d4c5585df263007e66a7925634f42e612 Mon Sep 17 00:00:00 2001 From: s97712 Date: Sat, 23 Aug 2025 22:37:53 +0800 Subject: [PATCH 2/4] Update GitHub Actions to use latest artifact actions - Upgrade upload-artifact and download-artifact from v3 to v4 - Add pattern parameter to download-artifact for better filtering - Replace deprecated create-release action with softprops/action-gh-release@v2 - Update release creation parameters for new action compatibility --- .github/workflows/build.yml | 9 +++++---- .github/workflows/release.yml | 15 +++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68ded0f..d024910 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,7 @@ jobs: cp tree-sitter/dist/* TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/ - name: Upload Native Libraries - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: native-${{ matrix.rid }} path: TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/ @@ -66,8 +66,9 @@ jobs: dotnet-version: '9.0.x' - name: Download Native Libraries - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: + pattern: native-* path: TypeScriptParser.Native/runtimes/ - name: Cache NuGet packages @@ -96,14 +97,14 @@ jobs: run: dotnet test TypeScriptParser.Tests --no-build --configuration Release --logger trx --results-directory TestResults/ - name: Upload Test Results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: always() with: name: test-results path: TestResults/ - name: Upload Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: build-artifacts path: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3bda310..058c421 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,7 +39,7 @@ jobs: cp tree-sitter/dist/* TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/ - name: Upload Native Libraries - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: native-${{ matrix.rid }} path: TypeScriptParser.Native/runtimes/${{ matrix.rid }}/native/ @@ -64,8 +64,9 @@ jobs: echo "version=${TAG}" >> $GITHUB_OUTPUT - name: Download Native Libraries - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: + pattern: native-* path: TypeScriptParser.Native/runtimes/ - name: Cache NuGet packages @@ -90,7 +91,7 @@ jobs: dotnet test TypeScriptParser.TestPackage --configuration Release --logger trx --results-directory TestResults/ - name: Upload Test Results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: always() with: name: release-test-results @@ -103,12 +104,10 @@ jobs: 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: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v2 with: - tag_name: ${{ github.ref }} - release_name: Release ${{ steps.version.outputs.version }} + tag_name: ${{ github.ref_name }} + name: Release ${{ steps.version.outputs.version }} body: | ## TypeScript Parser v${{ steps.version.outputs.version }} From 359dd35f8492fea46b7ad6236bbb80727cd474c3 Mon Sep 17 00:00:00 2001 From: s97712 Date: Sat, 23 Aug 2025 22:54:58 +0800 Subject: [PATCH 3/4] Replace package reference with project reference for TypeScriptParser.Native Switch from NuGet package dependency to direct project reference for better development workflow and build integration. --- TypeScriptParser/TypeScriptParser.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TypeScriptParser/TypeScriptParser.csproj b/TypeScriptParser/TypeScriptParser.csproj index 7bfe759..12650d2 100644 --- a/TypeScriptParser/TypeScriptParser.csproj +++ b/TypeScriptParser/TypeScriptParser.csproj @@ -10,9 +10,9 @@ $(NoWarn);CS1591 - + - + From 53791967d88aa9d4255a82e713760a520e8933e7 Mon Sep 17 00:00:00 2001 From: s97712 Date: Sat, 23 Aug 2025 23:48:34 +0800 Subject: [PATCH 4/4] Add artifacts directory --- artifacts/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 artifacts/.gitkeep diff --git a/artifacts/.gitkeep b/artifacts/.gitkeep new file mode 100644 index 0000000..e69de29