diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9d8f92f..ec54826 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,13 +3,13 @@ name: Release # Builds plugctl for each platform and publishes a GitHub release with the archives, plus the # container image ghcr.io/zompinc/plugctl built from the Linux binaries. Both carry build # provenance: `gh attestation verify -R zompinc/plugctl` (or oci://) checks that -# this workflow built them, and from which commit. +# this workflow built them, and from which commit. The Windows build also goes to Chocolatey. # # - Run it from the Actions tab (workflow_dispatch) on master: it tags the commit with the # version Nerdbank.GitVersioning calculates and publishes. # - Or push a tag v that matches that calculated version. -# - A pull request that changes this file or the Dockerfile builds everything but publishes -# nothing. +# - A pull request that changes this file, the Dockerfile or choco/ builds everything, and +# installs the Chocolatey package, but publishes nothing. env: ACT: @@ -21,7 +21,7 @@ on: tags: ["v*"] pull_request: branches: [master] - paths: [.github/workflows/release.yml, Dockerfile, .dockerignore] + paths: [.github/workflows/release.yml, Dockerfile, .dockerignore, choco/**] permissions: contents: read @@ -248,3 +248,67 @@ jobs: prerelease=; case "$VERSION" in *-*) prerelease=--prerelease;; esac gh release create "$tag" --repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" \ --title "plugctl $VERSION" --generate-notes $prerelease * + + # The Chocolatey package: packed, installed and run here, then pushed to the community + # repository, where each version waits for moderation before it is listed. A pull request + # installs from the build artifact instead of the (not yet published) release. + chocolatey: + needs: [version, build, publish] + if: ${{ !cancelled() && needs.build.result == 'success' && (needs.publish.result == 'success' || github.event_name == 'pull_request') }} + runs-on: windows-latest + env: + CAN_PUSH: ${{ secrets.CHOCOLATEY_PUSH_KEY != '' }} + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: plugctl-x86_64-pc-windows-msvc + path: dist + + - name: Pack + shell: pwsh + env: + VERSION: ${{ needs.version.outputs.version }} + run: | + $zip = Get-Item "dist/plugctl-$env:VERSION-x86_64-pc-windows-msvc.zip" + $url = if ($env:GITHUB_EVENT_NAME -eq 'pull_request') { + ([uri]$zip.FullName).AbsoluteUri + } else { + "https://github.com/$env:GITHUB_REPOSITORY/releases/download/v$env:VERSION/$($zip.Name)" + } + $sum = (Get-FileHash $zip -Algorithm SHA256).Hash.ToLower() + $script = 'choco/tools/chocolateyInstall.ps1' + (Get-Content $script -Raw).Replace('__URL64__', $url).Replace('__CHECKSUM64__', $sum) | + Set-Content $script -NoNewline + choco pack choco/plugctl.nuspec --version $env:VERSION --out dist + if ($LASTEXITCODE) { exit $LASTEXITCODE } + + - name: Install and run + shell: pwsh + env: + VERSION: ${{ needs.version.outputs.version }} + run: | + choco install plugctl --source dist --version $env:VERSION --prerelease -y --no-progress + if ($LASTEXITCODE) { exit $LASTEXITCODE } + $out = plugctl --version + $out + if ($out -notmatch [regex]::Escape($env:VERSION)) { exit 1 } + choco uninstall plugctl -y --no-progress + if ($LASTEXITCODE) { exit $LASTEXITCODE } + + - uses: actions/upload-artifact@v4 + with: + name: chocolatey + path: dist/*.nupkg + if-no-files-found: error + retention-days: 5 + + - name: Push + if: ${{ github.event_name != 'pull_request' && env.CAN_PUSH == 'true' }} + shell: pwsh + env: + VERSION: ${{ needs.version.outputs.version }} + CHOCOLATEY_PUSH_KEY: ${{ secrets.CHOCOLATEY_PUSH_KEY }} + run: | + choco push "dist/plugctl.$env:VERSION.nupkg" --source https://push.chocolatey.org/ --api-key $env:CHOCOLATEY_PUSH_KEY + if ($LASTEXITCODE) { exit $LASTEXITCODE } diff --git a/README.md b/README.md index b20d996..5960ff4 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ TP-Link Kasa plugs come first, including firmware that only accepts KLAP (the en Download the archive for your platform from [Releases](https://github.com/zompinc/plugctl/releases) and put `plugctl` (or `plugctl.exe`) on your `PATH`. There are static Linux builds for x86_64 and aarch64 (which also run on aarch64 OpenWrt routers), Windows x86_64, and macOS on Apple silicon and Intel. `SHA256SUMS` lists each archive's checksum. +On Windows, Chocolatey installs it and puts it on `PATH` (`--pre` while releases are pre-releases; a new version appears once Chocolatey's moderators approve it): + +```powershell +choco install plugctl --pre +``` + Each archive and image carries a build provenance attestation, which shows that this repository's release workflow built it and from which commit: ```sh diff --git a/choco/plugctl.nuspec b/choco/plugctl.nuspec new file mode 100644 index 0000000..fd0c8a9 --- /dev/null +++ b/choco/plugctl.nuspec @@ -0,0 +1,37 @@ + + + + + plugctl + 0.0.0 + plugctl + Zomp Inc. + zompinc + https://github.com/zompinc/plugctl + https://github.com/zompinc/plugctl + https://github.com/zompinc/plugctl/tree/master/choco + https://github.com/zompinc/plugctl#readme + https://github.com/zompinc/plugctl/issues + https://github.com/zompinc/plugctl/blob/master/LICENSE + false + Copyright (c) 2026 Zomp Inc. + https://github.com/zompinc/plugctl/releases + smart-plug kasa tp-link power-cycle cli + Switch or power-cycle smart plugs by MAC from scripts and CI. + +plugctl switches or power-cycles smart plugs from scripts, CI jobs and Rust, as one binary with no Python or .NET at run time. It is built for power-cycling hardware under test. + +- TP-Link Kasa plugs, including firmware that only accepts KLAP. +- Plugs are identified by MAC, so a DHCP move cannot make it switch the wrong device. +- Protected plugs refuse off and cycle without --allow-protected. +- Each plug has a minimum off time. +- Plugs on an isolated network are reached through an SSH tunnel. + +Run `plugctl --help` to start, and see the README for the config file. + + + + + + diff --git a/choco/tools/chocolateyInstall.ps1 b/choco/tools/chocolateyInstall.ps1 new file mode 100644 index 0000000..62fdaab --- /dev/null +++ b/choco/tools/chocolateyInstall.ps1 @@ -0,0 +1,12 @@ +$ErrorActionPreference = 'Stop' + +# The Release workflow replaces the URL and checksum with the release's Windows archive. +# Chocolatey puts a shim for plugctl.exe on PATH. +$packageArgs = @{ + packageName = $env:ChocolateyPackageName + unzipLocation = Split-Path -Parent $MyInvocation.MyCommand.Definition + url64bit = '__URL64__' + checksum64 = '__CHECKSUM64__' + checksumType64 = 'sha256' +} +Install-ChocolateyZipPackage @packageArgs