mirror of
https://github.com/supermerill/SuperSlicer.git
synced 2026-11-26 23:29:04 +00:00
Submit signed stable MSI packages to Chocolatey
This commit is contained in:
parent
a86d317435
commit
13fafa1b76
9 changed files with 813 additions and 0 deletions
59
.github/chocolatey/Pack-Release.ps1
vendored
Normal file
59
.github/chocolatey/Pack-Release.ps1
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
param(
|
||||
[Parameter(Mandatory = $true)][string]$MetadataPath,
|
||||
[Parameter(Mandatory = $true)][string]$WorkDirectory,
|
||||
[Parameter(Mandatory = $true)][string]$OutputDirectory
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version Latest
|
||||
$metadata = Get-Content -LiteralPath $MetadataPath -Raw | ConvertFrom-Json
|
||||
$tag = $metadata.source_version
|
||||
if ($tag -notmatch '^\d+\.\d+\.\d+\.\d+$') { throw 'Invalid stable release tag' }
|
||||
$expectedUrl = "https://github.com/supermerill/SuperSlicer/releases/download/$tag/SuperSlicer_${tag}_win64.msi"
|
||||
if ($metadata.msi_url -cne $expectedUrl -or $metadata.repository -cne 'supermerill/SuperSlicer') {
|
||||
throw 'MSI URL must identify the selected public upstream release'
|
||||
}
|
||||
New-Item -ItemType Directory -Path $WorkDirectory | Out-Null
|
||||
$msi = Join-Path (Resolve-Path -LiteralPath $WorkDirectory).Path 'installer.msi'
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $expectedUrl -OutFile $msi
|
||||
if ((Get-Item -LiteralPath $msi).Length -ne $metadata.size) { throw 'Release MSI size mismatch' }
|
||||
$digest = (Get-FileHash -LiteralPath $msi -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
if ($metadata.digest -and $metadata.digest -cne "sha256:$digest") { throw 'Release MSI digest mismatch' }
|
||||
$signature = Get-AuthenticodeSignature -LiteralPath $msi
|
||||
if ($signature.Status -ne 'Valid' -or $null -eq $signature.SignerCertificate) {
|
||||
throw 'Chocolatey publication requires a valid, publicly trusted MSI signature; self-signed test output is forbidden'
|
||||
}
|
||||
|
||||
# Open the MSI database read-only; never install or execute the release here.
|
||||
$installer = New-Object -ComObject WindowsInstaller.Installer
|
||||
$database = $null
|
||||
$view = $null
|
||||
try {
|
||||
$database = $installer.OpenDatabase($msi, 0)
|
||||
$view = $database.OpenView('SELECT `Property`, `Value` FROM `Property`')
|
||||
$view.Execute()
|
||||
$properties = @{}
|
||||
while ($null -ne ($record = $view.Fetch())) {
|
||||
$properties[$record.StringData(1)] = $record.StringData(2)
|
||||
[void][Runtime.InteropServices.Marshal]::ReleaseComObject($record)
|
||||
}
|
||||
if ($properties['ProductName'] -cne 'SuperSlicer' -or $properties['Manufacturer'] -cne 'Supermerill' -or
|
||||
($properties['ProductVersion'] -cne $tag -and $properties['ProductVersion'] -cne $metadata.package_version)) {
|
||||
throw 'MSI product name, publisher or version does not match this stable release'
|
||||
}
|
||||
} finally {
|
||||
if ($null -ne $view) {
|
||||
$view.Close()
|
||||
[void][Runtime.InteropServices.Marshal]::ReleaseComObject($view)
|
||||
}
|
||||
if ($null -ne $database) { [void][Runtime.InteropServices.Marshal]::ReleaseComObject($database) }
|
||||
[void][Runtime.InteropServices.Marshal]::ReleaseComObject($installer)
|
||||
}
|
||||
|
||||
$renderer = Join-Path (Split-Path $PSScriptRoot -Parent) 'scripts/chocolatey.py'
|
||||
& python -B $renderer stage --metadata $MetadataPath --msi $msi --destination $OutputDirectory
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Chocolatey package rendering failed' }
|
||||
& choco pack (Join-Path $OutputDirectory 'superslicer.nuspec') --output-directory $OutputDirectory --no-progress
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Chocolatey packing failed' }
|
||||
$expectedPackage = Join-Path $OutputDirectory "superslicer.$($metadata.package_version).nupkg"
|
||||
if (-not (Test-Path -LiteralPath $expectedPackage -PathType Leaf)) { throw 'Expected normalized nupkg was not generated' }
|
||||
91
.github/chocolatey/README.md
vendored
Normal file
91
.github/chocolatey/README.md
vendored
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
# Chocolatey publication
|
||||
|
||||
`release_chocolatey.yml` submits a script-only `superslicer` package referencing the
|
||||
**published stable Windows MSI**. It never publishes the RC draft or embeds the MSI
|
||||
inside the nupkg. URL, SHA-256, source version and normalized package version are
|
||||
fixed when packing; installing the package does not query "latest".
|
||||
|
||||
## One-time setup outside this repository
|
||||
|
||||
1. **Coordinate package ownership first.** As checked on 2026-11-13,
|
||||
[superslicer](https://community.chocolatey.org/packages/superslicer) is maintained
|
||||
by **verbalinsurection**, with package source at
|
||||
[Verbalinsurection/Chocolatey-SuperSlicer](https://github.com/Verbalinsurection/Chocolatey-SuperSlicer).
|
||||
Use [Contact Maintainers](https://community.chocolatey.org/packages/superslicer/ContactOwners)
|
||||
to request co-maintainer rights or agree a handover. Owning the software/GitHub
|
||||
repository or putting a name in a nuspec does not grant Chocolatey publishing
|
||||
rights. Stop the old updater by agreement to avoid two publishers racing.
|
||||
|
||||
2. **Agree and test the portable-to-MSI transition.** The existing package embeds a
|
||||
portable ZIP and creates a `superslicer.exe` shim and desktop shortcut. This new
|
||||
package installs the MSI for all users and relies on the MSI's shortcuts and
|
||||
Chocolatey's automatic MSI uninstaller; it does not create a new CLI shim.
|
||||
Back up profiles/settings (including any portable configuration) before removing
|
||||
an old package. Test fresh MSI installation, MSI-to-MSI upgrade/uninstall and the
|
||||
old portable-package removal in a disposable VM/Sandbox. The new install script
|
||||
fails when it detects a legacy portable directory or shim: it does **not** delete
|
||||
old files, user settings or arbitrary shortcuts to make an upgrade succeed.
|
||||
A transparent in-place portable-to-MSI migration is not claimed or implemented.
|
||||
Validate this policy with the maintainer/moderators before enabling publication.
|
||||
|
||||
3. **Finish SignPath production activation and publish a real stable release.**
|
||||
A beta/nightly or self-signed test build is not eligible. Publish the draft manually
|
||||
after all RC uploads finish. For tag `2.7.63.0`, the MSI is
|
||||
`SuperSlicer_2.7.63.0_win64.msi`. The Windows packer checks its size, GitHub digest
|
||||
when available, public Authenticode trust, ProductName `SuperSlicer`, Manufacturer
|
||||
`Supermerill`, and matching ProductVersion without executing/installing the MSI.
|
||||
|
||||
4. **Create/use the authorized Chocolatey account's API key.** Log into
|
||||
[Chocolatey Community](https://community.chocolatey.org/account), find the API key
|
||||
in the account settings and store it directly in **SuperSlicer → Settings → Secrets
|
||||
and variables → Actions → New repository secret → `CHOCO_API_KEY`**. It must belong
|
||||
to an account authorized to push `superslicer`. This is not a GitHub PAT or a
|
||||
SignPath token. Never put the key in Git, chat, nuspecs or package files.
|
||||
|
||||
5. **Enable and supervise the first submission.** After the ownership and migration
|
||||
checks, set the Actions repository variable **`CHOCO_ENABLED=true`**. Deploy this
|
||||
workflow with the release and to the default branch for manual retries. Inspect
|
||||
the generated nupkg (available as an Actions artifact) before rollout. Follow
|
||||
Chocolatey's validation, verification and moderation results. A successful push
|
||||
means **submitted**, not necessarily approved/visible to ordinary users. Trusted
|
||||
package policies may automate some reviews; there is no guaranteed turnaround.
|
||||
Rotate the key as needed; remove/disable CHOCO_ENABLED to stop new submissions.
|
||||
|
||||
## Version contract, retries and safety
|
||||
|
||||
Chocolatey 2.x [normalizes versions](https://docs.chocolatey.org/en-us/choco/features/version-number-normalization/):
|
||||
`2.7.63.0` becomes package `2.7.63`, while `2.7.63.12` stays `2.7.63.12`. Leading zeroes
|
||||
are normalized too. The **MSI URL always retains the exact four-part GitHub tag**;
|
||||
never construct it from `$env:ChocolateyPackageVersion` at install time.
|
||||
|
||||
Automatic submission uses `release: released`; drafts/betas/nightlies are excluded
|
||||
by this integration's policy. A missed event can be retried with **Publish stable
|
||||
release to Chocolatey**, selecting the **default branch** and the stable tag. Publishing
|
||||
via another workflow's `GITHUB_TOKEN` does not trigger a second release workflow;
|
||||
manual publication in the GitHub UI does.
|
||||
|
||||
The preflight checks the current GitHub release, exact MSI and Chocolatey's public
|
||||
version endpoint. A visible existing version is skipped; network/API errors fail
|
||||
instead of being treated as absence. A pending/unlisted submission may not be visible
|
||||
through the public feed: inspect the maintainer dashboard before retrying. Push errors
|
||||
(including duplicates or missing ownership) fail visibly. Never force-replace/delete
|
||||
packages, change an existing published MSI, or silently invent a revision to bypass
|
||||
moderation. Concurrency serializes current submissions but is not a moderation lock.
|
||||
|
||||
Only the final `choco push` step receives `CHOCO_API_KEY`, with no debug logging and
|
||||
without saving it to Chocolatey configuration. Build jobs have read-only GitHub access.
|
||||
The nupkg contains only `chocolateyInstall.ps1` and `VERIFICATION.txt` plus NuGet metadata.
|
||||
It installs the x64 MSI with SHA-256 validation and `/qn /norestart`; successful MSI exit
|
||||
codes include reboot-required results. No existing user installation is changed by CI.
|
||||
|
||||
## Local checks (no publishing)
|
||||
|
||||
```powershell
|
||||
python -B -m unittest discover -s .github/scripts/tests -v
|
||||
actionlint .github/workflows/release_chocolatey.yml
|
||||
```
|
||||
|
||||
Tests use fake release/feed responses and fixture bytes, test the install script with
|
||||
Chocolatey helpers mocked, and exercise `choco pack` when Chocolatey is installed.
|
||||
They never install SuperSlicer or push a package. These do not replace a real signed
|
||||
MSI, Sandbox migration testing or community validation/moderation.
|
||||
54
.github/chocolatey/tests/Test-InstallScript.ps1
vendored
Normal file
54
.github/chocolatey/tests/Test-InstallScript.ps1
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
param(
|
||||
[Parameter(Mandatory = $true)][string]$PackageDirectory,
|
||||
[Parameter(Mandatory = $true)][string]$WorkDirectory
|
||||
)
|
||||
|
||||
# No Chocolatey module, network, installed software or real installer is used.
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version Latest
|
||||
New-Item -ItemType Directory -Path "$WorkDirectory/bin" -Force | Out-Null
|
||||
$env:ChocolateyInstall = $WorkDirectory
|
||||
$env:ChocolateyPackageName = 'superslicer'
|
||||
$env:ChocolateyForceX86 = 'false'
|
||||
$global:ChocoFixtureState = @{ bits = 64; received = $null }
|
||||
function Get-OSArchitectureWidth { param($Compare) return $global:ChocoFixtureState.bits -eq $Compare }
|
||||
function Install-ChocolateyPackage {
|
||||
param($packageName, $softwareName, $fileType, $url64bit, $checksum64, $checksumType64, $silentArgs, $validExitCodes)
|
||||
$global:ChocoFixtureState.received = $PSBoundParameters
|
||||
}
|
||||
function Assert-Fails([scriptblock]$Action, [string]$Pattern) {
|
||||
$failed = $false
|
||||
try { & $Action } catch {
|
||||
if ($_.Exception.Message -notlike $Pattern) { throw }
|
||||
$failed = $true
|
||||
}
|
||||
if (-not $failed) { throw "Expected failure: $Pattern" }
|
||||
if ($null -ne $global:ChocoFixtureState.received) { throw 'Called installer helper before rejecting unsafe input' }
|
||||
}
|
||||
$install = Join-Path $PackageDirectory 'tools/chocolateyInstall.ps1'
|
||||
& $install
|
||||
$received = $global:ChocoFixtureState.received
|
||||
if ($received.fileType -ne 'msi' -or $received.silentArgs -ne '/qn /norestart' -or
|
||||
$received.checksumType64 -ne 'sha256' -or $received.checksum64 -notmatch '^[0-9A-F]{64}$' -or
|
||||
$received.url64bit -notmatch '^https://github.com/supermerill/SuperSlicer/releases/download/.+_win64\.msi$' -or
|
||||
(@($received.validExitCodes) -join ',') -ne '0,1641,3010') {
|
||||
throw 'Unexpected installer helper arguments'
|
||||
}
|
||||
$global:ChocoFixtureState.received = $null
|
||||
$global:ChocoFixtureState.bits = 32
|
||||
Assert-Fails { & $install } '*requires Windows x64*'
|
||||
$global:ChocoFixtureState.bits = 64
|
||||
$env:ChocolateyForceX86 = 'true'
|
||||
Assert-Fails { & $install } '*requires Windows x64*'
|
||||
$env:ChocolateyForceX86 = 'false'
|
||||
'portable shim fixture' | Set-Content -LiteralPath "$WorkDirectory/bin/superslicer.exe"
|
||||
Assert-Fails { & $install } '*Legacy portable SuperSlicer detected*'
|
||||
if (-not (Test-Path "$WorkDirectory/bin/superslicer.exe")) { throw 'Legacy shim was deleted' }
|
||||
Remove-Item -LiteralPath "$WorkDirectory/bin/superslicer.exe"
|
||||
$portable = Join-Path $PackageDirectory 'tools/SuperSlicer_old'
|
||||
New-Item -ItemType Directory -Path $portable | Out-Null
|
||||
try {
|
||||
Assert-Fails { & $install } '*Legacy portable SuperSlicer detected*'
|
||||
if (-not (Test-Path -LiteralPath $portable)) { throw 'Portable directory was deleted' }
|
||||
} finally { Remove-Item -LiteralPath $portable }
|
||||
Write-Host 'PASS: MSI arguments, SHA-256, exit codes, architecture guards and nondestructive legacy detection'
|
||||
6
.github/release/README.md
vendored
6
.github/release/README.md
vendored
|
|
@ -113,6 +113,12 @@ see the [WinGet setup and manual first submission](../winget/README.md). Drafts,
|
|||
beta releases and nightly builds are not submitted. The RC master never receives
|
||||
the external WinGet token.
|
||||
|
||||
The separate [`release_chocolatey.yml`](../workflows/release_chocolatey.yml) can submit
|
||||
the same public stable MSI to Chocolatey after `CHOCO_ENABLED=true`. It requires
|
||||
publishing rights for the existing `superslicer` package and an agreed/tested transition
|
||||
from its portable ZIP package; see [Chocolatey setup](../chocolatey/README.md). The RC
|
||||
master never receives `CHOCO_API_KEY`, and a push does not bypass community moderation.
|
||||
|
||||
## Offline verification and migration
|
||||
|
||||
```powershell
|
||||
|
|
|
|||
154
.github/scripts/chocolatey.py
vendored
Normal file
154
.github/scripts/chocolatey.py
vendored
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
"""Prepare a script-only Chocolatey package from a published stable upstream MSI."""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from release import GitHub, ReleaseError, annotation, asset_names, sha256, usable_asset
|
||||
|
||||
|
||||
REPOSITORY = "supermerill/SuperSlicer"
|
||||
FEED = "https://community.chocolatey.org/api/v2"
|
||||
TEMPLATES = Path(__file__).resolve().parents[2] / "packaging/chocolatey"
|
||||
|
||||
|
||||
def package_version(tag):
|
||||
if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", tag):
|
||||
raise ReleaseError("Chocolatey automation accepts only stable four-part release tags, without beta/nightly suffixes")
|
||||
parts = [str(int(part)) for part in tag.split(".")]
|
||||
return ".".join(parts[:3] if parts[3] == "0" else parts)
|
||||
|
||||
|
||||
def package_exists(version):
|
||||
if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+(?:\.[0-9]+)?", version):
|
||||
raise ReleaseError("Invalid Chocolatey package version")
|
||||
url = f"{FEED}/Packages(Id='superslicer',Version='{version}')"
|
||||
request = urllib.request.Request(url, headers={"User-Agent": "SuperSlicer-Chocolatey-release"})
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=60) as response:
|
||||
root = ET.fromstring(response.read())
|
||||
except urllib.error.HTTPError as error:
|
||||
code = error.code
|
||||
error.close()
|
||||
if code == 404:
|
||||
return False
|
||||
raise ReleaseError(f"Chocolatey version lookup failed: HTTP {code}") from None
|
||||
except (urllib.error.URLError, ET.ParseError):
|
||||
raise ReleaseError("Chocolatey version lookup failed; refusing to assume the version is absent") from None
|
||||
title = root.find("{http://www.w3.org/2005/Atom}title")
|
||||
found_version = root.find(".//{http://schemas.microsoft.com/ado/2007/08/dataservices}Version")
|
||||
if title is None or title.text != "superslicer" or found_version is None or not found_version.text:
|
||||
raise ReleaseError("Unexpected Chocolatey version lookup response")
|
||||
found = found_version.text
|
||||
if found.count(".") == 2:
|
||||
found += ".0"
|
||||
if package_version(found) != version:
|
||||
raise ReleaseError("Unexpected Chocolatey version lookup response")
|
||||
return True
|
||||
|
||||
|
||||
def validate_metadata(metadata):
|
||||
tag = metadata["source_version"]
|
||||
version = package_version(tag)
|
||||
name = asset_names("SuperSlicer", tag)["windows"][1]
|
||||
url = f"https://github.com/{REPOSITORY}/releases/download/{tag}/{name}"
|
||||
if (metadata.get("schema") != 1 or metadata.get("repository") != REPOSITORY or
|
||||
metadata.get("package_version") != version or metadata.get("msi_name") != name or metadata.get("msi_url") != url):
|
||||
raise ReleaseError("Chocolatey metadata does not match the selected upstream release")
|
||||
if type(metadata.get("size")) is not int or metadata["size"] <= 0:
|
||||
raise ReleaseError("Invalid MSI size")
|
||||
digest = metadata.get("digest")
|
||||
if digest is not None and not re.fullmatch(r"sha256:[0-9a-f]{64}", digest):
|
||||
raise ReleaseError("Invalid GitHub MSI digest")
|
||||
|
||||
|
||||
def prepare(api, tag, exists=package_exists):
|
||||
version = package_version(tag)
|
||||
if api.repository.lower() != REPOSITORY.lower():
|
||||
raise ReleaseError("Chocolatey publication is restricted to upstream SuperSlicer")
|
||||
item = api.request("GET", "/releases/tags/" + urllib.parse.quote(tag, safe=""))
|
||||
if (item.get("tag_name") != tag or item.get("draft") is not False or
|
||||
item.get("prerelease") is not False or not item.get("published_at")):
|
||||
raise ReleaseError("Chocolatey requires the exact published, non-prerelease release")
|
||||
name = asset_names("SuperSlicer", tag)["windows"][1]
|
||||
assets = api.assets(item["id"])
|
||||
if name not in assets or not usable_asset(assets[name]):
|
||||
raise ReleaseError(f"Missing or incomplete release MSI: {name}")
|
||||
asset = assets[name]
|
||||
metadata = {"schema": 1, "repository": REPOSITORY, "source_version": tag,
|
||||
"package_version": version, "msi_name": name, "msi_url": asset.get("browser_download_url"),
|
||||
"size": asset["size"], "digest": asset.get("digest")}
|
||||
validate_metadata(metadata)
|
||||
submit = not exists(version)
|
||||
if not submit:
|
||||
annotation("warning", f"Chocolatey superslicer {version} already exists; not pushing or replacing it")
|
||||
return metadata, {"submit": "true" if submit else "false", "package_version": version,
|
||||
"package_file": f"superslicer.{version}.nupkg"}
|
||||
|
||||
|
||||
def stage(metadata, msi, destination, templates=TEMPLATES):
|
||||
# The Windows wrapper verifies Authenticode and MSI properties before calling
|
||||
# this local renderer. Never put the MSI itself inside the public nupkg.
|
||||
validate_metadata(metadata)
|
||||
if not msi.is_file() or msi.is_symlink() or msi.stat().st_size != metadata["size"]:
|
||||
raise ReleaseError("Downloaded MSI does not match the expected release asset size")
|
||||
digest = sha256(msi)
|
||||
if metadata.get("digest") and metadata["digest"] != "sha256:" + digest:
|
||||
raise ReleaseError("Downloaded MSI does not match the GitHub asset digest")
|
||||
if destination.exists() and any(destination.iterdir()):
|
||||
raise ReleaseError("Chocolatey staging directory is not empty")
|
||||
replacements = {"@SOURCE_VERSION@": metadata["source_version"], "@PACKAGE_VERSION@": metadata["package_version"],
|
||||
"@MSI_URL@": metadata["msi_url"], "@SHA256@": digest.upper()}
|
||||
for relative in ("superslicer.nuspec", "tools/chocolateyInstall.ps1"):
|
||||
text = (templates / relative).read_text(encoding="utf-8-sig")
|
||||
for token, value in replacements.items():
|
||||
text = text.replace(token, value)
|
||||
if re.search(r"@[A-Z_]+@", text):
|
||||
raise ReleaseError(f"Unresolved Chocolatey template token in {relative}")
|
||||
target = destination / relative
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text(text, encoding="utf-8")
|
||||
(destination / "tools/VERIFICATION.txt").write_text(
|
||||
f"Upstream release: https://github.com/{REPOSITORY}/releases/tag/{metadata['source_version']}\n"
|
||||
f"Installer: {metadata['msi_url']}\nSHA256: {digest.upper()}\n"
|
||||
"The MSI is downloaded from the upstream release, not embedded or repacked.\n", encoding="utf-8")
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("command", choices=("prepare", "stage"))
|
||||
parser.add_argument("--tag")
|
||||
parser.add_argument("--metadata", type=Path, required=True)
|
||||
parser.add_argument("--output", type=Path)
|
||||
parser.add_argument("--msi", type=Path)
|
||||
parser.add_argument("--destination", type=Path)
|
||||
args = parser.parse_args(argv)
|
||||
if args.command == "prepare":
|
||||
if not args.tag or not args.output:
|
||||
parser.error("prepare requires --tag and --output")
|
||||
api = GitHub(os.environ.get("GITHUB_REPOSITORY", ""), os.environ.get("GH_TOKEN", ""))
|
||||
metadata, outputs = prepare(api, args.tag)
|
||||
args.metadata.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.metadata.write_text(json.dumps(metadata, indent=2) + "\n", encoding="utf-8")
|
||||
with args.output.open("a", encoding="utf-8") as output:
|
||||
for key, value in outputs.items():
|
||||
output.write(f"{key}={value}\n")
|
||||
else:
|
||||
if not args.msi or not args.destination:
|
||||
parser.error("stage requires --msi and --destination")
|
||||
stage(json.loads(args.metadata.read_text(encoding="utf-8")), args.msi, args.destination)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except (ReleaseError, OSError, ValueError, KeyError, TypeError) as error:
|
||||
annotation("error", error)
|
||||
sys.exit(1)
|
||||
315
.github/scripts/tests/test_chocolatey.py
vendored
Normal file
315
.github/scripts/tests/test_chocolatey.py
vendored
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
"""Offline Chocolatey publication and local packing tests; never installs or pushes."""
|
||||
|
||||
import contextlib
|
||||
import copy
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
|
||||
|
||||
SCRIPTS = Path(__file__).resolve().parents[1]
|
||||
SPEC = importlib.util.spec_from_file_location("chocolatey_release", SCRIPTS / "chocolatey.py")
|
||||
chocolatey = importlib.util.module_from_spec(SPEC)
|
||||
with mock.patch.object(sys, "path", [str(SCRIPTS), *sys.path]):
|
||||
SPEC.loader.exec_module(chocolatey)
|
||||
VERSION = "2.7.63.0"
|
||||
PACKAGE_VERSION = "2.7.63"
|
||||
NAME = f"SuperSlicer_{VERSION}_win64.msi"
|
||||
URL = f"https://github.com/supermerill/SuperSlicer/releases/download/{VERSION}/{NAME}"
|
||||
NAMESPACE = {"n": "http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd"}
|
||||
|
||||
|
||||
class ChocolateyTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.api = mock.Mock(spec=chocolatey.GitHub)
|
||||
self.api.repository = chocolatey.REPOSITORY
|
||||
self.item = {"id": 42, "tag_name": VERSION, "draft": False, "prerelease": False,
|
||||
"published_at": "2026-11-13T00:00:00Z"}
|
||||
self.api.request.return_value = self.item
|
||||
self.bytes = b"MSI fixture, not a real installer"
|
||||
self.asset = {"name": NAME, "state": "uploaded", "size": len(self.bytes),
|
||||
"browser_download_url": URL, "digest": "sha256:" + hashlib.sha256(self.bytes).hexdigest()}
|
||||
self.api.assets.return_value = {NAME: self.asset}
|
||||
self.exists = mock.Mock(return_value=False)
|
||||
approved_temp = Path(os.environ.get("LOCALAPPDATA", tempfile.gettempdir())) / "Temp/opencode"
|
||||
self.folder = tempfile.TemporaryDirectory(dir=approved_temp if approved_temp.is_dir() else None)
|
||||
self.root = Path(self.folder.name)
|
||||
self.stdout = io.StringIO()
|
||||
self.redirect = contextlib.redirect_stdout(self.stdout)
|
||||
self.redirect.__enter__()
|
||||
|
||||
def tearDown(self):
|
||||
self.redirect.__exit__(None, None, None)
|
||||
self.folder.cleanup()
|
||||
|
||||
def prepare(self, tag=VERSION):
|
||||
return chocolatey.prepare(self.api, tag, self.exists)
|
||||
|
||||
def payload(self):
|
||||
metadata, _ = self.prepare()
|
||||
msi = self.root / NAME
|
||||
msi.write_bytes(self.bytes)
|
||||
destination = self.root / "package"
|
||||
chocolatey.stage(metadata, msi, destination)
|
||||
return metadata, msi, destination
|
||||
|
||||
def test_chocolatey_normalizes_only_package_version_not_source_tag(self):
|
||||
for source, expected in ((VERSION, PACKAGE_VERSION), ("2.7.63.12", "2.7.63.12"),
|
||||
("02.007.063.000", "2.7.63"), ("02.007.063.012", "2.7.63.12")):
|
||||
self.assertEqual(expected, chocolatey.package_version(source))
|
||||
metadata, outputs = self.prepare()
|
||||
self.assertEqual(VERSION, metadata["source_version"])
|
||||
self.assertEqual(URL, metadata["msi_url"])
|
||||
self.assertEqual(PACKAGE_VERSION, metadata["package_version"])
|
||||
self.assertEqual("superslicer.2.7.63.nupkg", outputs["package_file"])
|
||||
self.exists.assert_called_once_with(PACKAGE_VERSION)
|
||||
|
||||
def test_invalid_prerelease_and_nightly_tags_fail_before_api(self):
|
||||
for tag in ("2.7.63.0-beta", "2.7.63.0+UNKNOWN", "2.7.63.0-2026-11-13", "nightly",
|
||||
"v2.7.63.0", "2.7.63", "../2.7.63.0", "2.7.63.0\nsubmit=true"):
|
||||
with self.subTest(tag=tag), self.assertRaises(chocolatey.ReleaseError):
|
||||
self.prepare(tag)
|
||||
self.api.request.assert_not_called()
|
||||
|
||||
def test_forks_drafts_prereleases_and_wrong_tags_are_rejected(self):
|
||||
self.api.repository = "example/SuperSlicer"
|
||||
with self.assertRaisesRegex(chocolatey.ReleaseError, "upstream"):
|
||||
self.prepare()
|
||||
self.api.repository = chocolatey.REPOSITORY
|
||||
original = copy.deepcopy(self.item)
|
||||
for field, value in (("draft", True), ("draft", None), ("prerelease", True), ("prerelease", None),
|
||||
("published_at", None), ("tag_name", "2.7.62.0")):
|
||||
self.api.request.return_value = {**original, field: value}
|
||||
with self.subTest(field=field, value=value), self.assertRaisesRegex(chocolatey.ReleaseError, "published, non-prerelease"):
|
||||
self.prepare()
|
||||
self.exists.assert_not_called()
|
||||
|
||||
def test_missing_empty_incomplete_or_misnamed_msi_is_rejected(self):
|
||||
for assets in ({}, {"SuperSlicer_2.7.63.0.msi": self.asset},
|
||||
{NAME: {**self.asset, "size": 0}}, {NAME: {**self.asset, "state": "starter"}}):
|
||||
self.api.assets.return_value = assets
|
||||
with self.subTest(assets=assets), self.assertRaisesRegex(chocolatey.ReleaseError, "Missing or incomplete"):
|
||||
self.prepare()
|
||||
|
||||
def test_url_and_digest_are_validated_before_checking_feed(self):
|
||||
for changes in ({"browser_download_url": "https://example.com/installer.msi"},
|
||||
{"browser_download_url": URL.replace(VERSION, "2.7.62.0")},
|
||||
{"digest": "sha256:not-a-hash"}):
|
||||
self.api.assets.return_value = {NAME: {**self.asset, **changes}}
|
||||
with self.subTest(changes=changes), self.assertRaises(chocolatey.ReleaseError):
|
||||
self.prepare()
|
||||
self.exists.assert_not_called()
|
||||
|
||||
def test_visible_existing_version_is_skipped_not_overwritten(self):
|
||||
self.exists.return_value = True
|
||||
_, outputs = self.prepare()
|
||||
self.assertEqual("false", outputs["submit"])
|
||||
self.assertIn("::warning::", self.stdout.getvalue())
|
||||
self.assertTrue(all(call.args[0] == "GET" for call in self.api.request.call_args_list))
|
||||
|
||||
def test_rendered_package_has_pinned_url_hash_and_no_msi(self):
|
||||
metadata, msi, destination = self.payload()
|
||||
self.assertEqual({"superslicer.nuspec", "tools/chocolateyInstall.ps1", "tools/VERIFICATION.txt"},
|
||||
{p.relative_to(destination).as_posix() for p in destination.rglob("*") if p.is_file()})
|
||||
nuspec = ET.parse(destination / "superslicer.nuspec")
|
||||
self.assertEqual("superslicer", nuspec.find("n:metadata/n:id", NAMESPACE).text)
|
||||
self.assertEqual(PACKAGE_VERSION, nuspec.find("n:metadata/n:version", NAMESPACE).text)
|
||||
script = (destination / "tools/chocolateyInstall.ps1").read_text()
|
||||
self.assertIn(URL, script)
|
||||
self.assertIn(chocolatey.sha256(msi).upper(), script)
|
||||
self.assertNotIn("ChocolateyPackageVersion", script)
|
||||
self.assertNotIn("@MSI_URL@", script)
|
||||
self.assertIn(VERSION, (destination / "tools/VERIFICATION.txt").read_text())
|
||||
self.assertEqual("https://cdn.jsdelivr.net/gh/supermerill/SuperSlicer@2.7.63.0/resources/icons/SuperSlicer.png",
|
||||
nuspec.find("n:metadata/n:iconUrl", NAMESPACE).text)
|
||||
|
||||
def test_tampered_size_hash_or_metadata_is_rejected(self):
|
||||
metadata, _ = self.prepare()
|
||||
msi = self.root / NAME
|
||||
msi.write_bytes(self.bytes + b"tamper")
|
||||
with self.assertRaisesRegex(chocolatey.ReleaseError, "size"):
|
||||
chocolatey.stage(metadata, msi, self.root / "package")
|
||||
msi.write_bytes(b"x" * len(self.bytes))
|
||||
with self.assertRaisesRegex(chocolatey.ReleaseError, "digest"):
|
||||
chocolatey.stage(metadata, msi, self.root / "package")
|
||||
msi.write_bytes(self.bytes)
|
||||
for changes in ({"msi_url": "https://example.com/installer.msi"}, {"package_version": VERSION},
|
||||
{"msi_name": "../installer.msi"}, {"repository": "example/SuperSlicer"}):
|
||||
with self.subTest(changes=changes), self.assertRaises(chocolatey.ReleaseError):
|
||||
chocolatey.stage({**metadata, **changes}, msi, self.root / "package")
|
||||
|
||||
def test_without_github_digest_locally_computed_checksum_is_still_pinned(self):
|
||||
self.asset["digest"] = None
|
||||
_, msi, destination = self.payload()
|
||||
self.assertIn(chocolatey.sha256(msi).upper(), (destination / "tools/chocolateyInstall.ps1").read_text())
|
||||
|
||||
def test_nonempty_staging_directory_is_not_overwritten(self):
|
||||
metadata, msi, destination = self.payload()
|
||||
with self.assertRaisesRegex(chocolatey.ReleaseError, "not empty"):
|
||||
chocolatey.stage(metadata, msi, destination)
|
||||
|
||||
def test_cli_writes_metadata_and_normalized_outputs_without_key(self):
|
||||
metadata, outputs = self.prepare()
|
||||
output = self.root / "outputs"
|
||||
metadata_path = self.root / "metadata.json"
|
||||
with mock.patch.object(chocolatey, "GitHub", return_value=self.api), \
|
||||
mock.patch.object(chocolatey, "prepare", return_value=(metadata, outputs)):
|
||||
chocolatey.main(["prepare", "--tag", VERSION, "--metadata", str(metadata_path), "--output", str(output)])
|
||||
self.assertEqual(metadata, json.loads(metadata_path.read_text()))
|
||||
self.assertIn("package_file=superslicer.2.7.63.nupkg\n", output.read_text())
|
||||
self.assertNotIn("CHOCO_API_KEY", metadata_path.read_text() + output.read_text())
|
||||
|
||||
@unittest.skipUnless(os.name == "nt" and shutil.which("powershell"), "Requires Windows PowerShell")
|
||||
def test_install_script_with_mock_helpers_never_runs_msi(self):
|
||||
_, _, destination = self.payload()
|
||||
script = SCRIPTS.parent / "chocolatey/tests/Test-InstallScript.ps1"
|
||||
result = subprocess.run(["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(script),
|
||||
"-PackageDirectory", str(destination), "-WorkDirectory", str(self.root / "mock-choco")],
|
||||
capture_output=True, text=True, timeout=60)
|
||||
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
|
||||
@unittest.skipUnless(os.name == "nt" and shutil.which("powershell"), "Requires Windows PowerShell")
|
||||
def test_packer_rejects_unsigned_download_before_rendering(self):
|
||||
metadata, _ = self.prepare()
|
||||
msi = self.root / NAME
|
||||
msi.write_bytes(self.bytes)
|
||||
metadata_path = self.root / "release.json"
|
||||
metadata_path.write_text(json.dumps(metadata), encoding="utf-8")
|
||||
destination = self.root / "package"
|
||||
command = r"""
|
||||
$ErrorActionPreference = 'Stop'
|
||||
function Invoke-WebRequest {
|
||||
param([switch]$UseBasicParsing, $Uri, $OutFile)
|
||||
Copy-Item -LiteralPath $env:CHOCO_FIXTURE_MSI -Destination $OutFile
|
||||
}
|
||||
try {
|
||||
& $env:CHOCO_FIXTURE_PACKER -MetadataPath $env:CHOCO_FIXTURE_METADATA -WorkDirectory $env:CHOCO_FIXTURE_WORK -OutputDirectory $env:CHOCO_FIXTURE_OUTPUT
|
||||
throw 'Unexpected successful packing of an unsigned fixture'
|
||||
} catch {
|
||||
if ($_.Exception.Message -notlike '*publicly trusted MSI signature*') { throw }
|
||||
}
|
||||
exit 0
|
||||
"""
|
||||
environment = {**os.environ, "CHOCO_FIXTURE_MSI": str(msi), "CHOCO_FIXTURE_METADATA": str(metadata_path),
|
||||
"CHOCO_FIXTURE_PACKER": str(SCRIPTS.parent / "chocolatey/Pack-Release.ps1"),
|
||||
"CHOCO_FIXTURE_WORK": str(self.root / "download"), "CHOCO_FIXTURE_OUTPUT": str(destination)}
|
||||
result = subprocess.run(["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", command],
|
||||
env=environment, capture_output=True, text=True, timeout=60)
|
||||
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
self.assertFalse(destination.exists())
|
||||
|
||||
@unittest.skipUnless(os.name == "nt" and shutil.which("choco"), "Requires Chocolatey CLI for local packing only")
|
||||
def test_choco_pack_produces_normalized_script_only_nupkg(self):
|
||||
_, _, destination = self.payload()
|
||||
result = subprocess.run(["choco", "pack", str(destination / "superslicer.nuspec"), "--output-directory", str(destination),
|
||||
"--no-progress"], capture_output=True, text=True, timeout=60)
|
||||
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
with zipfile.ZipFile(destination / "superslicer.2.7.63.nupkg") as archive:
|
||||
names = set(archive.namelist())
|
||||
self.assertIn("tools/chocolateyInstall.ps1", names)
|
||||
self.assertIn("tools/VERIFICATION.txt", names)
|
||||
self.assertFalse(any(name.lower().endswith((".msi", ".exe", ".dll")) for name in names))
|
||||
self.assertFalse(any("tests/" in name or name.endswith("README.md") for name in names))
|
||||
|
||||
|
||||
class FeedTests(unittest.TestCase):
|
||||
def response(self, content):
|
||||
response = mock.MagicMock()
|
||||
response.__enter__.return_value.read.return_value = content
|
||||
return response
|
||||
|
||||
def test_exact_version_found_without_credentials(self):
|
||||
xml = b'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"><title>superslicer</title><d:Version>2.7.63</d:Version></entry>'
|
||||
with mock.patch.object(chocolatey.urllib.request, "urlopen", return_value=self.response(xml)) as urlopen:
|
||||
self.assertTrue(chocolatey.package_exists(PACKAGE_VERSION))
|
||||
request = urlopen.call_args.args[0]
|
||||
self.assertEqual(f"{chocolatey.FEED}/Packages(Id='superslicer',Version='2.7.63')", request.full_url)
|
||||
self.assertIsNone(request.get_header("Authorization"))
|
||||
|
||||
def test_feed_four_part_zero_is_equivalent_to_normalized_package(self):
|
||||
xml = b'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"><title>superslicer</title><d:Version>2.7.63.0</d:Version></entry>'
|
||||
with mock.patch.object(chocolatey.urllib.request, "urlopen", return_value=self.response(xml)):
|
||||
self.assertTrue(chocolatey.package_exists(PACKAGE_VERSION))
|
||||
|
||||
def test_only_404_means_absent(self):
|
||||
for code in (404, 403, 429, 500):
|
||||
error = chocolatey.urllib.error.HTTPError("https://example.com", code, "test reason", {}, io.BytesIO())
|
||||
try:
|
||||
with mock.patch.object(chocolatey.urllib.request, "urlopen", side_effect=error):
|
||||
if code == 404:
|
||||
self.assertFalse(chocolatey.package_exists(PACKAGE_VERSION))
|
||||
else:
|
||||
with self.assertRaises(chocolatey.ReleaseError):
|
||||
chocolatey.package_exists(PACKAGE_VERSION)
|
||||
finally:
|
||||
error.close()
|
||||
|
||||
def test_network_or_unexpected_response_does_not_mean_absent(self):
|
||||
with mock.patch.object(chocolatey.urllib.request, "urlopen", side_effect=chocolatey.urllib.error.URLError("private reason")):
|
||||
with self.assertRaises(chocolatey.ReleaseError):
|
||||
chocolatey.package_exists(PACKAGE_VERSION)
|
||||
for content in (b"not XML", b"<html/>"):
|
||||
with mock.patch.object(chocolatey.urllib.request, "urlopen", return_value=self.response(content)):
|
||||
with self.assertRaises(chocolatey.ReleaseError):
|
||||
chocolatey.package_exists(PACKAGE_VERSION)
|
||||
|
||||
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
yaml = None
|
||||
|
||||
|
||||
@unittest.skipIf(yaml is None, "Install PyYAML for workflow contract tests")
|
||||
class ChocolateyWorkflowTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.workflow = yaml.load((SCRIPTS.parent / "workflows/release_chocolatey.yml").read_text(), Loader=yaml.BaseLoader)
|
||||
self.job = self.workflow["jobs"]["publish"]
|
||||
|
||||
def test_stable_only_opt_in_and_manual_default_branch(self):
|
||||
self.assertEqual({"release", "workflow_dispatch"}, set(self.workflow["on"]))
|
||||
self.assertEqual(["released"], self.workflow["on"]["release"]["types"])
|
||||
self.assertIn("vars.CHOCO_ENABLED == 'true'", self.job["if"])
|
||||
self.assertIn("github.repository == 'supermerill/SuperSlicer'", self.job["if"])
|
||||
self.assertIn("!github.event.release.draft && !github.event.release.prerelease", self.job["if"])
|
||||
self.assertIn("github.event.repository.default_branch", self.job["if"])
|
||||
self.assertEqual("false", self.workflow["concurrency"]["cancel-in-progress"])
|
||||
|
||||
def test_checkout_and_credentials_are_restricted(self):
|
||||
self.assertEqual({"contents": "read"}, self.workflow["permissions"])
|
||||
checkout = self.job["steps"][0]
|
||||
self.assertEqual("${{ github.sha }}", checkout["with"]["ref"])
|
||||
self.assertEqual("false", checkout["with"]["persist-credentials"])
|
||||
secret_steps = [step for step in self.job["steps"] if "CHOCO_API_KEY" in step.get("env", {})]
|
||||
self.assertEqual(1, len(secret_steps))
|
||||
self.assertIn("choco push", secret_steps[0]["run"])
|
||||
self.assertIn("https://push.chocolatey.org/", secret_steps[0]["run"])
|
||||
for step in self.job["steps"]:
|
||||
self.assertNotIn("${{", step.get("run", ""))
|
||||
self.assertNotRegex(step.get("run", ""), r"--force|--debug|--verbose|choco apikey")
|
||||
|
||||
def test_signature_and_msi_metadata_checked_before_render_and_pack(self):
|
||||
script = (SCRIPTS.parent / "chocolatey/Pack-Release.ps1").read_text()
|
||||
self.assertIn("$signature.Status -ne 'Valid'", script)
|
||||
self.assertIn("$installer.OpenDatabase($msi, 0)", script)
|
||||
self.assertIn("$properties['ProductVersion']", script)
|
||||
self.assertLess(script.index("Get-AuthenticodeSignature"), script.index("$renderer stage"))
|
||||
self.assertLess(script.index("$properties['ProductVersion']"), script.index("$renderer stage"))
|
||||
self.assertLess(script.index("$renderer stage"), script.index("choco pack"))
|
||||
names = [step.get("name") for step in self.job["steps"]]
|
||||
self.assertLess(names.index("Verify signed MSI and pack the script-only package"), names.index("Submit to Chocolatey Community Repository"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
83
.github/workflows/release_chocolatey.yml
vendored
Normal file
83
.github/workflows/release_chocolatey.yml
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
name: Publish stable release to Chocolatey
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [released]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release_tag:
|
||||
description: 'Published stable tag to submit, e.g. 2.7.63.0 (not a draft or beta)'
|
||||
type: string
|
||||
required: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: chocolatey-${{ github.repository }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
if: >-
|
||||
vars.CHOCO_ENABLED == 'true' && github.repository == 'supermerill/SuperSlicer' &&
|
||||
((github.event_name == 'release' && !github.event.release.draft && !github.event.release.prerelease) ||
|
||||
(github.event_name == 'workflow_dispatch' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)))
|
||||
runs-on: windows-2022
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.sha }}
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Test publication guards offline
|
||||
run: python -B -m unittest discover -s .github/scripts/tests -v
|
||||
- name: Check current release, exact MSI and normalized package version
|
||||
id: prepare
|
||||
shell: powershell
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
RELEASE_TAG: ${{ inputs.release_tag || github.event.release.tag_name }}
|
||||
run: >-
|
||||
python -B .github/scripts/chocolatey.py prepare --tag "$env:RELEASE_TAG"
|
||||
--metadata "$env:RUNNER_TEMP/chocolatey-release.json" --output "$env:GITHUB_OUTPUT"
|
||||
- name: Verify signed MSI and pack the script-only package
|
||||
if: steps.prepare.outputs.submit == 'true'
|
||||
shell: powershell
|
||||
run: >-
|
||||
./.github/chocolatey/Pack-Release.ps1 -MetadataPath "$env:RUNNER_TEMP/chocolatey-release.json"
|
||||
-WorkDirectory "$env:RUNNER_TEMP/chocolatey-download" -OutputDirectory chocolatey-package
|
||||
- name: Keep the exact package submitted for review
|
||||
if: steps.prepare.outputs.submit == 'true'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: chocolatey-${{ steps.prepare.outputs.package_version }}-${{ github.run_attempt }}
|
||||
path: chocolatey-package/${{ steps.prepare.outputs.package_file }}
|
||||
if-no-files-found: error
|
||||
- name: Submit to Chocolatey Community Repository
|
||||
if: steps.prepare.outputs.submit == 'true'
|
||||
shell: powershell
|
||||
env:
|
||||
CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }}
|
||||
PACKAGE_FILE: ${{ steps.prepare.outputs.package_file }}
|
||||
run: |
|
||||
if ([string]::IsNullOrWhiteSpace($env:CHOCO_API_KEY)) {
|
||||
throw 'Set CHOCO_API_KEY for an authorized maintainer of superslicer; see .github/chocolatey/README.md.'
|
||||
}
|
||||
choco push "chocolatey-package/$env:PACKAGE_FILE" --source 'https://push.chocolatey.org/' --api-key "$env:CHOCO_API_KEY" --no-progress
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Chocolatey submission failed; inspect moderation/ownership or an existing submission before retrying.' }
|
||||
- name: Summarize submission
|
||||
shell: powershell
|
||||
env:
|
||||
PACKAGE_VERSION: ${{ steps.prepare.outputs.package_version }}
|
||||
SUBMIT: ${{ steps.prepare.outputs.submit }}
|
||||
run: |
|
||||
$url = "https://community.chocolatey.org/packages/superslicer/$env:PACKAGE_VERSION"
|
||||
if ($env:SUBMIT -eq 'false') {
|
||||
"Chocolatey: version already exists; no overwrite or push. $url" >> $env:GITHUB_STEP_SUMMARY
|
||||
} else {
|
||||
"Chocolatey: submitted for validation/moderation, not guaranteed approved yet. $url" >> $env:GITHUB_STEP_SUMMARY
|
||||
}
|
||||
26
packaging/chocolatey/superslicer.nuspec
Normal file
26
packaging/chocolatey/superslicer.nuspec
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>superslicer</id>
|
||||
<version>@PACKAGE_VERSION@</version>
|
||||
<title>SuperSlicer (MSI)</title>
|
||||
<authors>Supermerill</authors>
|
||||
<projectUrl>https://github.com/supermerill/SuperSlicer</projectUrl>
|
||||
<packageSourceUrl>https://github.com/supermerill/SuperSlicer/tree/@SOURCE_VERSION@/packaging/chocolatey</packageSourceUrl>
|
||||
<projectSourceUrl>https://github.com/supermerill/SuperSlicer/tree/@SOURCE_VERSION@</projectSourceUrl>
|
||||
<licenseUrl>https://github.com/supermerill/SuperSlicer/blob/@SOURCE_VERSION@/LICENSE</licenseUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<iconUrl>https://cdn.jsdelivr.net/gh/supermerill/SuperSlicer@@SOURCE_VERSION@/resources/icons/SuperSlicer.png</iconUrl>
|
||||
<bugTrackerUrl>https://github.com/supermerill/SuperSlicer/issues</bugTrackerUrl>
|
||||
<tags>superslicer gcode slicer 3d-printing admin</tags>
|
||||
<summary>G-code generator for 3D printers, installed using the upstream Windows MSI.</summary>
|
||||
<description>SuperSlicer converts 3D models into G-code for FFF printers and is based on PrusaSlicer and Slic3r.
|
||||
This package installs the upstream production-signed Windows x64 MSI for all users. Administrator privileges are required.
|
||||
For an existing portable Chocolatey installation, back up settings and uninstall the old portable package first; automatic portable-to-MSI migration is not performed.</description>
|
||||
<releaseNotes>https://github.com/supermerill/SuperSlicer/releases/tag/@SOURCE_VERSION@</releaseNotes>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="tools\chocolateyInstall.ps1" target="tools" />
|
||||
<file src="tools\VERIFICATION.txt" target="tools" />
|
||||
</files>
|
||||
</package>
|
||||
25
packaging/chocolatey/tools/chocolateyInstall.ps1
Normal file
25
packaging/chocolatey/tools/chocolateyInstall.ps1
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
if (-not (Get-OSArchitectureWidth -Compare 64) -or $env:ChocolateyForceX86 -eq 'true') {
|
||||
throw 'SuperSlicer MSI requires Windows x64; a 32-bit installation is not available.'
|
||||
}
|
||||
|
||||
# Do not silently replace a portable installation or erase its profiles/settings.
|
||||
$toolsDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
||||
$portableDirectories = @(Get-ChildItem -LiteralPath $toolsDirectory -Directory -Filter 'SuperSlicer_*')
|
||||
$portableShim = Join-Path $env:ChocolateyInstall 'bin/superslicer.exe'
|
||||
if ($portableDirectories.Count -gt 0 -or (Test-Path -LiteralPath $portableShim)) {
|
||||
throw 'Legacy portable SuperSlicer detected. Back up your settings and uninstall the old portable Chocolatey package before installing the MSI package. No files have been removed.'
|
||||
}
|
||||
|
||||
$packageArgs = @{
|
||||
packageName = $env:ChocolateyPackageName
|
||||
softwareName = 'SuperSlicer'
|
||||
fileType = 'msi'
|
||||
url64bit = '@MSI_URL@'
|
||||
checksum64 = '@SHA256@'
|
||||
checksumType64 = 'sha256'
|
||||
silentArgs = '/qn /norestart'
|
||||
validExitCodes = @(0, 1641, 3010)
|
||||
}
|
||||
Install-ChocolateyPackage @packageArgs
|
||||
Loading…
Add table
Reference in a new issue