11name : 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
88on :
9- release :
9+ workflow_run :
10+ workflows : ["release"]
1011 types :
11- - published
12+ - completed
1213
1314defaults :
1415 run :
@@ -17,53 +18,62 @@ defaults:
1718jobs :
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 }}
0 commit comments