From 73a90476b2bdbc99d81481e221298930c5325586 Mon Sep 17 00:00:00 2001 From: Mike Mondragon Date: Wed, 3 Jul 2024 15:15:05 -0700 Subject: [PATCH] When a GH publish completes publish the same version of okta-aws-cli to Chocolatey.org --- .github/workflows/chocolatey.yml | 69 +++++++++++++++++++ nuspec/chocolatey/okta-aws-cli.nuspec | 2 +- nuspec/chocolatey/tools/chocolateyinstall.ps1 | 5 +- 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/chocolatey.yml diff --git a/.github/workflows/chocolatey.yml b/.github/workflows/chocolatey.yml new file mode 100644 index 0000000..d59d55a --- /dev/null +++ b/.github/workflows/chocolatey.yml @@ -0,0 +1,69 @@ +name: Chocolatey Deploy + +# This GH action will push a okta-aws-cli build to chocolatey.org when a +# okta-aws-cli GH release is completed. +# +# inspired by https://github.com/rcmaehl/MSEdgeRedirect thank you rcmaehl 🙏🙏🙏 + +on: + release: + types: + - published + +defaults: + run: + shell: bash + +jobs: + chocolatey: + runs-on: windows-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Unshallow + run: git fetch --prune --unshallow + - + name: Get latest release tag + uses: oprypin/find-latest-tag@v1 + with: + repository: ${{ github.repository }} + releases-only: true + id: latesttag + - + name: Set Version + id: version + run: | + version=$(echo "${{ steps.latesttag.outputs.tag }}" | grep -oE "[[:digit:]]{1,}\.[[:digit:]]{1,}\.[[:digit:]]{1,}") + echo "nuget=$version" >> $GITHUB_OUTPUT + sed -i "s/{VERSION}/${version}/g" "nuspec/chocolatey/okta-aws-cli.nuspec" + - + name: Set Checksum + run: | + filename="okta-aws-cli_${{ steps.version.outputs.nuget }}_windows_386.zip" + url="https://github.com/${{ github.repository }}/releases/download/${{ steps.latesttag.outputs.tag }}/${filename}" + sed -i "s#{ZIPURL}#${url}#g" "nuspec/chocolatey/tools/chocolateyinstall.ps1" + curl -sSL "${url}" -o "nuspec/chocolatey/${filename}" + sha256=$(cat "nuspec/chocolatey/${filename}" | sha256sum -) + sed -i "s/{SHA256CHECKSUM}/${sha256:0:64}/g" "nuspec/chocolatey/tools/chocolateyinstall.ps1" + - + name: Choco Downgrade + uses: crazy-max/ghaction-chocolatey@v3 + with: + args: install chocolatey --version=1.2.1 --allow-downgrade -y -r --no-progress + - + name: Pack Release + uses: crazy-max/ghaction-chocolatey@v3 + with: + args: pack nuspec/chocolatey/okta-aws-cli.nuspec --outputdirectory nuspec/chocolatey + - + name: Choco Upgrade + uses: crazy-max/ghaction-chocolatey@v3 + with: + args: upgrade chocolatey + - + name: Upload Release + uses: crazy-max/ghaction-chocolatey@v3 + with: + args: push nuspec/chocolatey/okta-aws-cli.${{ steps.version.outputs.nuget }}.nupkg -s https://push.chocolatey.org/ -k ${{ secrets.CHOCO_API_KEY }} \ No newline at end of file diff --git a/nuspec/chocolatey/okta-aws-cli.nuspec b/nuspec/chocolatey/okta-aws-cli.nuspec index 512d147..4038775 100644 --- a/nuspec/chocolatey/okta-aws-cli.nuspec +++ b/nuspec/chocolatey/okta-aws-cli.nuspec @@ -3,7 +3,7 @@ okta-aws-cli - 2.0.1 + {VERSION} Okta, Inc. Okta AWS CLI (Install) Okta diff --git a/nuspec/chocolatey/tools/chocolateyinstall.ps1 b/nuspec/chocolatey/tools/chocolateyinstall.ps1 index 39da834..110ef84 100644 --- a/nuspec/chocolatey/tools/chocolateyinstall.ps1 +++ b/nuspec/chocolatey/tools/chocolateyinstall.ps1 @@ -1,13 +1,12 @@ $ErrorActionPreference = 'Stop' $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" -$url = 'https://github.com/okta/okta-aws-cli/releases/download/v2.0.1/okta-aws-cli_2.0.1_windows_386.zip' $packageArgs = @{ packageName = $env:ChocolateyPackageName unzipLocation = $toolsDir - url = $url - checksum = 'F05862D42BF14133EFA88C9F77C0AB942858CA0FFDE980D0615395E8E48FD4D6' + url = '{ZIPURL}' + checksum = '{SHA256CHECKSUM}' checksumType = 'sha256' }