Skip to content

Build package for NuGet (#28) #5

Build package for NuGet (#28)

Build package for NuGet (#28) #5

Workflow file for this run

name: Build for NuGet
on:
push:
tags:
- '*.*.*'
branches:
- 'main'
paths:
- '**/*.csproj'
- '**/*.props'
- '**/*.targets'
- '.github/workflows/nuget.yml'
pull_request:
paths:
- '**/*.csproj'
- '**/*.props'
- '**/*.targets'
- '.github/workflows/nuget.yml'
workflow_dispatch:
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # get full history, not shallow clone
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Build
run: dotnet build KSPBuildTools.csproj
- name: Package
run: dotnet pack KSPBuildTools.csproj --configuration Release --output ${{ env.NuGetDirectory }}
- uses: actions/upload-artifact@v4
with:
name: nuget-package
if-no-files-found: error
path: ${{ env.NuGetDirectory }}/*.nupkg
deploy-nuget:
runs-on: ubuntu-latest
needs: [ build ]
environment:
name: "NuGet"
url: "https://www.nuget.org/packages/KSPBuildTools"
if: github.event_name == 'push'
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- uses: actions/download-artifact@v4
with:
name: nuget-package
path: ${{ env.NuGetDirectory }}
- name: Publish Package to NuGet
run: >-
dotnet nuget push ${{ env.NuGetDirectory }}/*.nupkg
--api-key ${{ secrets.NUGET_API_KEY }}
--source https://api.nuget.org/v3/index.json
- name: Authenticate with Github
run: >-
dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }}
--store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- name: Publish Package to Github
run: |
dotnet nuget push --source "github" ${{ env.NuGetDirectory }}/*.nupkg