Skip to content

test

test #152

Workflow file for this run

name: publish
on:
push:
branches:
- '*'
pull_request:
branches:
- '*'
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget
defaults:
run:
shell: pwsh
jobs:
create_nuget:
runs-on: ubuntu-latest
env:
RepositoryBranch: ${{github.ref}}
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
- run: dotnet run --project Meziantou.Polyfill.Generator/Meziantou.Polyfill.Generator.csproj
- run: dotnet pack Meziantou.Polyfill --configuration Release
- uses: actions/upload-artifact@v4
with:
name: nuget
if-no-files-found: error
retention-days: 3
path: '**/*.nupkg'
- uses: actions/upload-artifact@v4
with:
name: generated-code
if-no-files-found: error
retention-days: 3
path: '**/*.g.cs'
validate_nuget:
runs-on: ubuntu-latest
needs: [ create_nuget ]
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core (global.json)
uses: actions/setup-dotnet@v4
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Run dotnet validate
run: |
dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
$files = Get-ChildItem "${{ env.NuGetDirectory }}/*" -Recurse -Include *.nupkg
$Errors = $false
foreach($file in $files) {
& meziantou.validate-nuget-package "$file"
if ($LASTEXITCODE -ne 0) {
$Errors = $true
}
}
if ($Errors) {
exit 1
}
tests:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
- run: dotnet run --project Meziantou.Polyfill.Generator/Meziantou.Polyfill.Generator.csproj
- run: dotnet test Meziantou.Polyfill.SourceGenerator.Tests --logger trx --results-directory test-results
- run: dotnet test Meziantou.Polyfill.Tests --logger trx --results-directory test-results
- uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: test-results
path: test-results
deploy:
runs-on: 'ubuntu-latest'
needs: [ validate_nuget, tests ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
- run: |
Write-Host "Current ref: $env:GITHUB_REF"
Write-Host "Searching nupkg in folder: ${{ env.NuGetDirectory }}"
$files = Get-ChildItem "${{ env.NuGetDirectory }}/*" -Recurse -Include *.nupkg
foreach($file in $files) {
Write-Host "Pushing NuGet package: $($file.FullName)"
if ($env:GITHUB_REF -eq 'refs/heads/main')
{
& dotnet nuget push "$($file.FullName)" --api-key "$env:NuGetApiKey" --source https://api.nuget.org/v3/index.json --force-english-output --skip-duplicate
}
else
{
Write-Host "Not on the default branch => Do not push"
}
}
name: Publish NuGet packages
if: always()
env:
NuGetApiKey: ${{ secrets.NuGetApiKey }}