Skip to content

Commit 485c489

Browse files
snealmoleskea-b
committed
Add Chocolatey packaging for Windows
Co-authored-by: Shawn Neal <[email protected]> Co-authored-by: Michael Oleske <[email protected]> Co-authored-by: Al Berez <[email protected]>
1 parent 4ebc704 commit 485c489

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# stop on all errors
2+
$ErrorActionPreference = 'Stop';
3+
4+
$packageName = 'cloudfoundry-cli'
5+
$registryUninstallerKeyName = 'cloudfoundry-cli'
6+
$version = '${version}'
7+
$url = '${claw_url}/stable?release=windows32-exe&version=${version}&source=github-rel'
8+
$url64 = '${claw_url}/stable?release=windows64-exe&version=${version}&source=github-rel'
9+
$checksum = '${checksum}'
10+
$checksum64 = '${checksum64}'
11+
$installDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
12+
$validExitCodes = @(0)
13+
14+
Install-ChocolateyZipPackage -PackageName "$packageName" `
15+
-Url "$url" `
16+
-ChecksumType sha256 `
17+
-Checksum "$checksum" `
18+
-Url64bit "$url64" `
19+
-ChecksumType64 sha256 `
20+
-Checksum64 "$checksum64" `
21+
-UnzipLocation "$installDir"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Do not remove this test for UTF-8: if “Ω” does not appear as greek uppercase omega letter enclosed in quotation
4+
marks, you should use an editor that supports UTF-8, not this one.
5+
-->
6+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
7+
<metadata>
8+
<id>cloudfoundry-cli</id>
9+
<title>Cloud Foundry CLI</title>
10+
<version>${version}</version>
11+
<authors>Cloud Foundry Foundation</authors>
12+
<owners>Cloud Foundry Foundation</owners>
13+
<summary>Install official command line client for Cloud Foundry.</summary>
14+
<description>Cloud Foundry CLI is the official command line client for Cloud Foundry
15+
</description>
16+
<projectUrl>https://github.com/cloudfoundry/cli</projectUrl>
17+
<tags>cf cli cloudfoundry</tags>
18+
<copyright>Cloud Foundry Foundation</copyright>
19+
<licenseUrl>https://raw.githubusercontent.com/cloudfoundry/cli/master/LICENSE</licenseUrl>
20+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
21+
<iconUrl>https://raw.githubusercontent.com/cloudfoundry/cli/main/.github/win/cf.ico</iconUrl>
22+
<packageSourceUrl>https://github.com/cloudfoundry/cli</packageSourceUrl>
23+
<docsUrl>https://docs.cloudfoundry.org/cf-cli/</docsUrl>
24+
<bugTrackerUrl>https://github.com/cloudfoundry/cli/issues</bugTrackerUrl>
25+
<releaseNotes>https://github.com/cloudfoundry/cli/releases</releaseNotes>
26+
</metadata>
27+
<files>
28+
<file src="tools\*.*" target="tools"/>
29+
</files>
30+
</package>

.github/workflows/release-update-repos.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,103 @@ jobs:
473473
- name: Test Version Match
474474
run: cf -v | grep -q "${VERSION_BUILD}"
475475

476+
update-windows:
477+
name: Update Windows Chocolatey Package
478+
runs-on: windows-2019
479+
defaults:
480+
run:
481+
shell: pwsh
482+
needs: setup
483+
environment: ${{ needs.setup.outputs.secrets-environment }}
484+
env:
485+
CLAW_URL: ${{ needs.setup.outputs.claw-url }}
486+
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
487+
VERSION_MAJOR: ${{ needs.setup.outputs.version-major }}
488+
steps:
489+
490+
- name: Setup
491+
run: |
492+
echo "VERSION_BUILD: ${VERSION_BUILD}"
493+
echo "Environment: ${ENVIRONMENT}"
494+
495+
- name: Checkout
496+
uses: actions/checkout@v4
497+
498+
- name: Calculate Checksums
499+
run: |
500+
foreach ($bit in @('32', '64')) {
501+
$file="cf-cli_win${bit}.zip"
502+
Invoke-WebRequest "${env:CLAW_URL}/stable?release=windows${bit}-exe&version=${env:VERSION_BUILD}&source=github-rel" `
503+
-OutFile $file
504+
505+
if (-not (Test-Path -Path $file)) {
506+
Write-Error "Failed to download $file" -ErrorAction Stop
507+
}
508+
509+
$hash = (Get-FileHash $file).Hash
510+
Add-Content -Path "$env:GITHUB_ENV" -Value "CLI_WIN${bit}_SHA256=$hash"
511+
}
512+
513+
- name: Render Chocolatey Templates
514+
run: |
515+
# Ensure current directory is accurate for WriteAllLines
516+
[System.Environment]::CurrentDirectory = (Get-Location).Path
517+
518+
# Use WriteAllLines because it uses UTF8 without a BOM
519+
$nuspec = (Get-Content -Encoding utf8 -Raw ./.github/win/choco/cloudfoundry-cli.nuspec.tmpl).
520+
Replace('${version}', $env:VERSION_BUILD)
521+
[System.IO.File]::WriteAllLines('./cloudfoundry-cli.nuspec', $nuspec)
522+
523+
New-Item -Path ./tools -ItemType Directory -Force | Out-Null
524+
(Get-Content -Encoding utf8 -Raw ./.github/win/choco/chocolateyinstall.ps1.tmpl).
525+
Replace('${version}', $env:VERSION_BUILD). `
526+
Replace('${checksum}', $env:CLI_WIN32_SHA256). `
527+
Replace('${checksum64}', $env:CLI_WIN64_SHA256). `
528+
Replace('${claw_url}', $env:CLAW_URL) | `
529+
Set-Content ./tools/chocolateyinstall.ps1 -Encoding utf8
530+
531+
- name: Create Chocolatey Package
532+
run: |
533+
choco pack ./cloudfoundry-cli.nuspec
534+
535+
- name: Push Chocolatey Package
536+
env:
537+
CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }}
538+
run: |
539+
choco config set --name=defaultPushSource --value=https://push.chocolatey.org/
540+
choco setapikey --key $env:CHOCO_API_KEY --source https://push.chocolatey.org/
541+
choco push "cloudfoundry-cli.$env:VERSION_BUILD.nupkg"
542+
543+
test-windows:
544+
name: Test Windows Chocolatey Package
545+
runs-on: windows-2019
546+
defaults:
547+
run:
548+
shell: pwsh
549+
needs:
550+
- setup
551+
- update-windows
552+
environment: ${{ needs.setup.outputs.secrets-environment }}
553+
env:
554+
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
555+
VERSION_MAJOR: ${{ needs.setup.outputs.version-major }}
556+
steps:
557+
558+
- name: Install cf cli package
559+
run: choco install cloudfoundry-cli --version $env:VERSION_BUILD
560+
561+
- name: Print Chocolatey CF CLI Versions
562+
run: |
563+
cd 'C:/ProgramData/chocolatey/lib/cloudfoundry-cli/tools'
564+
./cf -v
565+
Invoke-Expression "./cf$env:VERSION_MAJOR -v"
566+
567+
- name: Test Chocolatey Version Match
568+
run: |
569+
cd 'C:/ProgramData/chocolatey/lib/cloudfoundry-cli/tools'
570+
$found = (./cf -v | Select-String "$env:VERSION_BUILD")
571+
if ($null -eq $found) {
572+
Write-Error "CF CLI version $env:VERSION_BUILD was not found" -ErrorAction Stop
573+
}
574+
476575
# vim: set sw=2 ts=2 sts=2 et tw=78 foldlevel=2 fdm=indent nospell:

0 commit comments

Comments
 (0)