diff --git a/.github/scripts/winget_fetch.sh b/.github/scripts/winget_fetch.sh new file mode 100755 index 0000000..7e86f6d --- /dev/null +++ b/.github/scripts/winget_fetch.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Download the WinGet manifests for one version from the lazyunity- branch of +# ManeFunction/winget-pkgs (the branch GoReleaser opens the microsoft/winget-pkgs PR from) +# into $MANIFEST_DIR. The version is $INPUT_VERSION, or the one in cmd/lazyunity/main.go. +set -euo pipefail + +version="${INPUT_VERSION:-}" +if [ -z "$version" ]; then + version="$(sed -n 's/^var version = "\([^"]*\)".*/\1/p' cmd/lazyunity/main.go)" +fi +if ! [[ "$version" =~ ^[0-9A-Za-z.+-]+$ ]]; then + echo "bad version: '$version'" >&2 + exit 1 +fi + +repo="ManeFunction/winget-pkgs" +ref="lazyunity-$version" +path="manifests/m/ManeFunction/lazyunity/$version" +echo "Fetching $repo@$ref:$path" + +mkdir -p "$MANIFEST_DIR" +for name in $(gh api "repos/$repo/contents/$path?ref=$ref" --jq '.[].name'); do + gh api "repos/$repo/contents/$path/$name?ref=$ref" -H "Accept: application/vnd.github.raw" > "$MANIFEST_DIR/$name" + echo " $name" +done diff --git a/.github/scripts/winget_schema.py b/.github/scripts/winget_schema.py new file mode 100644 index 0000000..2757749 --- /dev/null +++ b/.github/scripts/winget_schema.py @@ -0,0 +1,48 @@ +"""Validate a WinGet manifest folder against the JSON schemas its files declare. + +Each GoReleaser-generated file names its schema in a `# yaml-language-server: $schema=...` +comment; that schema is downloaded and the file is checked against it. Exits 1 on any error. + +Usage: python winget_schema.py +""" + +import json +import pathlib +import re +import sys +import urllib.request + +import jsonschema +import yaml + +SCHEMA_RE = re.compile(r"^#\s*yaml-language-server:\s*\$schema=(\S+)", re.MULTILINE) + + +def main() -> int: + folder = pathlib.Path(sys.argv[1]) + files = sorted(folder.glob("*.yaml")) + if not files: + print(f"no manifests in {folder}") + return 1 + + ok = True + for path in files: + text = path.read_text(encoding="utf-8") + match = SCHEMA_RE.search(text) + if not match: + print(f"{path.name}: no $schema comment") + ok = False + continue + url = match.group(1) + with urllib.request.urlopen(url, timeout=30) as response: + schema = json.load(response) + errors = list(jsonschema.Draft7Validator(schema).iter_errors(yaml.safe_load(text))) + print(f"{path.name}: {url} -> {'OK' if not errors else 'FAIL'}") + for error in errors: + ok = False + print(f" {list(error.path)}: {error.message}") + return 0 if ok else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/.github/workflows/winget-check.yml b/.github/workflows/winget-check.yml new file mode 100644 index 0000000..7640f0b --- /dev/null +++ b/.github/workflows/winget-check.yml @@ -0,0 +1,86 @@ +# Checks the WinGet manifests GoReleaser pushed to ManeFunction/winget-pkgs, so the three +# boxes of the microsoft/winget-pkgs pull request template can be ticked truthfully: +# the 1.28 schema (Linux), `winget validate` and `winget install --manifest` (Windows). +# Run it by hand after a release: Actions -> WinGet check -> Run workflow. +name: WinGet check + +on: + workflow_dispatch: + inputs: + version: + description: "Version to check, e.g. 0.1.0 (empty: the version in cmd/lazyunity/main.go)" + required: false + pull_request: + paths: + - .github/workflows/winget-check.yml + - .github/scripts/winget_schema.py + - .github/scripts/winget_fetch.sh + +permissions: + contents: read + +env: + INPUT_VERSION: ${{ inputs.version }} + MANIFEST_DIR: winget-manifest # relative to the workspace: Git Bash and pwsh both read it + +jobs: + schema: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Download the manifests + run: bash .github/scripts/winget_fetch.sh + env: + GH_TOKEN: ${{ github.token }} + + - name: Validate against the declared schema + run: | + python3 -m pip install --quiet jsonschema==4.26.0 PyYAML==6.0.4 + python3 .github/scripts/winget_schema.py "$MANIFEST_DIR" + + winget: + runs-on: windows-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Download the manifests + shell: bash + run: bash .github/scripts/winget_fetch.sh + env: + GH_TOKEN: ${{ github.token }} + + - name: Update winget to the latest release + # The runner image's winget lags behind (v1.11 in Dec 2026) and warns on the + # 1.28 schema headers, which makes `winget validate` exit non-zero + shell: pwsh + run: | + Install-Module Microsoft.WinGet.Client -Force -Scope CurrentUser -Repository PSGallery + Repair-WinGetPackageManager -Latest -Force # -AllUsers fails on the Server runner (0x80073CF1) + winget --version + + - name: winget validate + shell: pwsh + run: winget validate --manifest (Resolve-Path $env:MANIFEST_DIR).Path + + - name: winget install --manifest + shell: pwsh + run: | + winget settings --enable LocalManifestFiles + winget install --manifest (Resolve-Path $env:MANIFEST_DIR).Path --accept-package-agreements --accept-source-agreements --disable-interactivity + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + - name: Run the installed lazyunity + shell: pwsh + run: | + # winget puts the portable alias here; this step's PATH predates the install + $env:PATH = "$env:LOCALAPPDATA\Microsoft\WinGet\Links;$env:PATH" + lazyunity --version + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + - name: winget uninstall + shell: pwsh + run: | + winget list --name lazyunity --accept-source-agreements --disable-interactivity + winget uninstall --manifest (Resolve-Path $env:MANIFEST_DIR).Path --accept-source-agreements --disable-interactivity + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }