Skip to content

Support .NET 10 and C# 14 #71

Support .NET 10 and C# 14

Support .NET 10 and C# 14 #71

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: publish
on:
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
push:
branches:
- 'main' # Run the workflow when pushing to the main branch
- 'release/**' # Run the workflow when pushing to a release branch
pull_request:
branches:
- '*' # Run the workflow for all pull requests
release:
types:
- published # Run the workflow when a new GitHub release is published
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace }}/nuget
defaults:
run:
shell: pwsh
jobs:
pack_nuget:
name: dotnet pack
runs-on: ubuntu-latest
# Checkout the source code
steps:
- name: Harden Runner
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Checkout source"
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET SDK with global.json
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
global-json-file: global.json
# Create the NuGet package in the folder from the environment variable NuGetDirectory
- name: dotnet pack Sagara.FeedReader
run: dotnet pack ./src/Sagara.FeedReader/Sagara.FeedReader.csproj --configuration Release --output ${{ env.NuGetDirectory }}
# Upload .nupkg files as an artifact, so they can be used in the following jobs
- name: Upload NuGet packages as artifacts
if: github.event_name == 'release'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: nuget
if-no-files-found: error
retention-days: 1
path: ${{ env.NuGetDirectory }}/*
# Upload global.json as an artifact so that we don't have to check out the whole repo to publish to nuget.
- name: Upload global.json as artifact
if: github.event_name == 'release'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: globaljson
if-no-files-found: error
retention-days: 1
path: ${{ github.workspace }}/global.json
run_test:
runs-on: ubuntu-latest
steps:
- name: "Checkout source"
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
# Install the .NET SDK indicated in the global.json file
# Even though the prior STS and LTS versions are pre-installed on the runner, explicitly list
# them here for clarity. We need their runtimes to execute their tests.
- name: Setup .NET SDK with global.json
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
global-json-file: global.json
dotnet-version: |
8.0.x
9.0.x
# Only run the unit tests, NOT the integration intests that download from tens of feeds.
- name: Run tests
run: dotnet test src/Sagara.FeedReader.Tests.Unit/Sagara.FeedReader.Tests.Unit.csproj --configuration Release
deploy_packages:
# 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: [ pack_nuget, run_test ]
permissions:
# Enable GitHub OIDC token issuance for this job
id-token: write
steps:
# Download the NuGet package created in the pack job
- name: Download NuGet package artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: nuget
path: ${{ env.NuGetDirectory }}
# Download the global.json file uploaded in the pack job
- name: Download NuGet package artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: globaljson
path: ${{ github.workspace }}
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET SDK with global.json
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
global-json-file: global.json
# Get a short-lived API key
- name: NuGet login (OIDC)
uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0
id: login
with:
# nuget.org username, NOT email address
user: ${{ secrets.NUGET_USER }}
# Publish all NuGet .nupkg files to NuGet.
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
- name: Publish package (.nupkg) files
run: |
foreach ($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
$file
dotnet nuget push $file --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}