Chocolatey Deploy #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Chocolatey Deploy | |
| # This workflow runs after the release workflow completes successfully, | |
| # ensuring release assets are available before packaging for Chocolatey. | |
| # | |
| # inspired by https://github.com/rcmaehl/MSEdgeRedirect thank you rcmaehl 🙏🙏🙏 | |
| on: | |
| workflow_run: | |
| workflows: ["release"] | |
| types: | |
| - completed | |
| workflow_dispatch: # For manual testing | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| chocolatey: | |
| runs-on: windows-latest | |
| # Only run if manually triggered OR release workflow succeeded on a tag | |
| if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v')) }} | |
| 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: Download and Embed Binary | |
| 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}" | |
| echo "Downloading ${url}..." | |
| curl -sSL --fail "${url}" -o "nuspec/chocolatey/tools/okta-aws-cli.zip" | |
| # Verify the downloaded file is a valid zip archive | |
| if [ "$(head -c 2 "nuspec/chocolatey/tools/okta-aws-cli.zip")" != "PK" ]; then | |
| echo "ERROR: Downloaded file is not a valid zip archive" | |
| exit 1 | |
| fi | |
| echo "Successfully downloaded and verified binary" | |
| ls -la nuspec/chocolatey/tools/ | |
| - 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 }} | |