Skip to content
Open
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
385 changes: 385 additions & 0 deletions .github/workflows/desktop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,385 @@
name: Desktop app

# The CraftBot desktop app in desktop/ (Rust + Tauri), built on the
# launcher's core (launcher/core/).
#
# On pushes and pull requests: test and build it on every platform it ships
# for. On a v* tag: build the installers, sign them where the signing
# secrets exist (the same ones the Release workflow uses for the setup
# window), and attach them to that tag's release once the Release workflow
# has published it. It runs apart from Release so a failure here never holds
# up the rest of a release.

on:
push:
# Branch pushes need naming as soon as tags are: with tags alone, GitHub
# runs the workflow for tags only. Paths are not checked for tags.
branches:
- "**"
tags:
- "v*"
paths:
- "desktop/**"
- "launcher/core/**"
- ".cargo/config.toml"
- "app/provision/python_downloads.json"
- ".github/workflows/desktop.yml"
pull_request:
paths:
- "desktop/**"
- "launcher/core/**"
- ".cargo/config.toml"
- "app/provision/python_downloads.json"
- ".github/workflows/desktop.yml"
workflow_dispatch:

permissions:
contents: write

env:
CARGO_TERM_COLOR: always
TAURI_CLI: "@tauri-apps/cli@2.12.6"
# The CraftBot release the app installs (launcher/core/build.rs).
CRAFTBOT_VERSION: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || '' }}

jobs:
linux:
name: Linux ${{ matrix.arch }}
# The oldest Ubuntu with WebKitGTK 4.1: packages built here install on
# it and everything newer.
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
runner: ubuntu-22.04
- arch: aarch64
runner: ubuntu-22.04-arm
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build prerequisites
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libayatana-appindicator3-dev \
librsvg2-dev libxdo-dev libssl-dev file patchelf

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: desktop
prefix-key: desktop-${{ matrix.runner }}

- name: Lint
working-directory: desktop
run: |
cargo fmt -- --check
cargo clippy --release --all-targets -- -D warnings

- name: Set up Node (Tauri CLI)
uses: actions/setup-node@v4
with:
node-version: 22

- name: Test
working-directory: desktop
run: cargo test --release

- name: Build
working-directory: desktop
run: |
set -euo pipefail
version="${CRAFTBOT_VERSION#v}"
config="{\"version\":\"${version:-0.1.0}\"}"
npx --yes "$TAURI_CLI" build --bundles deb rpm appimage --config "$config"

- name: Package
run: |
set -euo pipefail
mkdir -p dist
b=desktop/target/release/bundle
cp "$b"/deb/*.deb "dist/CraftBot-linux-${{ matrix.arch }}.deb"
cp "$b"/rpm/*.rpm "dist/CraftBot-linux-${{ matrix.arch }}.rpm"
cp "$b"/appimage/*.AppImage "dist/CraftBot-linux-${{ matrix.arch }}.AppImage"
ls -la dist/

- name: Upload
uses: actions/upload-artifact@v4
with:
name: desktop-linux-${{ matrix.arch }}
path: dist/*

windows:
name: Windows
runs-on: windows-latest
outputs:
signed: ${{ steps.sign-state.outputs.signed }}
env:
HAS_SIGNING: ${{ secrets.AZURE_TENANT_ID != '' && secrets.AZURE_CLIENT_ID != '' && secrets.AZURE_CLIENT_SECRET != '' && secrets.TRUSTED_SIGNING_ENDPOINT != '' && secrets.TRUSTED_SIGNING_ACCOUNT != '' && secrets.TRUSTED_SIGNING_PROFILE != '' }}
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: desktop
prefix-key: desktop-windows-latest

- name: Set up Node (Tauri CLI)
uses: actions/setup-node@v4
with:
node-version: 22

- name: Test
working-directory: desktop
run: cargo test --release

- name: Version
run: |
version="${CRAFTBOT_VERSION#v}"
echo "APP_CONFIG={\"version\":\"${version:-0.1.0}\"}" >> "$GITHUB_ENV"

# The app is signed before it is packed into the installer, and the
# installer after: Smart App Control checks both.
- name: Build
working-directory: desktop
run: npx --yes "$TAURI_CLI" build --no-bundle --config "$APP_CONFIG"

- name: Sign the app
if: env.HAS_SIGNING == 'true' && startsWith(github.ref, 'refs/tags/v')
uses: azure/artifact-signing-action@v2
with:
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }}
azure-client-id: ${{ secrets.AZURE_CLIENT_ID }}
azure-client-secret: ${{ secrets.AZURE_CLIENT_SECRET }}
endpoint: ${{ secrets.TRUSTED_SIGNING_ENDPOINT }}
signing-account-name: ${{ secrets.TRUSTED_SIGNING_ACCOUNT }}
certificate-profile-name: ${{ secrets.TRUSTED_SIGNING_PROFILE }}
files: ${{ github.workspace }}\desktop\target\release\craftbot-desktop.exe
file-digest: SHA256
timestamp-rfc3161: http://timestamp.acs.microsoft.com
timestamp-digest: SHA256

- name: Bundle
working-directory: desktop
run: npx --yes "$TAURI_CLI" bundle --bundles nsis --config "$APP_CONFIG"

- name: Package
run: |
set -euo pipefail
mkdir -p dist
cp desktop/target/release/bundle/nsis/*-setup.exe dist/CraftBot-windows-setup.exe
ls -la dist/

- name: Sign the installer
if: env.HAS_SIGNING == 'true' && startsWith(github.ref, 'refs/tags/v')
uses: azure/artifact-signing-action@v2
with:
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }}
azure-client-id: ${{ secrets.AZURE_CLIENT_ID }}
azure-client-secret: ${{ secrets.AZURE_CLIENT_SECRET }}
endpoint: ${{ secrets.TRUSTED_SIGNING_ENDPOINT }}
signing-account-name: ${{ secrets.TRUSTED_SIGNING_ACCOUNT }}
certificate-profile-name: ${{ secrets.TRUSTED_SIGNING_PROFILE }}
files: ${{ github.workspace }}\dist\CraftBot-windows-setup.exe
file-digest: SHA256
timestamp-rfc3161: http://timestamp.acs.microsoft.com
timestamp-digest: SHA256

- name: Record signing state
id: sign-state
run: |
if [ "$HAS_SIGNING" = "true" ] && [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "signed=true" >> "$GITHUB_OUTPUT"
else
echo "signed=false" >> "$GITHUB_OUTPUT"
fi

- name: Upload
uses: actions/upload-artifact@v4
with:
name: desktop-windows
path: dist/*

macos:
name: macOS (universal)
runs-on: macos-15
outputs:
notarized: ${{ steps.notarize-state.outputs.notarized }}
env:
HAS_CERT: ${{ secrets.MACOS_CERT_P12_BASE64 != '' && secrets.MACOS_CERT_PASSWORD != '' }}
HAS_NOTARY: ${{ secrets.APPLE_ID != '' && secrets.APPLE_TEAM_ID != '' && secrets.APPLE_APP_PASSWORD != '' }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-apple-darwin,x86_64-apple-darwin

- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: desktop
prefix-key: desktop-macos-15

- name: Set up Node (Tauri CLI)
uses: actions/setup-node@v4
with:
node-version: 22

- name: Test
working-directory: desktop
run: cargo test --release

- name: Import the Developer ID certificate
if: env.HAS_CERT == 'true' && startsWith(github.ref, 'refs/tags/v')
env:
MACOS_CERT_P12_BASE64: ${{ secrets.MACOS_CERT_P12_BASE64 }}
MACOS_CERT_PASSWORD: ${{ secrets.MACOS_CERT_PASSWORD }}
run: |
set -euo pipefail
keychain="$RUNNER_TEMP/signing.keychain-db"
keychain_password="$(openssl rand -base64 24)"
security create-keychain -p "$keychain_password" "$keychain"
security set-keychain-settings -lut 21600 "$keychain"
security unlock-keychain -p "$keychain_password" "$keychain"
printf '%s' "$MACOS_CERT_P12_BASE64" | base64 --decode > "$RUNNER_TEMP/cert.p12"
security import "$RUNNER_TEMP/cert.p12" -k "$keychain" \
-P "$MACOS_CERT_PASSWORD" -T /usr/bin/codesign
rm -f "$RUNNER_TEMP/cert.p12"
security set-key-partition-list -S apple-tool:,apple:,codesign: \
-s -k "$keychain_password" "$keychain" >/dev/null
security list-keychains -d user -s "$keychain" \
$(security list-keychains -d user | tr -d '"')
identity="$(security find-identity -v -p codesigning "$keychain" \
| awk -F'"' '/Developer ID Application/ {print $2; exit}')"
if [ -z "$identity" ]; then
echo "::error::the certificate holds no 'Developer ID Application' identity"
exit 1
fi
echo "MACOS_SIGN_IDENTITY=$identity" >> "$GITHUB_ENV"

# With a Developer ID identity Tauri signs with the hardened runtime
# and, given the Apple ID variables, notarizes and staples the app.
# Without one it is ad-hoc signed ("-").
- name: Build
working-directory: desktop
env:
NOTARY_APPLE_ID: ${{ secrets.APPLE_ID }}
NOTARY_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
NOTARY_PASSWORD: ${{ secrets.APPLE_APP_PASSWORD }}
run: |
set -euo pipefail
export APPLE_SIGNING_IDENTITY="${MACOS_SIGN_IDENTITY:--}"
if [ -n "${MACOS_SIGN_IDENTITY:-}" ] && [ "$HAS_NOTARY" = "true" ]; then
export APPLE_ID="$NOTARY_APPLE_ID" APPLE_TEAM_ID="$NOTARY_TEAM_ID" APPLE_PASSWORD="$NOTARY_PASSWORD"
fi
version="${CRAFTBOT_VERSION#v}"
npx --yes "$TAURI_CLI" build --target universal-apple-darwin --bundles app dmg \
--config "{\"version\":\"${version:-0.1.0}\"}"

- name: Record notarization state
id: notarize-state
run: |
if [ -n "${MACOS_SIGN_IDENTITY:-}" ] && [ "$HAS_NOTARY" = "true" ]; then
echo "notarized=true" >> "$GITHUB_OUTPUT"
else
echo "notarized=false" >> "$GITHUB_OUTPUT"
fi

- name: Package
run: |
set -euo pipefail
mkdir -p dist
cp desktop/target/universal-apple-darwin/release/bundle/dmg/*.dmg dist/CraftBot-macos.dmg
ls -la dist/

- name: Remove the signing keychain
if: always() && env.HAS_CERT == 'true' && startsWith(github.ref, 'refs/tags/v')
run: security delete-keychain "$RUNNER_TEMP/signing.keychain-db" || true

- name: Upload
uses: actions/upload-artifact@v4
with:
name: desktop-macos
path: dist/*

# On a tag: wait for the Release workflow to publish the release, then add
# the installers and a section about them to its notes.
attach:
name: Attach to the release
if: startsWith(github.ref, 'refs/tags/v')
needs: [linux, windows, macos]
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TAG: ${{ github.ref_name }}
WINDOWS_SIGNED: ${{ needs.windows.outputs.signed }}
MACOS_NOTARIZED: ${{ needs.macos.outputs.notarized }}
steps:
- name: Download the installers
uses: actions/download-artifact@v4
with:
path: dist
pattern: desktop-*
merge-multiple: true

- name: Wait for the release
run: |
for _ in $(seq 1 120); do
gh release view "$TAG" >/dev/null 2>&1 && exit 0
sleep 30
done
echo "::error::the release for $TAG did not appear within an hour"
exit 1

- name: Upload and describe
run: |
set -euo pipefail
gh release upload "$TAG" dist/* --clobber
gh release view "$TAG" --json body -q .body > notes.md
if ! grep -q '^### CraftBot app' notes.md; then
{
echo
echo '### CraftBot app'
echo
echo 'CraftBot in its own window, with a tray icon. It installs CraftBot the first'
echo 'time you open it, starts it when it is not running, and keeps it running in'
echo 'the background when you close the window.'
echo
echo '| Computer | Download |'
echo '|---|---|'
echo '| Windows 10 or 11 | `CraftBot-windows-setup.exe` |'
echo '| macOS 12 or later, Apple silicon or Intel | `CraftBot-macos.dmg` |'
echo '| Linux, x86_64 | `CraftBot-linux-x86_64.AppImage`, `.deb` or `.rpm` |'
echo '| Linux, ARM64 | `CraftBot-linux-aarch64.AppImage`, `.deb` or `.rpm` |'
if [ "$WINDOWS_SIGNED" != "true" ]; then
echo
echo 'The Windows app is not code-signed: if SmartScreen stops it, select'
echo '**More info**, then **Run anyway**.'
fi
if [ "$MACOS_NOTARIZED" != "true" ]; then
echo
echo 'The macOS app is not notarized: after the first attempt to open it, select'
echo '**Open Anyway** in **System Settings > Privacy & Security**.'
fi
} >> notes.md
gh release edit "$TAG" --notes-file notes.md
fi
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ jobs:
set -euo pipefail
# The oldest macOS the binary is built for is the one the launcher
# checks for, from the same constant.
MACOSX_DEPLOYMENT_TARGET="$(sed -n 's/^pub const MIN_MACOS: &str = "\(.*\)";/\1/p' src/preflight.rs)"
MACOSX_DEPLOYMENT_TARGET="$(sed -n 's/^pub const MIN_MACOS: &str = "\(.*\)";/\1/p' core/src/preflight.rs)"
export MACOSX_DEPLOYMENT_TARGET
echo "MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET"
cargo build --release --target aarch64-apple-darwin
Expand Down
Loading
Loading