Skip to content

Commit

Permalink
chore: add winget cd support
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcampbell committed Aug 2, 2024
1 parent 3e2d017 commit f08c074
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ jobs:

cd-publish-release-packages:
name: Release binaries via distribution channels
needs: build-and-upload-binaries
needs:
- release
- build-and-upload-binaries
if: ${{ github.ref_name == 'main' && inputs.production_release == 'true' }} # Might want to adjust this to publish (pre-release) on merge as well.
uses: ./.github/workflows/publish-release-packages.yaml
with:
artifactName: algokit-cli
release_version: ${{ needs.release.outputs.release_version }}
secrets: inherit
35 changes: 13 additions & 22 deletions .github/workflows/publish-release-packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
required: true
type: string
description: "The github artifact holding the wheel file which will be published"
release_version:
required: true
type: string
description: "The release version that will be published (e.g. 0.1.0)"
do_brew:
required: false
default: true
Expand All @@ -29,10 +33,10 @@ on:
description: "Publish to Winget repository"
workflow_dispatch:
inputs:
release:
release_version:
required: true
type: string
description: "The existing github release which will be published (e.g. v0.1.0)"
description: "The release version that will be published (e.g. 0.1.0). Note this is not the tag version."
do_brew:
required: false
default: true
Expand Down Expand Up @@ -65,7 +69,7 @@ jobs:
# Download either via release or provided artifact
- name: Download release
if: ${{ github.event_name == 'workflow_dispatch' }}
run: gh release download ${{ inputs.release }} --pattern "*.whl" --dir dist
run: gh release download v${{ inputs.release_version }} --pattern "*.whl" --dir dist
env:
GH_TOKEN: ${{ github.token }}

Expand Down Expand Up @@ -94,7 +98,7 @@ jobs:
# Download either via release or provided artifact
- name: Download release
if: ${{ github.event_name == 'workflow_dispatch' }}
run: gh release download ${{ inputs.release }} --pattern "*.whl" --dir dist
run: gh release download v${{ inputs.release_version }} --pattern "*.whl" --dir dist
env:
GH_TOKEN: ${{ github.token }}

Expand Down Expand Up @@ -134,9 +138,8 @@ jobs:
WINGET_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
run: |
echo 'Publishing to winget'
# The below can be uncommented after we've manually created the first release on winget
# & .\scripts\winget\update-package.ps1 `
# -releaseVersionTag '${{ inputs.release }}'
& .\scripts\winget\update-package.ps1 `
-releaseVersion '${{ inputs.release_version }}'
publish-snap:
runs-on: ubuntu-latest
Expand All @@ -146,31 +149,19 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set release version
shell: bash
continue-on-error: true
run: |
if [ -z "${{ inputs.release }}" ]; then
echo "RELEASE_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_ENV
git describe --tags $(git rev-list --tags --max-count=1)
else
echo "RELEASE_VERSION=${{ inputs.release }}" >> $GITHUB_ENV
fi
fetch-depth: 1

- name: Download binary artifact from release
if: ${{ env.RELEASE_VERSION != '' || (github.event_name == 'workflow_dispatch' && inputs.release != '') }}
run: |
gh release download ${{ env.RELEASE_VERSION || inputs.release }} --pattern "*-snap.tar.gz" --dir dist
gh release download v${{ inputs.release_version }} --pattern "*-snap.tar.gz" --dir dist
BINARY_PATH=$(ls dist/*-snap.tar.gz)
echo "BINARY_PATH=$BINARY_PATH" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ github.token }}

- name: Generate snapcraft.yaml
run: |
./scripts/snap/create-snapcraft-yaml.sh ${{ github.workspace }} ${{ env.RELEASE_VERSION }} ${{ env.BINARY_PATH }} "stable"
./scripts/snap/create-snapcraft-yaml.sh ${{ github.workspace }} ${{ inputs.release_version }} ${{ env.BINARY_PATH }} "stable"
- name: Upload snapcraft.yaml as reference artifact
uses: actions/upload-artifact@v2
Expand Down
9 changes: 3 additions & 6 deletions scripts/snap/create-snapcraft-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,26 @@ set -e

# Check if the correct number of arguments are passed
if [ "$#" -ne 4 ]; then
echo "Usage: $0 <destination_directory> <release_tag> <artifact_path> <grade>"
echo "Usage: $0 <destination_directory> <release_version> <artifact_path> <grade>"
exit 1
fi

# Assign arguments to variables
DESTINATION_DIR="$1"
RELEASE_TAG="$2"
RELEASE_VERSION="$2"
ARTIFACT_PATH="$3"
GRADE="$4"

# Ensure the destination directory exists
mkdir -p "${DESTINATION_DIR}/snap"

# Extract version from RELEASE_TAG, assuming it's in the format "vX.Y.Z"
VERSION="${RELEASE_TAG#v}"

# Use the provided ARTIFACT_PATH
SOURCE="$ARTIFACT_PATH"

# Create the snapcraft.yaml file
cat > "${DESTINATION_DIR}/snap/snapcraft.yaml" <<EOF
name: algokit
version: "$VERSION"
version: "$RELEASE_VERSION"
summary: The AlgoKit CLI is the one-stop shop tool for developers building on Algorand
description: |
AlgoKit gets developers of all levels up and running with a familiar,
Expand Down
7 changes: 3 additions & 4 deletions scripts/winget/update-package.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Param(
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[String]
$releaseVersionTag
$releaseVersion
)

Function ThrowOnNonZeroExit {
Expand All @@ -12,9 +12,8 @@ Function ThrowOnNonZeroExit {
}

$wingetPackage = 'AlgorandFoundation.AlgoKit'
$release = Invoke-RestMethod -uri "https://api.github.com/repos/algorandfoundation/algokit-cli/releases/tags/$releaseVersionTag"
$release = Invoke-RestMethod -uri "https://api.github.com/repos/algorandfoundation/algokit-cli/releases/tags/v$releaseVersion"
$installerUrl = $release | Select -ExpandProperty assets -First 1 | Where-Object -Property name -match '-windows_x64-winget\.msix$' | Select -ExpandProperty browser_download_url
$releaseVersion = $releaseVersionTag.Trim("v")

$wingetDir = New-Item -Force -ItemType Directory -Path .\build\winget
$wingetExecutable = "$wingetDir\wingetcreate.exe"
Expand Down

0 comments on commit f08c074

Please sign in to comment.