Skip to content

Build and Publish Nuget #40

Build and Publish Nuget

Build and Publish Nuget #40

Workflow file for this run

name: Build and Publish Nuget
on:
workflow_dispatch: # <-- allows manual trigger
push:
branches:
- release/*
tags:
- 'v*'
jobs:
build-and-test:
runs-on: ubuntu-22.04
permissions:
id-token: write # enable GitHub OIDC token issuance for this job
strategy:
matrix:
dotnet-version: [8.x, 9.x] # test all supported versions
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET SDK and runtime
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Run Tests with coverage
run: dotnet test --configuration Release --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=./coverage/
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: NavneetHegde/OpenCode
# ========================
# SBOM Generation Step
# ========================
- name: Install CycloneDX .NET Tool
run: dotnet tool install --global CycloneDX
- name: Generate SBOM
run: |
export PATH="$PATH:$HOME/.dotnet/tools"
cyclonedx dotnet -s . -o sbom -f json
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom/sbom.xml
- name: Pack
if: matrix.dotnet-version == '9.x'
run: dotnet pack --configuration Release --no-build --output ./nupkg
- name: Nuget Login (OIDC + temp API Key)
if: matrix.dotnet-version == '9.x'
uses: Nuget/login@v1
id: login
with:
user: ${{secrets.NUGET_USER}}
- name: Nuget push
if: matrix.dotnet-version == '9.x'
run: dotnet nuget push nupkg/*.nupkg --api-key ${{steps.login.outputs.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
- name: Done
run: echo "Package published successfully!"