Skip to content

Commit

Permalink
Publish to NuGet
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardog committed Feb 17, 2023
1 parent d7a2b16 commit 7b64557
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ jobs:
identifier: gerardog.gsudo
installers-regex: '\.msi$' # Only .msi files

publishNuget:
name: Push to Nuget
#if: github.ref == 'refs/heads/master' && github.repository == 'gerardog/gsudo'
if: github.repository == 'gerardog/gsudo'
runs-on: windows-latest
needs: [build, release]
permissions:
contents: write
environment:
name: release-nuget
env:
version: ${{ needs.build.outputs.version }}
version_MajorMinorPatch: ${{ needs.build.outputs.version_MajorMinorPatch }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
name: Binaries
path: ./artifacts
- name: Import Nuget Api Key
run: nuget setapikey ${{ secrets.NUGET_APIKEY }}
- name: Build Package for Nuget & Upload
run: ./build/06-release-Nuget.ps1

docs:
needs: publish
uses: ./.github/workflows/docs.yml
Expand Down
16 changes: 4 additions & 12 deletions build/05-release-Chocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (! (Test-IsAdmin)) {
throw "Must be admin to properly test generated package"
}

pushd $PSScriptRoot\..
pushd $PSScriptRoot\..

Get-Item .\artifacts\x64\gsudo.exe > $null || $(throw "Missing binaries/artifacts")

Expand All @@ -21,9 +21,8 @@ if ($env:version) {
}
"- Using version number v$version / v$version_MajorMinorPatch"

"- Cleaning Choco & Nuget template folder"
"- Cleaning Choco template folder"
git clean .\Build\Chocolatey\gsudo -xf
git clean .\Build\Nuget\gsudo -xf

"- Adding Artifacts"
cp artifacts\x?? .\Build\Chocolatey\gsudo\tools -Recurse -Force -Exclude *.pdb
Expand All @@ -34,8 +33,6 @@ Get-ChildItem .\build\Chocolatey\gsudo\tools\ -Recurse -Filter *.exe | % { ni "$
# Generate Tools\VERIFICATION.txt
Get-Content .\Build\Chocolatey\verification.txt.template | Out-File -encoding UTF8 .\Build\Chocolatey\gsudo\Tools\VERIFICATION.txt

(Get-Content Build\Nuget\gsudo.nuspec.template) -replace '#VERSION#', "$version" | Out-File -encoding UTF8 .\Build\Nuget\gsudo.nuspec

"- Calculating Hashes "

@"
Expand All @@ -50,11 +47,7 @@ Get-childitem *.bak -Recurse | Remove-Item
mkdir Artifacts\Chocolatey -Force > $null
& choco pack .\Build\Chocolatey\gsudo\gsudo.nuspec -outdir="$((get-item Artifacts\Chocolatey).FullName)" || $(throw "Choco pack failed.")

"- Packing v$version to nuget"
mkdir Artifacts\Nuget -Force > $null
& nuget pack .\Build\Nuget\gsudo.nuspec -OutputDirectory "$((get-item Artifacts\Nuget).FullName)" || $(throw "Nuget pack failed.")

"- Testing choco package"
"- Testing package"
if (choco list -lo | Where-object { $_.StartsWith("gsudo") }) {
choco upgrade gsudo --failonstderr -s Artifacts\Chocolatey -f -pre --confirm || $(throw "Choco upgrade failed.")
} else {
Expand All @@ -64,8 +57,7 @@ if (choco list -lo | Where-object { $_.StartsWith("gsudo") }) {
if($(choco apikey).Count -lt 2) { throw "Missing Chocolatey ApiKey. Use: choco apikey -k <your key here> -s https://push.chocolatey.org/" }

"`n- Uploading v$version to chocolatey"
:: choco push artifacts\Chocolatey\gsudo.$($version).nupkg || $(throw "Choco push failed.")

choco push artifacts\Chocolatey\gsudo.$($version).nupkg || $(throw "Choco push failed.")

"- Success"
popd
32 changes: 32 additions & 0 deletions build/06-release-Nuget.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pushd $PSScriptRoot\..

Get-Item .\artifacts\x64\gsudo.exe > $null || $(throw "Missing binaries/artifacts")

if ($env:version) {
"- Getting version from env:version"
$version = $env:version
$version_MajorMinorPatch=$env:version_MajorMinorPatch
} else {
"- Getting version using GitVersion"
$version = $(gitversion /showvariable LegacySemVer)
$version_MajorMinorPatch=$(gitversion /showvariable MajorMinorPatch)
}
"- Using version number v$version / v$version_MajorMinorPatch"

"- Cleaning Nuget template folder"
git clean .\Build\Nuget\gsudo -xf

"- Generate gsudo.nuspec"
(Get-Content Build\Nuget\gsudo.nuspec.template) -replace '#VERSION#', "$version" | Out-File -encoding UTF8 .\Build\Nuget\gsudo.nuspec


"- Packing v$version to nuget"
mkdir Artifacts\Nuget -Force > $null
& nuget pack .\Build\Nuget\gsudo.nuspec -OutputDirectory "$((get-item Artifacts\Nuget).FullName)" || $(throw "Nuget pack failed.")

"`n- Uploading v$version to Nuget"
nuget push artifacts\nuget\gsudo.$($version).nupkg -Source https://api.nuget.org/v3/index.json || $(throw "Nuget push failed.")


"- Success"
popd
1 change: 0 additions & 1 deletion build/06-release-Scoop.ps1

This file was deleted.

0 comments on commit 7b64557

Please sign in to comment.