Update Directory.Build.props #37
This file contains 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: "Build + Publish NuGet Package" | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
paths: | |
- "src/**" | |
- ".github/workflows/**" | |
- "lib.sln" | |
- "nuget.config" | |
push: | |
branches: | |
- master | |
paths: | |
- "src/**" | |
- ".github/workflows/**" | |
- "lib.sln" | |
- "nuget.config" | |
env: | |
DOTNET_NOLOGO: true | |
jobs: | |
build: | |
runs-on: "grid-bot-infra" | |
env: | |
VersionSuffix: ${{ github.event.pull_request.number && format('pr-{0}-{1}-{2}-preview', github.event.pull_request.number, github.run_number, github.run_attempt) || '' }} | |
SOLUTION_FILE_NAME: "./lib.sln" | |
steps: | |
# Setup | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Move to Checkout Path | |
run: | | |
mkdir -p /_/_work/${{ github.repository }}/${{ github.sha }} | |
mv * /_/_work/${{ github.repository }}/${{ github.sha }} | |
- name: Setup .NET 6 | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 6.0.x | |
# Build | |
- name: Restore NuGet Packages | |
working-directory: /_/_work/${{ github.repository }}/${{ github.sha }} | |
run: >- | |
dotnet restore | |
${{ env.SOLUTION_FILE_NAME }} | |
- name: Build Solution | |
working-directory: /_/_work/${{ github.repository }}/${{ github.sha }} | |
run: >- | |
dotnet build | |
${{ env.SOLUTION_FILE_NAME }} | |
--no-restore | |
-c Release | |
- name: Run Tests | |
working-directory: /_/_work/${{ github.repository }}/${{ github.sha }} | |
run: >- | |
dotnet test | |
${{ env.SOLUTION_FILE_NAME }} | |
--no-build | |
--no-restore | |
-c Release | |
- name: Pack NuGet Packages | |
working-directory: /_/_work/${{ github.repository }}/${{ github.sha }} | |
run: >- | |
dotnet pack | |
${{ env.SOLUTION_FILE_NAME }} | |
--no-build | |
--no-restore | |
--output ./dist | |
-c Release | |
# Finish | |
- name: Upload build artifacts | |
if: ${{ github.event_name == 'push' }} | |
continue-on-error: true | |
uses: actions/upload-artifact@v3 | |
with: | |
retention-days: 1 | |
name: nuget-packages | |
path: | | |
/_/_work/${{ github.repository }}/${{ github.sha }}/dist/*.nupkg | |
- name: Cleanup | |
if: always() | |
continue-on-error: true | |
run: | | |
rm -rf /_/_work/${{ github.repository }}/${{ github.sha }} | |
# Upload to NuGet | |
upload: | |
runs-on: "grid-bot-infra" | |
needs: "build" | |
environment: "release" | |
if: ${{ github.event_name == 'push' }} | |
steps: | |
# Setup | |
- name: Setup .NET 6 | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: "6.0.x" | |
- name: Download build artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: nuget-packages | |
path: dist | |
- name: Publish NuGet Packages | |
run: >- | |
dotnet nuget push | |
dist/*.nupkg | |
--skip-duplicate | |
--source ${{ vars.NUGET_SOURCE }} | |
--api-key ${{ secrets.NUGET_API_KEY }} |