Skip to content

Publish To Nuget

Publish To Nuget #31

Workflow file for this run

name: Publish To Nuget
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# pull_request:
# push:
release:
types: [published]
jobs:
build:
name: Build
#Needs windows to build the windows version
runs-on: windows-latest
env:
NUPKG_MAJOR: 1.0.2
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
PROJECT: MauiGestures/MauiGestures.csproj
# CODESIGN_PFX: ${{ secrets.CODESIGN_PFX }}
steps:
- uses: actions/checkout@v4
#Saves a nuget config
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
# - name: Install MAUI workload
# run: dotnet workload install maui
- name: Build
shell: pwsh
run: dotnet build -c Release $PROJECT
- name: Package & Publish NuGets
shell: pwsh
env:
#required so if it contains special characters they are not interpreted by powershell
NUGET_AUTH_TOKEN: ${{secrets.NUGETAPIKEY}}
NUGET_TARGET: https://api.nuget.org/v3/index.json
run: |
$VERSION="$env:NUPKG_MAJOR-ci$env:GITHUB_RUN_ID"
if ($env:GITHUB_EVENT_NAME -eq "release") {
$VERSION = $env:GITHUB_REF.Substring($env:GITHUB_REF.LastIndexOf('/') + 1)
}
echo "PACKAGE VERSION: $VERSION"
New-Item -ItemType Directory -Force -Path ./artifacts
dotnet pack --no-build --output ./artifacts -c Release -p:PackageVersion=$VERSION $PROJECT
# needs to CD because nuget push can't find nuget packages with a linux style path
cd ./artifacts
dotnet nuget push *.nupkg --skip-duplicate -k $env:NUGET_AUTH_TOKEN -s $env:NUGET_TARGET
# github package uses storage space, which is a limited resource
# echo "pkgverci=$VERSION" >> $GITHUB_OUTPUT
#$pfxPath = Join-Path -Path $pwd -ChildPath "codesigncert.pfx"
#[IO.File]::WriteAllBytes("$pfxPath", [System.Convert]::FromBase64String($env:CODESIGN_PFX))
#nuget sign .\artifacts\*.nupkg -CertificatePath $pfxPath -Timestamper http://timestamp.entrust.net/TSS/RFC3161sha2TS
# - name: Artifacts
# uses: actions/upload-artifact@v3
# with:
# name: nupkg
# path: ./artifacts
# publish:
# name: Publish
# needs: build
# runs-on: windows-latest
# environment: Default
# if: github.event_name == 'release'
# env:
# #required so if it contains special characters they are not interpreted by powershell
# NUGET_AUTH_TOKEN: ${{secrets.NUGETAPIKEY}}
# NUGET_TARGET: https://api.nuget.org/v3/index.json
# steps:
# - name: Download Artifacts
# uses: actions/download-artifact@v3
# with:
# name: nupkg
# - name: Setup .NET Core
# uses: actions/setup-dotnet@v3
# with:
# dotnet-version: 8.0.x
# - name: Push to nuget
## does not find the nupkg file when used without download artifact.
# run: dotnet nuget push ./artifacts/*.nupkg -s $env:NUGETAPIKEY -k $env:NUGET_AUTH_TOKEN