Skip to content

Commit 837b0fa

Browse files
committed
fix: update chocolatey workflow
1 parent 515ae7a commit 837b0fa

File tree

2 files changed

+52
-50
lines changed

2 files changed

+52
-50
lines changed

.github/workflows/chocolatey.yml

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Chocolatey Deploy
22

33
# This GH action will push a okta-aws-cli build to chocolatey.org when a
44
# okta-aws-cli GH release is completed.
5-
#
5+
#
66
# inspired by https://github.com/rcmaehl/MSEdgeRedirect thank you rcmaehl 🙏🙏🙏
77

88
on:
@@ -18,52 +18,74 @@ jobs:
1818
chocolatey:
1919
runs-on: windows-latest
2020
steps:
21-
-
22-
name: Checkout
21+
- name: Checkout
2322
uses: actions/checkout@v4
24-
-
25-
name: Unshallow
23+
24+
- name: Unshallow
2625
run: git fetch --prune --unshallow
27-
-
28-
name: Get latest release tag
26+
27+
- name: Get latest release tag
2928
uses: oprypin/find-latest-tag@v1
3029
with:
3130
repository: ${{ github.repository }}
3231
releases-only: true
3332
id: latesttag
34-
-
35-
name: Set Version
33+
34+
- name: Set Version
3635
id: version
3736
run: |
3837
version=$(echo "${{ steps.latesttag.outputs.tag }}" | grep -oE "[[:digit:]]{1,}\.[[:digit:]]{1,}\.[[:digit:]]{1,}")
3938
echo "nuget=$version" >> $GITHUB_OUTPUT
4039
sed -i "s/{VERSION}/${version}/g" "nuspec/chocolatey/okta-aws-cli.nuspec"
41-
-
42-
name: Set Checksum
40+
41+
- name: Download and Embed Binary
4342
run: |
4443
filename="okta-aws-cli_${{ steps.version.outputs.nuget }}_windows_386.zip"
4544
url="https://github.com/${{ github.repository }}/releases/download/${{ steps.latesttag.outputs.tag }}/${filename}"
46-
sed -i "s#{ZIPURL}#${url}#g" "nuspec/chocolatey/tools/chocolateyinstall.ps1"
47-
curl -sSL "${url}" -o "nuspec/chocolatey/${filename}"
48-
sha256=$(cat "nuspec/chocolatey/${filename}" | sha256sum -)
49-
sed -i "s/{SHA256CHECKSUM}/${sha256:0:64}/g" "nuspec/chocolatey/tools/chocolateyinstall.ps1"
50-
-
51-
name: Choco Downgrade
45+
46+
# Retry download with exponential backoff to handle release asset propagation delay
47+
download_success=false
48+
for i in 1 2 3 4 5; do
49+
echo "Download attempt $i..."
50+
if curl -sSL --fail "${url}" -o "nuspec/chocolatey/tools/okta-aws-cli.zip"; then
51+
download_success=true
52+
break
53+
fi
54+
echo "Download failed, waiting $((i * 30)) seconds before retry..."
55+
sleep $((i * 30))
56+
done
57+
58+
if [ "$download_success" != "true" ]; then
59+
echo "ERROR: Failed to download release asset after 5 attempts"
60+
exit 1
61+
fi
62+
63+
# Verify the downloaded file is a valid zip archive (zip files start with "PK")
64+
if [ "$(head -c 2 "nuspec/chocolatey/tools/okta-aws-cli.zip")" != "PK" ]; then
65+
echo "ERROR: Downloaded file is not a valid zip archive"
66+
exit 1
67+
fi
68+
69+
echo "Successfully downloaded and verified binary"
70+
ls -la nuspec/chocolatey/tools/
71+
72+
- name: Choco Downgrade
5273
uses: crazy-max/ghaction-chocolatey@v3
5374
with:
5475
args: install chocolatey --version=1.2.1 --allow-downgrade -y -r --no-progress
55-
-
56-
name: Pack Release
76+
77+
- name: Pack Release
5778
uses: crazy-max/ghaction-chocolatey@v3
5879
with:
5980
args: pack nuspec/chocolatey/okta-aws-cli.nuspec --outputdirectory nuspec/chocolatey
60-
-
61-
name: Choco Upgrade
81+
82+
- name: Choco Upgrade
6283
uses: crazy-max/ghaction-chocolatey@v3
6384
with:
6485
args: upgrade chocolatey
65-
-
66-
name: Upload Release
86+
87+
- name: Upload Release
6788
uses: crazy-max/ghaction-chocolatey@v3
6889
with:
69-
args: push nuspec/chocolatey/okta-aws-cli.${{ steps.version.outputs.nuget }}.nupkg -s https://push.chocolatey.org/ -k ${{ secrets.CHOCO_API_KEY }}
90+
args: push nuspec/chocolatey/okta-aws-cli.${{ steps.version.outputs.nuget }}.nupkg -s https://push.chocolatey.org/ -k ${{ secrets.CHOCO_API_KEY }}
91+
Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
1-
21
$ErrorActionPreference = 'Stop'
3-
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
4-
5-
$packageArgs = @{
6-
packageName = $env:ChocolateyPackageName
7-
unzipLocation = $toolsDir
8-
url = '{ZIPURL}'
9-
checksum = '{SHA256CHECKSUM}'
10-
checksumType = 'sha256'
11-
}
12-
13-
Install-ChocolateyZipPackage @packageArgs
14-
15-
16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
2+
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
283

4+
# Extract the embedded zip file (no remote download needed)
5+
$zipPath = Join-Path -Path $toolsDir -ChildPath 'okta-aws-cli.zip'
6+
Get-ChocolateyUnzip -FileFullPath $zipPath -Destination $toolsDir -PackageName $env:ChocolateyPackageName
297

8+
# Clean up the zip after extraction
9+
Remove-Item -Path $zipPath -Force -ErrorAction SilentlyContinue
3010

0 commit comments

Comments
 (0)