Skip to content

Commit 91f22f9

Browse files
authored
ci(release): push the Jetsocat package to nuget.org (#1506)
1 parent fc76b9b commit 91f22f9

File tree

1 file changed

+61
-9
lines changed

1 file changed

+61
-9
lines changed

.github/workflows/release.yml

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
runs-on: ${{ matrix.runner }}
107107
environment: publish-prod
108108
needs: preflight
109-
if: needs.preflight.outputs.skip-publishing == 'false' || ${{ inputs.dry-run }}
109+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' || inputs.dry-run }}
110110
strategy:
111111
fail-fast: false
112112
matrix:
@@ -212,7 +212,7 @@ jobs:
212212
runs-on: ubuntu-latest
213213
environment: publish-prod
214214
needs: preflight
215-
if: needs.preflight.outputs.skip-publishing == 'false' || ${{ inputs.dry-run }}
215+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' || inputs.dry-run }}
216216

217217
steps:
218218
- name: Configure runner
@@ -273,7 +273,7 @@ jobs:
273273
runs-on: ubuntu-latest
274274
environment: publish-prod
275275
needs: preflight
276-
if: needs.preflight.outputs.skip-publishing == 'false' || ${{ inputs.dry-run }}
276+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' || inputs.dry-run }}
277277

278278
steps:
279279
- name: Download artifacts
@@ -325,7 +325,7 @@ jobs:
325325
name: OneDrive (Devolutions Gateway)
326326
runs-on: ubuntu-latest
327327
needs: preflight
328-
if: needs.preflight.outputs.skip-publishing == 'false' || ${{ inputs.dry-run }}
328+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' || inputs.dry-run }}
329329
environment: onedrive-upload # for OneDrive secrets
330330

331331
steps:
@@ -373,7 +373,7 @@ jobs:
373373
374374
- name: Upload to OneDrive
375375
uses: ./.github/workflows/onedrive-upload
376-
if: (needs.preflight.outputs.skip-publishing == 'false') && (inputs.dry-run == false)
376+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' && !inputs.dry-run }}
377377
with:
378378
azure_client_id: ${{ secrets.ONEDRIVE_AUTOMATION_CLIENT_ID }}
379379
azure_client_secret: ${{ secrets.ONEDRIVE_AUTOMATION_CLIENT_SECRET }}
@@ -386,7 +386,7 @@ jobs:
386386
name: OneDrive (Devolutions Agent)
387387
runs-on: ubuntu-latest
388388
needs: preflight
389-
if: needs.preflight.outputs.skip-publishing == 'false' || ${{ inputs.dry-run }}
389+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' || inputs.dry-run }}
390390
environment: onedrive-upload # for OneDrive secrets
391391

392392
steps:
@@ -434,7 +434,7 @@ jobs:
434434
435435
- name: Upload to OneDrive
436436
uses: ./.github/workflows/onedrive-upload
437-
if: (needs.preflight.outputs.skip-publishing == 'false') && (inputs.dry-run == false)
437+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' && !inputs.dry-run }}
438438
with:
439439
azure_client_id: ${{ secrets.ONEDRIVE_AUTOMATION_CLIENT_ID }}
440440
azure_client_secret: ${{ secrets.ONEDRIVE_AUTOMATION_CLIENT_SECRET }}
@@ -443,16 +443,68 @@ jobs:
443443
remote: releases
444444
source_path: ${{ steps.prepare.outputs.files-to-upload }}
445445

446+
jetsocat-publish:
447+
name: Jetsocat NuGet publish
448+
runs-on: ubuntu-latest
449+
environment: publish-prod
450+
needs: preflight
451+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' || inputs.dry-run }}
452+
453+
steps:
454+
- name: Download jetsocat-nuget artifact
455+
shell: pwsh
456+
env:
457+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
458+
run: gh run download ${{ needs.preflight.outputs.run }} -n jetsocat-nuget --repo $Env:GITHUB_REPOSITORY
459+
460+
- name: Publish Jetsocat NuGet package
461+
shell: pwsh
462+
run: |
463+
Set-PSDebug -Trace 1
464+
465+
$Package = Get-ChildItem -Recurse -Filter "Devolutions.Jetsocat.*.nupkg" -File | Select-Object -First 1
466+
Write-Host "Package = $Package"
467+
468+
$PushCmd = @(
469+
'dotnet',
470+
'nuget',
471+
'push',
472+
"$($Package.FullName)",
473+
'--api-key',
474+
'${{ secrets.NUGET_API_KEY }}',
475+
'--source',
476+
'https://api.nuget.org/v3/index.json',
477+
'--skip-duplicate'
478+
)
479+
480+
$PushCmd = $PushCmd -Join ' '
481+
Write-Host $PushCmd
482+
483+
$DryRun = [System.Convert]::ToBoolean('${{ inputs.dry-run }}')
484+
if (-Not $DryRun) {
485+
try {
486+
Invoke-Expression $PushCmd
487+
} catch {
488+
if ($_.Exception.Message -ilike "*package already exists*" -Or $_.Exception.Message -ilike "*already has a package*") {
489+
echo "::warning::Jetsocat NuGet package not published; this version is already listed on NuGet.org"
490+
} else {
491+
Write-Error $_
492+
exit 1
493+
}
494+
}
495+
}
496+
446497
remove-labels:
447498
name: Remove release-required labels
448499
runs-on: ubuntu-latest
449-
if: needs.preflight.outputs.skip-publishing == 'false' || ${{ inputs.dry-run }}
500+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' && !inputs.dry-run }}
450501
needs:
451502
- container
452503
- github-release
453504
- psgallery-release
454505
- onedrive-gateway
455506
- onedrive-agent
507+
- jetsocat-publish
456508

457509
steps:
458510
- name: Check out ${{ github.repository }}
@@ -468,7 +520,7 @@ jobs:
468520
name: Upload SBOM
469521
runs-on: ubuntu-latest
470522
needs: preflight
471-
if: needs.preflight.outputs.skip-publishing == 'false' && inputs.dry-run == false
523+
if: ${{ needs.preflight.outputs.skip-publishing == 'false' && !inputs.dry-run }}
472524
environment: sbom
473525

474526
steps:

0 commit comments

Comments
 (0)