-
Notifications
You must be signed in to change notification settings - Fork 0
Chocolatey support #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ffc60d1
ff98642
b1a4af0
b903f58
160aa55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ dist/ | |
| *.toc | ||
| *.pyz | ||
| *.zip | ||
| *.nupkg | ||
| warn-*.txt | ||
| xref-*.html | ||
| localpycs/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?xml version="1.0"?> | ||
| <package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd"> | ||
| <metadata> | ||
| <id>slcli</id> | ||
| <version>$version$</version> | ||
| <title>SystemLink CLI</title> | ||
| <authors>NI</authors> | ||
| <owners>NI</owners> | ||
| <projectUrl>https://github.com/ni-kismet/systemlink-cli</projectUrl> | ||
| <license type="expression">MIT</license> | ||
| <requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
| <summary>SystemLink Command Line Interface</summary> | ||
| <description>SystemLink CLI provides management and automation for SystemLink resources (workspaces, functions, notebooks, executions, etc.).</description> | ||
| <tags>systemlink ni cli automation</tags> | ||
| <packageSourceUrl>https://github.com/ni-kismet/systemlink-cli</packageSourceUrl> | ||
| <docsUrl>https://github.com/ni-kismet/systemlink-cli#readme</docsUrl> | ||
| <bugTrackerUrl>https://github.com/ni-kismet/systemlink-cli/issues</bugTrackerUrl> | ||
| <iconUrl>https://raw.githubusercontent.com/ni-kismet/systemlink-cli/main/docs/icon.png</iconUrl> | ||
| <releaseNotes>See CHANGELOG.md in the repository.</releaseNotes> | ||
| </metadata> | ||
| <files> | ||
| <!-- No embedded binaries: install script downloads release artifact --> | ||
| <file src="tools\**" target="tools" /> | ||
| </files> | ||
| </package> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| $packageName = 'slcli' | ||
| $toolsDir = Split-Path -Parent $MyInvocation.MyCommand.Definition | ||
|
|
||
| # Version is inferred from nuspec; construct download URL | ||
| # Use the Chocolatey provided variable if available | ||
| # '$version$' is a build-time token that should be replaced during packaging. | ||
| if ($env:ChocolateyPackageVersion) { $version = $env:ChocolateyPackageVersion } else { $version = '$version$' } | ||
| if ($version -eq '$version$') { | ||
| throw "The package version could not be determined. Ensure that the build-time token `\$version\$` is replaced or the ChocolateyPackageVersion environment variable is set." | ||
| } | ||
|
|
||
| $zipName = "slcli.zip" | ||
| $downloadUrl = "https://github.com/ni-kismet/systemlink-cli/releases/download/v$version/$zipName" | ||
| $tempZip = Join-Path $toolsDir $zipName | ||
|
|
||
| Write-Host "Downloading slcli $version from $downloadUrl" | ||
| Get-ChocolateyWebFile -PackageName $packageName -FileFullPath $tempZip -Url $downloadUrl -Checksum '$checksum$' -ChecksumType 'sha256' | ||
|
|
||
| Write-Host 'Extracting archive' | ||
| Get-ChocolateyUnzip -FileFullPath $tempZip -Destination $toolsDir | ||
|
|
||
| # Optional: remove zip after extraction | ||
| Remove-Item $tempZip -Force -ErrorAction SilentlyContinue | ||
|
|
||
| # Chocolatey will shim slcli.exe in the extracted folder (assumed root of zip) | ||
| Write-Host 'slcli installation complete.' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| $packageName = 'slcli' | ||
| $toolsDir = Split-Path -Parent $MyInvocation.MyCommand.Definition | ||
|
|
||
| Write-Host 'Removing slcli files' | ||
| # Rely on Chocolatey shim removal; optionally cleanup extracted directory | ||
| # Keep minimal to avoid removing user data unexpectedly | ||
| Write-Host 'Uninstall complete.' |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,150 @@ | ||||||||||||||
| """Build a Chocolatey package for slcli (nupkg) using remote artifact download model. | ||||||||||||||
|
|
||||||||||||||
| Steps: | ||||||||||||||
| 1. Ensure dist/slcli.zip (Windows binary zip) exists or has been uploaded to release. | ||||||||||||||
| 2. Read version from pyproject.toml. | ||||||||||||||
| 3. Copy nuspec & tools scripts to a temp build dir (or pack in place) and run `choco pack`. | ||||||||||||||
| 4. Output .nupkg to dist/. | ||||||||||||||
|
|
||||||||||||||
| This script expects to run on Windows with Chocolatey available in PATH. | ||||||||||||||
| """ | ||||||||||||||
|
|
||||||||||||||
| from __future__ import annotations | ||||||||||||||
|
|
||||||||||||||
| import hashlib | ||||||||||||||
| import shutil | ||||||||||||||
| import subprocess | ||||||||||||||
| import sys | ||||||||||||||
| from pathlib import Path | ||||||||||||||
|
|
||||||||||||||
| import toml | ||||||||||||||
|
|
||||||||||||||
| ROOT = Path(__file__).parent.parent.resolve() | ||||||||||||||
| DIST = ROOT / "dist" | ||||||||||||||
| PYPROJECT = ROOT / "pyproject.toml" | ||||||||||||||
| CHOCO_DIR = ROOT / "packaging" / "choco" | ||||||||||||||
| NUSPEC = CHOCO_DIR / "slcli.nuspec" | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def get_version() -> str: | ||||||||||||||
| """Return project version from pyproject.toml.""" | ||||||||||||||
| data = toml.load(PYPROJECT) | ||||||||||||||
| return data["tool"]["poetry"]["version"] | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def ensure_dist() -> None: | ||||||||||||||
| """Ensure dist directory exists.""" | ||||||||||||||
| DIST.mkdir(parents=True, exist_ok=True) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def prepare_nuspec(version: str, work_dir: Path) -> Path: | ||||||||||||||
| """Copy nuspec and replace $version$ token. | ||||||||||||||
|
|
||||||||||||||
| Args: | ||||||||||||||
| version: semantic version string | ||||||||||||||
| work_dir: working temp directory | ||||||||||||||
| Returns: | ||||||||||||||
| Path to prepared nuspec | ||||||||||||||
| """ | ||||||||||||||
| target = work_dir / "slcli.nuspec" | ||||||||||||||
| content = NUSPEC.read_text(encoding="utf-8").replace("$version$", version) | ||||||||||||||
|
||||||||||||||
| content = NUSPEC.read_text(encoding="utf-8").replace("$version$", version) | |
| content = NUSPEC.read_text(encoding="utf-8") | |
| if "$version$" not in content: | |
| print("✗ Error: $version$ token not found in nuspec template.", file=sys.stderr) | |
| sys.exit(1) | |
| content = content.replace("$version$", version) |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The checksum token is mandatory for Chocolatey package security (as mentioned in the PR description). If the $checksum$ token is not found in the install script, the function should exit with an error rather than just printing a warning and continuing. This would prevent accidentally packaging an install script without checksum verification, which would be a security issue.
| print("Warning: checksum token not found in install script", file=sys.stderr) | |
| return | |
| print("✗ Error: checksum token ($checksum$) not found in install script. Aborting build.", file=sys.stderr) | |
| sys.exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In PowerShell, the proper way to escape a dollar sign in a double-quoted string is with a backtick, not a backslash. The current usage of
\$version\$should be written as`$version`$to correctly display the literal text "$version$" in the error message. While the current code may work, it doesn't follow PowerShell conventions and could be confusing.