Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file> -R zompinc/plugctl` (or oci://<image>) 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<version> 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:
Expand All @@ -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
Expand Down Expand Up @@ -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 }
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions choco/plugctl.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- The Chocolatey package. The Release workflow packs it with the release's version, and fills
in the download URL and checksum in tools/chocolateyInstall.ps1. -->
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>plugctl</id>
<version>0.0.0</version>
<title>plugctl</title>
<authors>Zomp Inc.</authors>
<owners>zompinc</owners>
<projectUrl>https://github.com/zompinc/plugctl</projectUrl>
<projectSourceUrl>https://github.com/zompinc/plugctl</projectSourceUrl>
<packageSourceUrl>https://github.com/zompinc/plugctl/tree/master/choco</packageSourceUrl>
<docsUrl>https://github.com/zompinc/plugctl#readme</docsUrl>
<bugTrackerUrl>https://github.com/zompinc/plugctl/issues</bugTrackerUrl>
<licenseUrl>https://github.com/zompinc/plugctl/blob/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright (c) 2026 Zomp Inc.</copyright>
<releaseNotes>https://github.com/zompinc/plugctl/releases</releaseNotes>
<tags>smart-plug kasa tp-link power-cycle cli</tags>
<summary>Switch or power-cycle smart plugs by MAC from scripts and CI.</summary>
<description>
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.
</description>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
12 changes: 12 additions & 0 deletions choco/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -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
Loading