Move to GitHub Actions #7
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
release: | |
types: [ published ] | |
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 | |
name: Create NuGet packages | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer | |
# Install the .NET SDK indicated in the global.json file | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
# Cache NuGet packages | |
- uses: actions/cache@v4 | |
with: | |
path: ~/.nuget/packages | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-nuget- | |
# Restore dependencies | |
- name: Restore dependencies | |
run: dotnet restore | |
# Create the NuGet package using MSBuild to match original AppVeyor parameters for deterministic builds | |
- name: Pack NuGet package | |
run: dotnet msbuild -t:Pack src/UTF-unknown.csproj -p:Configuration=Release -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg -p:ContinuousIntegrationBuild=true -p:EmbedUntrackedSources=true -p:PackageOutputPath=${{ env.NuGetDirectory }} -verbosity:minimal | |
# Publish the NuGet package as an artifact, so they can be used in the following jobs | |
- name: Upload packages to artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuget | |
if-no-files-found: error | |
retention-days: 7 | |
path: ${{ env.NuGetDirectory }}/* | |
validate_nuget: | |
runs-on: ubuntu-latest | |
needs: [ create_nuget ] | |
steps: | |
# Install the .NET SDK indicated in the global.json file | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
# Download the NuGet package created in the previous job | |
- uses: actions/download-artifact@v4 | |
with: | |
name: nuget | |
path: ${{ env.NuGetDirectory }} | |
# Install nuget validator | |
- name: Install nuget validator | |
run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global | |
# Validate metadata and content of the NuGet package | |
# https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab | |
# If some rules are not applicable, you can disable them | |
# using the --excluded-rules or --excluded-rule-ids option | |
- name: Validate package | |
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg") | |
run_test: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ ubuntu-latest, windows-latest, macos-latest ] | |
include: | |
# Only test on all frameworks on Windows (closest to original AppVeyor setup) | |
- os: windows-latest | |
test-framework: '' | |
# Test only .NET 8.0 on Linux and macOS for efficiency | |
- os: ubuntu-latest | |
test-framework: '--framework net8.0' | |
- os: macos-latest | |
test-framework: '--framework net8.0' | |
name: Run tests on ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
# Cache NuGet packages | |
- uses: actions/cache@v4 | |
with: | |
path: ~/.nuget/packages | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-nuget- | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Run tests | |
run: dotnet test --configuration Release --no-restore --logger trx --results-directory "TestResults-${{ matrix.os }}" ${{ matrix.test-framework }} | |
- name: Upload test results | |
uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: test-results-${{ matrix.os }} | |
path: TestResults-${{ matrix.os }}/*.trx | |
deploy: | |
# Publish only when creating a GitHub Release | |
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository | |
# You can update this logic if you want to manage releases differently | |
if: github.event_name == 'release' | |
runs-on: ubuntu-latest | |
needs: [ validate_nuget, run_test ] | |
steps: | |
# Download the NuGet package created in the previous job | |
- uses: actions/download-artifact@v4 | |
with: | |
name: nuget | |
path: ${{ env.NuGetDirectory }} | |
# Install the .NET SDK indicated in the global.json file | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v4 | |
# Publish the NuGet package to NuGet.org | |
# To publish to NuGet.org, you need to create an account and generate an API key | |
# - Create an account on NuGet.org | |
# - Go to https://www.nuget.org/account/apikeys | |
# - Create a new API key | |
# - Copy the API key and add it as a secret in your GitHub repository with the name NUGET_API_KEY | |
- name: Publish NuGet package | |
run: | | |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg, *.snupkg)) { | |
dotnet nuget push $file --api-key "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate | |
} |