Skip to content

Commit

Permalink
chore: native binary distribution via winget (#430)
Browse files Browse the repository at this point in the history
* chore: create the windows binary, installer and publish to winget
  • Loading branch information
neilcampbell authored Jul 29, 2024
1 parent d6277e6 commit d4759d6
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 29 deletions.
76 changes: 67 additions & 9 deletions .github/actions/build-binaries/windows/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,87 @@ inputs:
package_name:
description: "The name of the package"
required: true
version:
description: "The version to use for this artifact"
artifacts_dir:
description: "The directory to write artifacts you want to publish"
required: true
version:
description: "The version to use for this artifact"
production_release:
description: "Flag to determine if this is a production release"
required: true
azure_tenant_id:
description: "The Microsoft Entra tenant (directory) ID."
required: true
azure_client_id:
description: "The client (application) ID of an App Registration in the tenant."
required: true
azure_client_secret:
description: "A client secret that was generated for the App Registration."
required: true

runs:
using: "composite"
steps:
- name: Configure build environment
shell: bash
run: |
echo 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64' >> $GITHUB_PATH
echo 'BINARY_BUILD_DIR=dist\algokit' >> $GITHUB_ENV
echo 'WINGET_INSTALLER=${{ inputs.artifacts_dir }}\${{ inputs.package_name }}-winget.msix' >> $GITHUB_ENV
- name: Build binary
shell: bash
run: |
poetry run poe package_windows
- name: Package binary artifact
- name: Add metadata to binary
shell: bash
run: |
echo winget > '${{ env.BINARY_BUILD_DIR }}\_internal\algokit\resources\distribution-method'
- name: Sign executable
if: ${{ inputs.production_release == 'true' }}
uses: azure/[email protected]
with:
azure-tenant-id: ${{ inputs.azure_tenant_id }}
azure-client-id: ${{ inputs.azure_client_id }}
azure-client-secret: ${{ inputs.azure_client_secret }}
endpoint: https://weu.codesigning.azure.net/
trusted-signing-account-name: algokit-signing
certificate-profile-name: algokit
files-folder: ${{ env.BINARY_BUILD_DIR }}
files-folder-filter: exe
file-digest: SHA256
timestamp-rfc3161: http://timestamp.acs.microsoft.com
timestamp-digest: SHA256

- name: Build winget installer
shell: pwsh
run: |
Set-Location -Path dist\algokit\
tar -zcf ${{ inputs.artifacts_dir }}\${{ inputs.package_name }}.tar.gz *
Set-Location -Path ..\..
& .\scripts\winget\build-installer.ps1 `
-binaryDir '${{ env.BINARY_BUILD_DIR }}' `
-releaseVersion '${{ inputs.version }}' `
-outputFile '${{ env.WINGET_INSTALLER }}'
- name: Sign winget installer
if: ${{ inputs.production_release == 'true' }}
uses: azure/[email protected]
with:
azure-tenant-id: ${{ inputs.azure_tenant_id }}
azure-client-id: ${{ inputs.azure_client_id }}
azure-client-secret: ${{ inputs.azure_client_secret }}
endpoint: https://weu.codesigning.azure.net/
trusted-signing-account-name: algokit-signing
certificate-profile-name: algokit
files-folder: ${{ env.WINGET_INSTALLER }}
files-folder-filter: msix
file-digest: SHA256
timestamp-rfc3161: http://timestamp.acs.microsoft.com
timestamp-digest: SHA256

- name: Upload binary artifact
- name: Upload winget artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.package_name }}
path: ${{ inputs.artifacts_dir }}\${{ inputs.package_name }}.tar.gz
name: ${{ inputs.package_name }}-winget
path: ${{ env.WINGET_INSTALLER }}
if-no-files-found: error
4 changes: 4 additions & 0 deletions .github/workflows/build-binaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ jobs:
package_name: ${{ env.PACKAGE_NAME }}
version: ${{ env.RELEASE_VERSION }}
artifacts_dir: ${{ env.ARTIFACTS_DIR }}
production_release: ${{ inputs.production_release }}
azure_tenant_id: ${{ secrets.AZURE_TENANT_ID }}
azure_client_id: ${{ secrets.AZURE_CLIENT_ID }}
azure_client_secret: ${{ secrets.AZURE_CLIENT_SECRET }}

- name: Build linux binary
if: ${{ runner.os == 'Linux' }}
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/publish-release-packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ on:
default: true
type: boolean
description: "Publish to snap repository"
do_winget:
required: false
default: true
type: boolean
description: "Publish to Winget repository"
workflow_dispatch:
inputs:
release:
Expand All @@ -38,6 +43,11 @@ on:
default: true
type: boolean
description: "Publish to Chocolatey repository"
do_winget:
required: false
default: true
type: boolean
description: "Publish to Winget repository"
do_snap:
required: false
default: true
Expand Down Expand Up @@ -114,6 +124,20 @@ jobs:
with:
args: push --source https://push.chocolatey.org/

publish-winget:
runs-on: windows-latest
if: ${{ inputs.do_winget }}
steps:
- name: Publish to winget
shell: pwsh
env:
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 }}'
publish-snap:
runs-on: ubuntu-latest
if: ${{ inputs.do_snap }}
Expand Down
38 changes: 19 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ aiohttp = "3.9.5"
jsondiff = "^2.0.0"

[tool.poetry.group.dev.dependencies]
pyinstaller = {version = "^6.3.0"}
pyinstaller = {version = "^6.9.0"}
pytest = "^7.2.0"
ruff = ">=0.1.6,<0.5.0"
pip-audit = "^2.4.7"
Expand Down
56 changes: 56 additions & 0 deletions scripts/winget/build-installer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Param(
[Parameter(Mandatory = $true)]
[String]
$binaryDir,

[Parameter(Mandatory = $false)]
[AllowEmptyString()]
[String]
$releaseVersion,

[Parameter(Mandatory = $true)]
[String]
$outputFile
)

Function ThrowOnNonZeroExit {
Param( [String]$Message )
If ($LastExitCode -ne 0) {
Throw $Message
}
}

$ErrorActionPreference = 'Stop'

Remove-Item -Path build -Recurse -ErrorAction Ignore
$buildDir = New-Item -ItemType Directory -Path .\build\winget\installer
$installerContentDir = '.\scripts\winget\installer'

# Add installer assets
$assetsDir = New-Item -ItemType Directory -Path (Join-Path $buildDir assets)
Copy-Item -Path "$installerContentDir\assets\*" -Destination $assetsDir -Recurse | Out-Null

# Add manifest file
$version = if ($releaseVersion) {
# Strip the pre-release meta, as it's not valid
$releaseVersion -replace '-\w+|\+.+$', ''
}
else {
'0.0.1'
}
(Get-Content (Resolve-Path "$installerContentDir\AppxManifest.xml")).Replace('0.0.1.0', $("$version.0")) | Set-Content (Join-Path $buildDir AppxManifest.xml)

# Generate pri resource map for installer assets
$priConfig = (Resolve-Path "$installerContentDir\priconfig.xml")
Push-Location $buildDir
makepri new /ProjectRoot $buildDir /ConfigXml $priConfig | Out-Null
ThrowOnNonZeroExit "Failed to create pri file"
Pop-Location

# Add algokit binaries
Copy-Item -Path (Join-Path $binaryDir *) -Destination $buildDir -Recurse | Out-Null

# Generate msix
makeappx pack /o /h SHA256 /d $buildDir /p $outputFile | Out-Null
ThrowOnNonZeroExit "Failed to build msix"

33 changes: 33 additions & 0 deletions scripts/winget/installer/AppxManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" IgnorableNamespaces="uap uap3 uap10 desktop rescap">
<Identity Name="algokit" Publisher="CN=Algorand Foundation, O=Algorand Foundation, L=Singapore, C=SG" Version="0.0.1.0" ProcessorArchitecture="x64" />
<Properties>
<DisplayName>AlgoKit</DisplayName>
<PublisherDisplayName>Algorand Foundation</PublisherDisplayName>
<Description>The Algorand AlgoKit CLI is the one-stop shop tool for developers building on the Algorand network.</Description>
<Logo>assets\Square70x70Logo.png</Logo>
</Properties>
<Resources>
<Resource Language="en-us" />
</Resources>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.22000.0" />
</Dependencies>
<Applications>
<Application Id="algokit" Executable="algokit.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements BackgroundColor="transparent" DisplayName="Algorand AlgoKit CLI" Square150x150Logo="assets\Square150x150Logo.png" Square44x44Logo="assets\Square44x44Logo.png" Description="The Algorand AlgoKit CLI is the one-stop shop tool for developers building on the Algorand network.">
<uap:DefaultTile ShortName="AlgoKit" Square71x71Logo="assets\Square70x70Logo.png" />
</uap:VisualElements>
<Extensions>
<uap3:Extension Category="windows.appExecutionAlias">
<uap3:AppExecutionAlias>
<desktop:ExecutionAlias Alias="algokit.exe" />
</uap3:AppExecutionAlias>
</uap3:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scripts/winget/installer/assets/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions scripts/winget/installer/priconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resources targetOsVersion="10.0.0" majorVersion="1">
<packaging>
<autoResourcePackage qualifier="Language"/>
<autoResourcePackage qualifier="Scale"/>
<autoResourcePackage qualifier="DXFeatureLevel"/>
</packaging>
<index root="\" startIndexAt="\">
<default>
<qualifier name="Language" value="en-US"/>
<qualifier name="Contrast" value="standard"/>
<qualifier name="Scale" value="100"/>
<qualifier name="HomeRegion" value="001"/>
<qualifier name="TargetSize" value="256"/>
<qualifier name="LayoutDirection" value="LTR"/>
<qualifier name="Theme" value="dark"/>
<qualifier name="AlternateForm" value=""/>
<qualifier name="DXFeatureLevel" value="DX9"/>
<qualifier name="Configuration" value=""/>
<qualifier name="DeviceFamily" value="Universal"/>
<qualifier name="Custom" value=""/>
</default>
<indexer-config type="folder" foldernameAsQualifier="true" filenameAsQualifier="true" qualifierDelimiter="."/>
<indexer-config type="resw" convertDotsToSlashes="true" initialPath=""/>
<indexer-config type="resjson" initialPath=""/>
<indexer-config type="PRI"/>
</index>
<!--<index startIndexAt="Start Index Here" root="Root Here">-->
<!-- <indexer-config type="resfiles" qualifierDelimiter="."/>-->
<!-- <indexer-config type="priinfo" emitStrings="true" emitPaths="true" emitEmbeddedData="true"/>-->
<!--</index>-->
</resources>
23 changes: 23 additions & 0 deletions scripts/winget/update-package.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Param(
[Parameter(Mandatory=$true)]
[String]
$releaseVersionTag
)

Function ThrowOnNonZeroExit {
Param( [String]$Message )
If ($LastExitCode -ne 0) {
Throw $Message
}
}

$wingetPackage = 'AlgorandFoundation.AlgoKit'
$release = Invoke-RestMethod -uri "https://api.github.com/repos/algorandfoundation/algokit-cli/releases/tags/$releaseVersionTag"
$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"
Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile $wingetExecutable
& $wingetExecutable update $wingetPackage -s -v $releaseVersion -u "$installerUrl" -t "$env:WINGET_GITHUB_TOKEN"
ThrowOnNonZeroExit "Failed to update winget package"

1 comment on commit d4759d6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/algokit
   __init__.py15753%6–13, 17–24, 32–34
   __main__.py440%1–7
src/algokit/cli
   __init__.py47394%31–34
   codespace.py50982%28, 114, 137, 150–155
   completions.py108992%63–64, 83, 93–99
   dispenser.py121199%77
   doctor.py53394%146–148
   explore.py541474%34–39, 41–46, 84–91
   generate.py70396%76–77, 155
   goal.py47198%79
   init.py3112492%497–498, 503–504, 507, 528, 531–533, 544, 548, 606, 632, 661, 694, 703–705, 708–713, 726, 745, 757–758
   localnet.py1523279%65, 86–113, 133–137, 170, 182, 197–207, 220, 271, 292–293
   task.py34391%25–28
src/algokit/cli/project
   bootstrap.py32197%33
   deploy.py992080%47, 49, 101, 124, 146–148, 227, 234, 248–256, 259–268
   link.py891682%60, 65–66, 101–105, 115–120, 148–149, 218–219, 223
   list.py33585%21–23, 51–56
   run.py46393%38, 71, 160
src/algokit/cli/tasks
   analyze.py81199%81
   assets.py821384%65–66, 72, 74–75, 105, 119, 125–126, 132, 134, 136–137
   ipfs.py51884%52, 80, 92, 94–95, 105–107
   mint.py66494%48, 70, 91, 250
   send_transaction.py651085%52–53, 57, 89, 158, 170–174
   sign_transaction.py59886%21, 28–30, 71–72, 109, 123
   transfer.py39392%26, 90, 117
   utils.py994555%26–34, 40–43, 75–76, 100–101, 125–133, 152–162, 209, 258–259, 279–290, 297–299
   vanity_address.py561082%41, 45–48, 112, 114, 121–123
   wallet.py79495%21, 66, 136, 162
src/algokit/core
   codespace.py1756861%34–37, 41–44, 48–71, 111–112, 125–133, 191, 200–202, 210, 216–217, 229–236, 251–298, 311–313, 338–344, 348, 395
   conf.py57984%12, 24, 28, 36, 38, 73–75, 80
   dispenser.py2022687%91, 123–124, 141–149, 191–192, 198–200, 218–219, 259–260, 318, 332–334, 345–346, 356, 369, 384
   doctor.py65789%67–69, 92–94, 134
   generate.py50394%44, 85, 103
   goal.py65494%21, 36–37, 47
   init.py671085%53, 57–62, 70, 81, 88, 108–109
   log_handlers.py68790%50–51, 63, 112–116, 125
   proc.py45198%99
   sandbox.py2632391%32, 89–92, 97, 101–103, 153, 201–208, 219, 590, 606, 631, 639
   typed_client_generation.py1702088%62–64, 103–108, 132, 135–138, 156, 159–162, 229, 232–235
   utils.py1484073%50–51, 57–69, 125–131, 155, 158, 164–177, 198–200, 229–232, 254
src/algokit/core/compilers
   python.py28582%19–20, 25, 49–50
src/algokit/core/config_commands
   container_engine.py412149%24, 29–31, 47–76
   version_prompt.py921485%37–38, 68, 87–90, 108, 118–125, 148
src/algokit/core/project
   __init__.py53394%50, 86, 145
   bootstrap.py120893%47, 126–127, 149, 176, 207–209
   deploy.py69987%108–111, 120–122, 126, 131
   run.py1251588%83, 88, 97–98, 133–134, 138–139, 143, 147, 261–269, 284
src/algokit/core/tasks
   analyze.py93397%105–112, 187
   ipfs.py63789%58–64, 140, 144, 146, 152
   nfd.py491373%25, 31, 34–41, 70–72, 99–101
   vanity_address.py903462%49–50, 54, 59–75, 92–108, 128–131
   wallet.py71593%37, 129, 155–157
src/algokit/core/tasks/mint
   mint.py781087%123–133, 187
   models.py901188%50, 52, 57, 71–74, 85–88
TOTAL465064086% 

Tests Skipped Failures Errors Time
488 0 💤 0 ❌ 0 🔥 27.050s ⏱️

Please sign in to comment.