mirror of
https://github.com/JoshiCodes/knock.git
synced 2026-12-04 15:09:41 +01:00
131 lines
5.9 KiB
YAML
131 lines
5.9 KiB
YAML
name: ci
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ['v*']
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
# The runner is arm64 with 2 CPUs. Job containers ask for at most that many,
|
|
# and JavaScript actions need node inside the container, so it comes first.
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: rust:1-bookworm
|
|
options: --cpus 2
|
|
steps:
|
|
- name: Install node and build dependencies
|
|
run: |
|
|
apt-get update
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs \
|
|
libwebkit2gtk-4.1-dev libgtk-3-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev librsvg2-dev libdbus-1-dev pkg-config
|
|
- uses: actions/checkout@v4
|
|
- run: cargo test -p knock-core --locked
|
|
|
|
# amd64 packages, cross-compiled on the arm64 runner. Ubuntu 22.04 is the
|
|
# oldest supported target, so glibc and WebKitGTK fit 22.04 and newer.
|
|
# No AppImage: its tooling only runs on amd64.
|
|
packages:
|
|
needs: test
|
|
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: ubuntu:22.04
|
|
options: --cpus 2
|
|
env:
|
|
DEBIAN_FRONTEND: noninteractive
|
|
TARGET: x86_64-unknown-linux-gnu
|
|
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: x86_64-linux-gnu-gcc
|
|
CC_x86_64_unknown_linux_gnu: x86_64-linux-gnu-gcc
|
|
CXX_x86_64_unknown_linux_gnu: x86_64-linux-gnu-g++
|
|
AR_x86_64_unknown_linux_gnu: x86_64-linux-gnu-ar
|
|
PKG_CONFIG_ALLOW_CROSS: '1'
|
|
PKG_CONFIG_SYSROOT_DIR: /
|
|
PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig
|
|
steps:
|
|
- name: Install node
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y curl ca-certificates gnupg git
|
|
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
|
|
apt-get install -y nodejs
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Add amd64 as a foreign architecture
|
|
run: |
|
|
# arm64 comes from ports.ubuntu.com, amd64 from the main archive.
|
|
sed -i -E 's/^deb (http)/deb [arch=arm64] \1/' /etc/apt/sources.list
|
|
cat > /etc/apt/sources.list.d/amd64.list <<'EOF'
|
|
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
|
|
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
|
|
deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
|
|
EOF
|
|
dpkg --add-architecture amd64
|
|
apt-get update
|
|
|
|
- name: Install cross toolchain and amd64 libraries
|
|
run: |
|
|
apt-get install -y build-essential pkg-config file cmake \
|
|
gcc-x86-64-linux-gnu g++-x86-64-linux-gnu libc6-dev-amd64-cross \
|
|
libwebkit2gtk-4.1-dev:amd64 libgtk-3-dev:amd64 libsoup-3.0-dev:amd64 \
|
|
libjavascriptcoregtk-4.1-dev:amd64 librsvg2-dev:amd64 libdbus-1-dev:amd64
|
|
|
|
- name: Install Rust
|
|
run: |
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --target "$TARGET"
|
|
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
|
|
|
- name: Build
|
|
run: |
|
|
npm ci
|
|
cargo build --release --locked -p knock-cli --target "$TARGET"
|
|
BIN="../target/$TARGET/release/knock"
|
|
npx tauri build --target "$TARGET" --bundles deb,rpm \
|
|
--config "{\"bundle\":{\"linux\":{\"deb\":{\"files\":{\"/usr/bin/knock\":\"$BIN\"}},\"rpm\":{\"files\":{\"/usr/bin/knock\":\"$BIN\"}}}}}"
|
|
|
|
- name: Check packages
|
|
run: |
|
|
OUT="target/$TARGET/release/bundle"
|
|
DEB=$(ls $OUT/deb/*.deb)
|
|
fail() { echo "check failed: $1"; exit 1; }
|
|
CONTENTS=$(dpkg-deb -c "$DEB")
|
|
[ "$(dpkg-deb --field "$DEB" Architecture)" = amd64 ] || fail "deb architecture is not amd64"
|
|
echo "$CONTENTS" | grep -qE 'usr/bin/knock-app$' || fail "knock-app missing from the deb"
|
|
echo "$CONTENTS" | grep -qE 'usr/bin/knock$' || fail "knock CLI missing from the deb"
|
|
echo "$CONTENTS" | grep -qE 'usr/share/applications/.+\.desktop$' || fail "desktop entry missing from the deb"
|
|
file "target/$TARGET/release/knock-app" | grep -q 'x86-64' || fail "knock-app is not an x86-64 binary"
|
|
file "target/$TARGET/release/knock" | grep -q 'x86-64' || fail "knock is not an x86-64 binary"
|
|
# Nothing newer than Ubuntu 22.04's glibc (2.35) may be required.
|
|
too_new=$(x86_64-linux-gnu-objdump -T "target/$TARGET/release/knock-app" | grep -oE 'GLIBC_2\.[0-9]+' | sort -u | awk -F. '$2 > 35')
|
|
if [ -n "$too_new" ]; then echo "needs newer glibc than Ubuntu 22.04: $too_new"; exit 1; fi
|
|
ls -la $OUT/deb $OUT/rpm
|
|
|
|
- uses: actions/upload-artifact@v3
|
|
with:
|
|
name: packages-amd64
|
|
path: |
|
|
target/x86_64-unknown-linux-gnu/release/bundle/deb/*.deb
|
|
target/x86_64-unknown-linux-gnu/release/bundle/rpm/*.rpm
|
|
|
|
- name: Attach to release
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
env:
|
|
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
|
TAG: ${{ github.ref_name }}
|
|
run: |
|
|
apt-get install -y jq
|
|
id=$(curl -fsS -H "Authorization: token $TOKEN" "$API/releases/tags/$TAG" | jq -r .id || true)
|
|
if [ -z "$id" ] || [ "$id" = "null" ]; then
|
|
pre=$(case "$TAG" in *-*) echo true;; *) echo false;; esac)
|
|
id=$(curl -fsS -X POST -H "Authorization: token $TOKEN" -H 'Content-Type: application/json' \
|
|
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"prerelease\":$pre}" "$API/releases" | jq -r .id)
|
|
fi
|
|
for f in target/$TARGET/release/bundle/deb/*.deb target/$TARGET/release/bundle/rpm/*.rpm; do
|
|
curl -fsS -X POST -H "Authorization: token $TOKEN" -F "attachment=@$f" "$API/releases/$id/assets?name=$(basename "$f")"
|
|
done
|