build: Add Lock file support for NuGet deps #22
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: Publish NuGet packages | |
permissions: | |
contents: write | |
packages: write | |
id-token: write | |
attestations: write | |
# Controls when the action will run. | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
build-test: | |
uses: ./.github/workflows/build-test.yml | |
publish-nuget: | |
name: Publish NuGet package | |
runs-on: ubuntu-latest | |
needs: | |
- build-test | |
strategy: | |
fail-fast: false | |
matrix: | |
# Sources to publish to | |
nuget: [ | |
{ name: "NuGet", source: "https://api.nuget.org", keyname: "NUGET_TOKEN" }, | |
{ name: "GitHub Packages", source: "https://nuget.pkg.github.com/Nodsoft", keyname: "GITHUB_TOKEN" } | |
] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # avoid shallow clone so nbgv can do its work. | |
- name: Setup dotnet | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0 | |
- uses: dotnet/nbgv@master | |
id: nbgv | |
- name: Restore dependencies | |
run: dotnet restore --locked-mode | |
- name: Build | |
run: dotnet build | |
- id: is-public-release | |
uses: ASzc/change-string-case-action@v6 | |
with: | |
string: ${{ steps.nbgv.outputs.PublicRelease }} | |
- name: Attest build provenance for .(s)nupkgs | |
uses: actions/attest-build-provenance@v1 | |
# Only once per package: take nuget provider | |
if: matrix.nuget.name == 'NuGet' | |
with: | |
subject-path: "**/Release/*nupkg" | |
# Publish | |
- name: Publish packages to ${{ matrix.nuget.name }} | |
run: | | |
dotnet nuget push "**/Release/*.nupkg" \ | |
--source "${{ matrix.nuget.source }}" \ | |
--symbol-source "${{ matrix.nuget.source }}" \ | |
--api-key "${{ secrets[matrix.nuget.keyname] }}" \ | |
--symbol-api-key "${{ secrets[matrix.nuget.keyname] }}" \ | |
--skip-duplicate |