@@ -421,3 +421,70 @@ jobs:
421
421
# For gh CLI. We need a real token since we're commenting on a PR in a
422
422
# different repo.
423
423
GH_TOKEN : ${{ secrets.CDRCI_GITHUB_TOKEN }}
424
+
425
+ publish-chocolatey :
426
+ name : Publish to Chocolatey
427
+ runs-on : windows-latest
428
+ needs : release
429
+ steps :
430
+ - name : Checkout
431
+ uses : actions/checkout@v3
432
+ with :
433
+ fetch-depth : 0
434
+
435
+ # Same reason as for release.
436
+ - name : Fetch git tags
437
+ run : git fetch --tags --force
438
+
439
+ # From https://chocolatey.org
440
+ - name : Install Chocolatey
441
+ run : |
442
+ Set-ExecutionPolicy Bypass -Scope Process -Force;
443
+ [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
444
+
445
+ iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
446
+
447
+ - name : Build chocolatey package
448
+ run : |
449
+ cd scripts/chocolatey
450
+
451
+ # The package version is the same as the tag minus the leading "v".
452
+ # The version in this output already has the leading "v" removed but
453
+ # we do it again to be safe.
454
+ $version = "${{ needs.release.outputs.version }}".Trim('v')
455
+
456
+ $release_assets = gh release view --repo coder/coder "v${version}" --json assets | `
457
+ ConvertFrom-Json
458
+
459
+ # Get the URL for the Windows ZIP from the release assets.
460
+ $zip_url = $release_assets.assets | `
461
+ Where-Object name -Match ".*_windows_amd64.zip$" | `
462
+ Select -ExpandProperty url
463
+
464
+ echo "ZIP URL: ${zip_url}"
465
+ echo "Package version: ${version}"
466
+
467
+ echo "Downloading ZIP..."
468
+ Invoke-WebRequest $zip_url -OutFile assets.zip
469
+
470
+ echo "Extracting ZIP..."
471
+ Expand-Archive assets.zip -DestinationPath assets/
472
+
473
+ # No need to specify nuspec if there's only one in the directory.
474
+ choco pack --version=$version binary_path=assets/coder.exe
475
+
476
+ # Bail if dry-run.
477
+ if ($env:CODER_DRY_RUN -match "t") {
478
+ echo "Skipping submission due to dry-run."
479
+ exit 0
480
+ }
481
+
482
+ choco apikey --api-key $env:CHOCO_API_KEY -source https://push.chocolatey.org/
483
+
484
+ # No need to specify nupkg if there's only one in the directory.
485
+ choco push --source https://push.chocolatey.org/
486
+
487
+ env :
488
+ # For gh CLI. We need a real token since we're commenting on a PR in a
489
+ # different repo.
490
+ CHOCO_API_KEY : ${{ secrets.CHOCO_API_KEY }}
0 commit comments