Files
knock/.github/workflows/release.yml
T

142 lines
5.1 KiB
YAML

name: release
# Runs on the GitHub mirror only (Gitea uses .gitea/workflows). macOS and
# Windows minutes are expensive on private repositories, so this runs for
# tags and on demand, not on every push.
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
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)
run: npx tauri build --target universal-apple-darwin --bundles app,dmg
- 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
# 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
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)
run: npx tauri build --bundles msi,nsis
- 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
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
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
- name: Attach to the GitHub release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
pre=""
case "$TAG" in *-*) pre="--prerelease";; esac
gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1 \
|| gh release create "$TAG" -R "$GITHUB_REPOSITORY" --title "$TAG" --notes "" $pre
find artifacts -type f -exec gh release upload "$TAG" -R "$GITHUB_REPOSITORY" --clobber {} +