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
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,43 @@ jobs:
else
npm publish --access public
fi

# tauri-plugin-python-cli (cli/) is a separate npm package with its own
# Trusted Publisher entry on npmjs.com.
publish-npm-cli:
name: Publish CLI to npm
runs-on: ubuntu-22.04
needs: release
environment: release
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: cli
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'

- name: Upgrade npm
run: npm install -g npm@latest

- name: check
run: |
npm install
npm run typecheck
npm test

- name: Publish to npm
run: |
NAME=$(node -p "require('./package.json').name")
VERSION=$(node -p "require('./package.json').version")
if [ -n "$(npm view "$NAME@$VERSION" version 2>/dev/null)" ]; then
echo "npm already has $NAME@$VERSION — skipping publish."
else
npm publish --access public
fi
148 changes: 133 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ jobs:
with:
path: tauri-plugin-python

# TEMP: the plugin's Cargo.toml has `[patch.crates-io] async_py = { path = "../async_py" }`
# until async_py 0.3.2 is published to crates.io. Remove this step (and the patch) afterwards.
- name: checkout async_py (local patch source)
uses: actions/checkout@v4
with:
repository: marcomq/async_py
path: async_py

- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
Expand Down Expand Up @@ -67,13 +59,6 @@ jobs:
with:
path: tauri-plugin-python

# TEMP: see note in the `lint` job. Remove once async_py 0.3.2 is on crates.io.
- name: checkout async_py (local patch source)
uses: actions/checkout@v4
with:
repository: marcomq/async_py
path: async_py

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
Expand Down Expand Up @@ -171,3 +156,136 @@ jobs:
echo "FAIL: app exited during startup (Python init likely panicked)."
exit 1
fi

cli:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: cli
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- run: npm install
- run: npm run typecheck
- run: npm test

# End-to-end deployment check: bundle a standalone Python with the CLI, build
# an installable app and start it from the install location with a minimal
# environment. The probe main.py reports which Python ran and what imports.
bundled-python:
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
bundle: app
- os: ubuntu-22.04
bundle: deb
- os: windows-latest
bundle: nsis
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
working-directory: examples/plain-javascript
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: lts/*

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
workspaces: examples/plain-javascript/src-tauri
key: bundled-python

- name: install dependencies (ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf xvfb

- name: use probe main.py
run: |
cp ci/probe_main.py src-tauri/src-python/main.py
echo markupsafe > src-tauri/src-python/requirements.txt

- name: bundle standalone Python
run: node ../../cli/bin/cli.js setup

- name: doctor (before build)
run: node ../../cli/bin/cli.js doctor

- name: build
run: |
npm install
npm run tauri build -- --bundles ${{ matrix.bundle }}

- name: doctor (after build)
run: node ../../cli/bin/cli.js doctor

- name: install app
id: install
run: |
DEST="$RUNNER_TEMP/installed"
BUNDLE=src-tauri/target/release/bundle
case "${{ runner.os }}" in
macOS)
mkdir -p "$DEST" && cp -R $BUNDLE/macos/*.app "$DEST/"
EXE=$(ls "$DEST"/*.app/Contents/MacOS/*) ;;
Linux)
dpkg -x $BUNDLE/deb/*.deb "$DEST"
EXE=$(ls "$DEST"/usr/bin/* | head -n1) ;;
Windows)
# The tauri NSIS installer ignores /D and installs per user to %LOCALAPPDATA%\<productName>.
PRODUCT=$(node -p "require('./src-tauri/tauri.conf.json').productName")
DEST="$(cygpath -u "$LOCALAPPDATA")/$PRODUCT"
$BUNDLE/nsis/*-setup.exe //S
for _ in $(seq 30); do
EXE=$(ls "$DEST"/*.exe 2>/dev/null | grep -vi uninstall | head -n1 || true)
[ -n "$EXE" ] && break
sleep 2
done
if [ -z "$EXE" ]; then
echo "No exe in $DEST"; ls -la "$DEST" "$(cygpath -u "$LOCALAPPDATA")"/plain* || true
exit 1
fi
EXE=$(cygpath -w "$EXE") ;;
esac
# The source copy must not be reachable as fallback.
rm -rf src-tauri/pyembed
echo "exe=$EXE" >> "$GITHUB_OUTPUT"

- name: start installed app
run: |
REPORT="$RUNNER_TEMP/report.txt"
if [ "${{ runner.os }}" = Linux ]; then
xvfb-run -a node ci/launch_bundled.mjs "${{ steps.install.outputs.exe }}" "$REPORT"
else
node ci/launch_bundled.mjs "${{ steps.install.outputs.exe }}" "$REPORT"
fi

# Like a user: apt-installs the .deb on a fresh Ubuntu without any Python.
- name: install and start in a clean container (no Python)
if: runner.os == 'Linux'
run: |
DEB=$(ls src-tauri/target/release/bundle/deb/*.deb)
docker run --rm \
-v "$PWD:/work:ro" -v "$(dirname "$(command -v node)"):/opt/node:ro" \
-e DEB="/work/$DEB" ubuntu:22.04 bash -euo pipefail -c '
export DEBIAN_FRONTEND=noninteractive PATH="/opt/node:$PATH"
apt-get update -qq
apt-get install -y -qq --no-install-recommends "$DEB" xvfb xauth > /dev/null
if compgen -G "/usr/lib/*/libpython3*" > /dev/null || command -v python3; then
echo "FAIL: the container has a system Python"; exit 1
fi
EXE=$(dpkg -L "$(dpkg-deb -f "$DEB" Package)" | grep "^/usr/bin/" | head -n1)
mkdir -p /tmp/run
xvfb-run -a node /work/ci/launch_bundled.mjs "$EXE" /tmp/run/report.txt
'
Loading
Loading