Skip to content

测试发布

测试发布 #12

Workflow file for this run

name: Build and Publish NuGet Package
on:
push:
branches: [ main, master ]
paths:
- 'src/**'
- '.github/workflows/**'
pull_request:
branches: [ main, master ]
paths:
- 'src/**'
env:
DOTNET_VERSION: '8.0.x'
PROJECT_PATH: 'src/CodeInject/CodeInject.csproj'
SOURCE_GENERATOR_PATH: 'src/CodeInjectSourceGenerator/CodeInjectSourceGenerator.csproj'
jobs:
build-and-test:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore CodeRegion.slnx
- name: Build Source Generator
run: dotnet build ${{ env.SOURCE_GENERATOR_PATH }} --configuration Release --no-restore --framework netstandard2.0
- name: Build project
run: dotnet build ${{ env.PROJECT_PATH }} --configuration Release --no-restore --framework netstandard2.0
- name: Run tests (if any)
run: dotnet test src/ --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage"
continue-on-error: true
- name: Pack NuGet package
run: dotnet pack ${{ env.PROJECT_PATH }} --configuration Release --no-build --output ./packages
- name: List packages for debugging
run: Get-ChildItem -Path "./packages" -Recurse
- name: Upload NuGet package as artifact
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: ./packages/*.nupkg
publish-nuget:
needs: build-and-test
runs-on: windows-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Download NuGet package artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
path: ./packages
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Verify packages exist
run: |
if (-not (Test-Path "./packages/*.nupkg")) {
Write-Error "No .nupkg files found in ./packages directory"
Get-ChildItem -Path "./packages" -Recurse
exit 1
}
Write-Host "Found packages:"
Get-ChildItem -Path "./packages" -Filter "*.nupkg"
- name: Publish NuGet package
run: |
$nupkgFiles = Get-ChildItem -Path "./packages" -Filter "*.nupkg"
foreach ($file in $nupkgFiles) {
dotnet nuget push $file.FullName `
--api-key ${{ secrets.NUGET_API_KEY }} `
--source https://api.nuget.org/v3/index.json `
--skip-duplicate
}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
publish-github:
needs: build-and-test
runs-on: windows-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Download NuGet package artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
path: ./packages
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Verify packages exist
run: |
if (-not (Test-Path "./packages/*.nupkg")) {
Write-Error "No .nupkg files found in ./packages directory"
Get-ChildItem -Path "./packages" -Recurse
exit 1
}
Write-Host "Found packages:"
Get-ChildItem -Path "./packages" -Filter "*.nupkg"
- name: Publish to GitHub Packages
run: |
$nupkgFiles = Get-ChildItem -Path "./packages" -Filter "*.nupkg"
foreach ($file in $nupkgFiles) {
dotnet nuget push $file.FullName `
--api-key ${{ secrets.GITHUB_TOKEN }} `
--source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json `
--skip-duplicate
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}