Skip to content

More than one foreach on the same collection, using complex content, … #8

More than one foreach on the same collection, using complex content, …

More than one foreach on the same collection, using complex content, … #8

Workflow file for this run

# 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@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration Release
- uses: actions/upload-artifact@v4
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@v4
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
}