Skip to content

Build and Publish Nuget #55

Build and Publish Nuget

Build and Publish Nuget #55

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 new tool-manifest
dotnet tool install CycloneDX
- name: Generate SBOM for latest tag on branch
id: generate_sbom
run: |
git fetch --tags
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
echo "Current branch: $BRANCH_NAME"
VERSION=$(git tag --merged $BRANCH_NAME --sort=-v:refname | head -n1)
if [ -z "$VERSION" ]; then
VERSION=$(git rev-parse --short HEAD)
fi
echo "Version for SBOM: $VERSION"
mkdir -p sbom/$VERSION
dotnet tool run dotnet-CycloneDX OpenCode/OpenCode.csproj -o sbom/$VERSION -F json
# Set step output
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Upload SBOM artifact
uses: actions/upload-artifact@v4
with:
name: SBOM-${{ steps.generate_sbom.outputs.version }}
path: sbom/${{ steps.generate_sbom.outputs.version }}/bom.json
- name: Pack
if: matrix.dotnet-version == '9.x'
run: dotnet pack --configuration Release --no-build --output ./nupkg
- name: Done
run: echo "Package published successfully!"