Skip to content

v5.9.4

v5.9.4 #498

# 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 NuGet packages
runs-on: ubuntu-latest
# Checkout the source code
steps:
- name: Harden Runner
uses: step-security/harden-runner@05e31511f85b41b11d1cf0ef85d0992719546e2c # v2.21.0
with:
egress-policy: audit
- name: "Checkout source"
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# 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 packages in the folder from the environment variable NuGetDirectory
- name: dotnet pack Sagara.Core
run: dotnet pack ./src/Sagara.Core/Sagara.Core.csproj --configuration Release --output ${{ env.NuGetDirectory }}
- name: dotnet pack Sagara.Core.AspNetCore
run: dotnet pack ./src/Sagara.Core.AspNetCore/Sagara.Core.AspNetCore.csproj --configuration Release --output ${{ env.NuGetDirectory }}
- name: dotnet pack Sagara.Core.Caching
run: dotnet pack ./src/Sagara.Core.Caching/Sagara.Core.Caching.csproj --configuration Release --output ${{ env.NuGetDirectory }}
- name: dotnet pack Sagara.Core.Data
run: dotnet pack ./src/Sagara.Core.Data/Sagara.Core.Data.csproj --configuration Release --output ${{ env.NuGetDirectory }}
- name: dotnet pack Sagara.Core.Google
run: dotnet pack ./src/Sagara.Core.Google/Sagara.Core.Google.csproj --configuration Release --output ${{ env.NuGetDirectory }}
- name: dotnet pack Sagara.Core.Logging.Serilog
run: dotnet pack ./src/Sagara.Core.Logging.Serilog/Sagara.Core.Logging.Serilog.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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# 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
- name: Run unit tests
run: dotnet test src/Sagara.Core.Tests/Sagara.Core.Tests.csproj --configuration Release
- name: Run unit tests (Sagara.Core.Google)
run: dotnet test src/Sagara.Core.Google.Tests/Sagara.Core.Google.Tests.csproj --configuration Release
run_integration_tests:
runs-on: ubuntu-latest
services:
redis:
image: redis:8
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
REDIS_ALLOW_FLUSH: "true"
ConnectionStrings__Redis: "localhost:6379,abortConnect=false"
steps:
- name: "Checkout source"
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Install the .NET SDK indicated in the global.json file
# The integration tests only target the latest version, so we don't need to install the prior
# STS and LTS versions here.
- name: Setup .NET SDK with global.json
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
global-json-file: global.json
- name: Run integration tests
run: dotnet test src/Sagara.Core.Caching.IntegrationTests/Sagara.Core.Caching.IntegrationTests.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, run_integration_tests ]
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
}