Skip to content

Commit 1cb452b

Browse files
committed
fix: trigger chocolatey workflow after release workflow completes
- Use workflow_run trigger to ensure release assets are available - Embed binary in package instead of downloading at install time - Add zip validation to catch invalid downloads - Only run when release workflow succeeds on a tag
1 parent 515ae7a commit 1cb452b

File tree

2 files changed

+43
-37
lines changed

2 files changed

+43
-37
lines changed

.github/workflows/chocolatey.yml

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
name: Chocolatey Deploy
22

3-
# This GH action will push a okta-aws-cli build to chocolatey.org when a
4-
# okta-aws-cli GH release is completed.
5-
#
3+
# This workflow runs after the release workflow completes successfully,
4+
# ensuring release assets are available before packaging for Chocolatey.
5+
#
66
# inspired by https://github.com/rcmaehl/MSEdgeRedirect thank you rcmaehl 🙏🙏🙏
77

88
on:
9-
release:
9+
workflow_run:
10+
workflows: ["release"]
1011
types:
11-
- published
12+
- completed
1213

1314
defaults:
1415
run:
@@ -17,53 +18,62 @@ defaults:
1718
jobs:
1819
chocolatey:
1920
runs-on: windows-latest
21+
# Only run if the release workflow succeeded and was triggered by a tag
22+
if: ${{ github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v') }}
2023
steps:
21-
-
22-
name: Checkout
24+
- name: Checkout
2325
uses: actions/checkout@v4
24-
-
25-
name: Unshallow
26+
27+
- name: Unshallow
2628
run: git fetch --prune --unshallow
27-
-
28-
name: Get latest release tag
29+
30+
- name: Get latest release tag
2931
uses: oprypin/find-latest-tag@v1
3032
with:
3133
repository: ${{ github.repository }}
3234
releases-only: true
3335
id: latesttag
34-
-
35-
name: Set Version
36+
37+
- name: Set Version
3638
id: version
3739
run: |
3840
version=$(echo "${{ steps.latesttag.outputs.tag }}" | grep -oE "[[:digit:]]{1,}\.[[:digit:]]{1,}\.[[:digit:]]{1,}")
3941
echo "nuget=$version" >> $GITHUB_OUTPUT
4042
sed -i "s/{VERSION}/${version}/g" "nuspec/chocolatey/okta-aws-cli.nuspec"
41-
-
42-
name: Set Checksum
43+
44+
- name: Download and Embed Binary
4345
run: |
4446
filename="okta-aws-cli_${{ steps.version.outputs.nuget }}_windows_386.zip"
4547
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
48+
49+
echo "Downloading ${url}..."
50+
curl -sSL --fail "${url}" -o "nuspec/chocolatey/tools/okta-aws-cli.zip"
51+
52+
# Verify the downloaded file is a valid zip archive
53+
if [ "$(head -c 2 "nuspec/chocolatey/tools/okta-aws-cli.zip")" != "PK" ]; then
54+
echo "ERROR: Downloaded file is not a valid zip archive"
55+
exit 1
56+
fi
57+
58+
echo "Successfully downloaded and verified binary"
59+
ls -la nuspec/chocolatey/tools/
60+
61+
- name: Choco Downgrade
5262
uses: crazy-max/ghaction-chocolatey@v3
5363
with:
5464
args: install chocolatey --version=1.2.1 --allow-downgrade -y -r --no-progress
55-
-
56-
name: Pack Release
65+
66+
- name: Pack Release
5767
uses: crazy-max/ghaction-chocolatey@v3
5868
with:
5969
args: pack nuspec/chocolatey/okta-aws-cli.nuspec --outputdirectory nuspec/chocolatey
60-
-
61-
name: Choco Upgrade
70+
71+
- name: Choco Upgrade
6272
uses: crazy-max/ghaction-chocolatey@v3
6373
with:
6474
args: upgrade chocolatey
65-
-
66-
name: Upload Release
75+
76+
- name: Upload Release
6777
uses: crazy-max/ghaction-chocolatey@v3
6878
with:
6979
args: push nuspec/chocolatey/okta-aws-cli.${{ steps.version.outputs.nuget }}.nupkg -s https://push.chocolatey.org/ -k ${{ secrets.CHOCO_API_KEY }}

nuspec/chocolatey/tools/chocolateyinstall.ps1

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
21
$ErrorActionPreference = 'Stop'
3-
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
2+
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
43

5-
$packageArgs = @{
6-
packageName = $env:ChocolateyPackageName
7-
unzipLocation = $toolsDir
8-
url = '{ZIPURL}'
9-
checksum = '{SHA256CHECKSUM}'
10-
checksumType = 'sha256'
11-
}
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
127

13-
Install-ChocolateyZipPackage @packageArgs
8+
# Clean up the zip after extraction
9+
Remove-Item -Path $zipPath -Force -ErrorAction SilentlyContinue
1410

1511

1612

0 commit comments

Comments
 (0)