Skip to content

Merge pull request #1 from uniblab/workflow #18

Merge pull request #1 from uniblab/workflow

Merge pull request #1 from uniblab/workflow #18

Workflow file for this run

name: build and publish
on:
push:
branches:
- main
permissions:
id-token: write
contents: read
packages: write
jobs:
# ----------------------------------------------------
# STAGE 1: Cross-Platform Build & Test (All 3 OSs)
# ----------------------------------------------------
build-and-test:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- run: dotnet clean Icod.Path.sln -c Release
- run: dotnet restore Icod.Path.sln
- run: dotnet build Icod.Path.sln -c Release --no-restore -p:ContinuousIntegrationBuild=true
- run: dotnet test Icod.Path.sln -c Release --no-build --logger trx
# Pack the specific project only on one OS to create the artifact
- name: Pack NuGet Package
if: matrix.os == 'windows-latest'
run: dotnet pack Icod.Path.csproj -c Release --no-build -o ./artifacts
# Save the package so the deploy job can access it
- name: Upload Artifact
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: ./artifacts/*nupkg
# ----------------------------------------------------
# STAGE 2: Secure & Single NuGet Deployment
# ----------------------------------------------------
deploy:
needs: build-and-test
runs-on: windows-latest
environment: Release
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
path: ./artifacts
- name: NuGet login (OIDC → temp API key)
uses: NuGet/login@v1
id: login
with:
user: ${{ secrets.NUGET_USER }}
# PowerShell friendly execution to push all target packages sequentially
- name: NuGet push
shell: pwsh
run: |
Get-ChildItem "./artifacts/Icod.Path.*.nupkg" | ForEach-Object {
dotnet nuget push $_.FullName --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
}
# PowerShell friendly execution to push all target packages sequentially
- name: Push to GitHub Packages
shell: pwsh
run: |
Get-ChildItem "./artifacts/Icod.Path.*.nupkg" | ForEach-Object {
dotnet nuget push $_.FullName --api-key "${{ secrets.GITHUB_TOKEN }}" --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --skip-duplicate
}