Skip to content

Commit 2f2affd

Browse files
authored
fix: trigger chocolatey workflow after release workflow completes (#306)
1 parent 515ae7a commit 2f2affd

File tree

3 files changed

+58
-67
lines changed

3 files changed

+58
-67
lines changed

.github/workflows/chocolatey.yml

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
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
13+
workflow_dispatch: # Manual trigger for re-runs if needed
1214

1315
defaults:
1416
run:
@@ -17,53 +19,62 @@ defaults:
1719
jobs:
1820
chocolatey:
1921
runs-on: windows-latest
22+
# Only run if manually triggered OR release workflow succeeded on a tag
23+
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v')) }}
2024
steps:
21-
-
22-
name: Checkout
25+
- name: Checkout
2326
uses: actions/checkout@v4
24-
-
25-
name: Unshallow
27+
28+
- name: Unshallow
2629
run: git fetch --prune --unshallow
27-
-
28-
name: Get latest release tag
30+
31+
- name: Get latest release tag
2932
uses: oprypin/find-latest-tag@v1
3033
with:
3134
repository: ${{ github.repository }}
3235
releases-only: true
3336
id: latesttag
34-
-
35-
name: Set Version
37+
38+
- name: Set Version
3639
id: version
3740
run: |
3841
version=$(echo "${{ steps.latesttag.outputs.tag }}" | grep -oE "[[:digit:]]{1,}\.[[:digit:]]{1,}\.[[:digit:]]{1,}")
3942
echo "nuget=$version" >> $GITHUB_OUTPUT
4043
sed -i "s/{VERSION}/${version}/g" "nuspec/chocolatey/okta-aws-cli.nuspec"
41-
-
42-
name: Set Checksum
44+
45+
- name: Download and Embed Binary
4346
run: |
4447
filename="okta-aws-cli_${{ steps.version.outputs.nuget }}_windows_386.zip"
4548
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
49+
50+
echo "Downloading ${url}..."
51+
curl -sSL --fail "${url}" -o "nuspec/chocolatey/tools/okta-aws-cli.zip"
52+
53+
# Verify the downloaded file is a valid zip archive
54+
if [ "$(head -c 2 "nuspec/chocolatey/tools/okta-aws-cli.zip")" != "PK" ]; then
55+
echo "ERROR: Downloaded file is not a valid zip archive"
56+
exit 1
57+
fi
58+
59+
echo "Successfully downloaded and verified binary"
60+
ls -la nuspec/chocolatey/tools/
61+
62+
- name: Choco Downgrade
5263
uses: crazy-max/ghaction-chocolatey@v3
5364
with:
5465
args: install chocolatey --version=1.2.1 --allow-downgrade -y -r --no-progress
55-
-
56-
name: Pack Release
66+
67+
- name: Pack Release
5768
uses: crazy-max/ghaction-chocolatey@v3
5869
with:
5970
args: pack nuspec/chocolatey/okta-aws-cli.nuspec --outputdirectory nuspec/chocolatey
60-
-
61-
name: Choco Upgrade
71+
72+
- name: Choco Upgrade
6273
uses: crazy-max/ghaction-chocolatey@v3
6374
with:
6475
args: upgrade chocolatey
65-
-
66-
name: Upload Release
76+
77+
- name: Upload Release
6778
uses: crazy-max/ghaction-chocolatey@v3
6879
with:
69-
args: push nuspec/chocolatey/okta-aws-cli.${{ steps.version.outputs.nuget }}.nupkg -s https://push.chocolatey.org/ -k ${{ secrets.CHOCO_API_KEY }}
80+
args: push nuspec/chocolatey/okta-aws-cli.${{ steps.version.outputs.nuget }}.nupkg -s https://push.chocolatey.org/ -k ${{ secrets.CHOCO_API_KEY }}

.github/workflows/release.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ on:
55
- master
66
- m2m_feature
77
tags:
8-
- 'v*'
8+
- "v*"
99
jobs:
1010
goreleaser:
1111
runs-on: ubuntu-latest
1212
steps:
13-
-
14-
name: Checkout
13+
- name: Checkout
1514
uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f #v3.4.0
16-
-
17-
name: Unshallow
15+
16+
- name: Unshallow
1817
run: git fetch --prune --unshallow
19-
-
20-
name: Set up Go
18+
19+
- name: Set up Go
2120
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 #v3.5.0
2221
with:
2322
go-version: 1.21
24-
-
25-
name: Import GPG key
23+
24+
- name: Import GPG key
2625
id: import_gpg
27-
uses: crazy-max/ghaction-import-gpg@111c56156bcc6918c056dbef52164cfa583dc549 #v5.2.0
26+
uses:
27+
crazy-max/ghaction-import-gpg@111c56156bcc6918c056dbef52164cfa583dc549 #v5.2.0
2828
# These secrets will need to be configured for the repository:
2929
with:
3030
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
3131
passphrase: ${{ secrets.PASSPHRASE }}
32-
-
33-
name: Run GoReleaser
32+
33+
- name: Run GoReleaser
3434
uses: goreleaser/goreleaser-action@v6.0.0
3535
with:
36-
version: '~> v2'
36+
version: "~> v2"
3737
args: release --clean
3838
env:
3939
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
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)