name: release # Push a tag vX.Y.Z (scripts/release.sh does it) and this builds every # platform and publishes a GitHub release. Manual runs build without # releasing; pick platforms to save macOS and Windows minutes. on: push: tags: ['v*'] workflow_dispatch: inputs: platforms: description: 'Which builds to run: all, or a comma list of macos, windows, linux' default: all permissions: contents: write jobs: macos: if: github.event_name == 'push' || inputs.platforms == 'all' || contains(inputs.platforms, 'macos') runs-on: macos-latest env: TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: node-version: 22 cache: npm - name: Rust for both Mac architectures run: rustup target add aarch64-apple-darwin x86_64-apple-darwin - uses: Swatinem/rust-cache@v2 - run: npm ci - name: Test run: cargo test -p knock-core --locked - name: App (universal .app and .dmg, plus a signed update package) run: | # Update packages only when the signing key is available. extra="" if [ -n "$TAURI_SIGNING_PRIVATE_KEY" ]; then extra='--config {"bundle":{"createUpdaterArtifacts":true}}'; fi npx tauri build --target universal-apple-darwin --bundles app,dmg $extra v=$(node -p "require('./src-tauri/tauri.conf.json').version") mkdir -p dist-update b=target/universal-apple-darwin/release/bundle/macos if [ -f "$b/knock.app.tar.gz" ]; then cp "$b/knock.app.tar.gz" "dist-update/knock_${v}_universal.app.tar.gz" cp "$b/knock.app.tar.gz.sig" "dist-update/knock_${v}_universal.app.tar.gz.sig" fi - name: CLI (universal binary) run: | cargo build --release --locked -p knock-cli --target aarch64-apple-darwin cargo build --release --locked -p knock-cli --target x86_64-apple-darwin mkdir -p dist-cli lipo -create -output dist-cli/knock \ target/aarch64-apple-darwin/release/knock target/x86_64-apple-darwin/release/knock tar -czf knock-cli-macos-universal.tar.gz -C dist-cli knock - name: Check run: | lipo -archs dist-cli/knock | grep -q arm64 lipo -archs dist-cli/knock | grep -q x86_64 ls target/universal-apple-darwin/release/bundle/dmg/*.dmg ./dist-cli/knock --version - uses: actions/upload-artifact@v5 with: name: macos path: | target/universal-apple-darwin/release/bundle/dmg/*.dmg knock-cli-macos-universal.tar.gz dist-update/* # Best effort per the spec. windows: if: github.event_name == 'push' || inputs.platforms == 'all' || contains(inputs.platforms, 'windows') runs-on: windows-latest continue-on-error: true env: TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: node-version: 22 cache: npm - uses: Swatinem/rust-cache@v2 - run: npm ci - name: App (.msi and setup .exe, signed for updates) shell: bash run: | if [ -n "$TAURI_SIGNING_PRIVATE_KEY" ]; then npx tauri build --bundles msi,nsis --config '{"bundle":{"createUpdaterArtifacts":true}}' else npx tauri build --bundles msi,nsis fi - name: CLI shell: pwsh run: | cargo build --release --locked -p knock-cli Compress-Archive -Path target/release/knock.exe -DestinationPath knock-cli-windows-x64.zip - uses: actions/upload-artifact@v5 with: name: windows path: | target/release/bundle/msi/*.msi target/release/bundle/nsis/*.exe target/release/bundle/nsis/*.exe.sig knock-cli-windows-x64.zip # Native amd64 Linux build on Ubuntu 22.04, with the AppImage the arm64 # Gitea runner cannot make, and a real smoke test. linux: if: github.event_name == 'push' || inputs.platforms == 'all' || contains(inputs.platforms, 'linux') runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: node-version: 22 cache: npm - uses: Swatinem/rust-cache@v2 - name: System libraries run: | sudo apt-get update sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev libdbus-1-dev xvfb - run: npm ci - name: Build run: | cargo build --release --locked -p knock-cli npx tauri build --bundles deb,rpm,appimage - name: Smoke test on Ubuntu 22.04 run: | sudo apt-get install -y ./target/release/bundle/deb/*.deb python3 -m http.server 18765 >/dev/null 2>&1 & sleep 1 mkdir -p /tmp/c/environments printf 'version: 1\nname: Smoke\n' > /tmp/c/knock.yaml printf 'name: Root\nurl: http://127.0.0.1:18765/\nassert:\n - { on: status, equals: 200 }\n' > /tmp/c/root.yaml knock run /tmp/c timeout 10 xvfb-run -a knock-app || [ $? -eq 124 ] - uses: actions/upload-artifact@v5 with: name: linux path: | target/release/bundle/deb/*.deb target/release/bundle/rpm/*.rpm target/release/bundle/appimage/*.AppImage # Arch package for the pacman repository on Gitea, built from the deb. # Needs the secret GITEA_PACKAGES_TOKEN (a Gitea token with package write # access); without it the job is skipped. arch: if: startsWith(github.ref, 'refs/tags/v') needs: [linux] runs-on: ubuntu-latest container: archlinux:latest env: TOKEN: ${{ secrets.GITEA_PACKAGES_TOKEN }} REGISTRY: https://git.joshicodes.de/api/packages/JoshiCodes/arch/joshicodes steps: - uses: actions/checkout@v5 - uses: actions/download-artifact@v5 with: name: linux path: artifacts - name: Build knock-bin if: env.TOKEN != '' run: | pacman -Syu --noconfirm --needed base-devel useradd -m builder deb=$(find artifacts -name '*.deb' | head -1) tag="${GITHUB_REF_NAME#v}" ver="${tag//-/}" mkdir -p /build && cp packaging/arch/knock-bin/PKGBUILD /build/ && cp "$deb" /build/ cd /build name=$(basename "$deb") sed -i -E "s/^pkgver=.*/pkgver=$ver/; s/^pkgrel=.*/pkgrel=1/" PKGBUILD sed -i -E "s|^source=.*|source=(\"$name\")|" PKGBUILD chown -R builder /build su builder -c 'makepkg --nodeps --noconfirm' ls -la *.pkg.tar.zst - name: Upload to the Gitea pacman repository if: env.TOKEN != '' run: | for f in /build/*.pkg.tar.zst; do curl --fail-with-body -sS -X PUT --user "JoshiCodes:$TOKEN" --upload-file "$f" "$REGISTRY" done release: if: startsWith(github.ref, 'refs/tags/v') needs: [macos, linux, windows] runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v5 with: path: artifacts merge-multiple: true - name: Update manifest for macOS and Windows env: TAG: ${{ github.ref_name }} REPO: ${{ github.repository }} run: | cd artifacts v="${TAG#v}" base="https://github.com/$REPO/releases/download/$TAG" mac=$(ls *_universal.app.tar.gz 2>/dev/null | head -1 || true) win=$(ls *-setup.exe 2>/dev/null | head -1 || true) if [ -z "$mac$win" ]; then echo "no signed update packages, skipping latest.json"; exit 0; fi python3 - "$v" "$base" "$mac" "$win" <<'PY' import json, sys, datetime, os v, base, mac, win = sys.argv[1:5] platforms = {} def sig(f): return open(f + ".sig").read().strip() if f and os.path.exists(f + ".sig") else None if mac and sig(mac): for p in ("darwin-aarch64", "darwin-x86_64"): platforms[p] = {"signature": sig(mac), "url": f"{base}/{mac}"} if win and sig(win): platforms["windows-x86_64"] = {"signature": sig(win), "url": f"{base}/{win}"} json.dump({"version": v, "notes": f"knock {v}", "pub_date": datetime.datetime.now(datetime.timezone.utc).isoformat(), "platforms": platforms}, open("latest.json", "w"), indent=2) print(open("latest.json").read()) PY - name: Checksums run: | cd artifacts sha256sum * > SHA256SUMS cat SHA256SUMS - name: Publish release env: GH_TOKEN: ${{ github.token }} TAG: ${{ github.ref_name }} run: | pre="" case "$TAG" in *-*) pre="--prerelease";; esac if gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1; then gh release upload "$TAG" -R "$GITHUB_REPOSITORY" --clobber artifacts/* else gh release create "$TAG" -R "$GITHUB_REPOSITORY" --title "knock ${TAG#v}" --generate-notes $pre artifacts/* fi