Skip to content

Commit

Permalink
Create deploynuget.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
malware-dev authored Nov 19, 2023
1 parent e71e31f commit b991ca9
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/deploynuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Build and Deploy

on:
workflow_dispatch:
inputs:
publishToNuGet:
description: 'Publish to NuGet (y/n)'
required: true
default: 'y'
push:
branches:
- main
paths:
- 'Source/**/PackageVersion.txt'

env:
NuGetDirectory: ${{ github.workspace }}/nuget

jobs:
build:

runs-on: ubuntu-latest

environment: Deploy

defaults:
run:
working-directory: ./Source
shell: pwsh

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x

- name: Restore dependencies
run: dotnet restore

- name: Build solution
run: dotnet build --configuration Release

- uses: actions/upload-artifact@v3
with:
name: BuildOutput
retention-days: 7
path: "**/bin/Release/*.*"

- name: Collect NuGet packages
run: |
New-Item -ItemType Directory -Force -Path ${{ env.NuGetDirectory }}
$files = Get-ChildItem -Path . -Filter *.nupkg -Recurse
Write-Host "Found files: $files"
foreach ($file in $files) {
Write-Host "Copying file: $file"
Copy-Item -Path $file.FullName -Destination ${{ env.NuGetDirectory }}
}
- uses: actions/upload-artifact@v3
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg

- name: Publish NuGet packages
if: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.publishToNuGet == 'y') || github.event_name == 'push' }}
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}

0 comments on commit b991ca9

Please sign in to comment.