jesse-r-s-hines_obsidian-op.../.github/workflows/test.yaml
2026-05-16 12:31:37 -04:00

181 lines
6.5 KiB
YAML

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Test
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
# Allow triggering the workflow manually and in check_for_new_obsidian.yaml
workflow_dispatch:
jobs:
test-desktop:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
# Enable these if you want to test your plugin on different platforms
# - windows-latest
# - macos-latest
runs-on: ${{ matrix.os }}
name: Test ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "24.x"
cache: 'npm'
- run: npm ci
- run: npm run build
- name: Run unit tests
run: npm run test:unit
# Get key to use for the .obsidian-cache GitHub cache. Run wdio.conf.mts directly,
# which will logs the Obsidian versions to test (see the `if (process.env.CI)` bit
# in wdio.conf.mts). We'll use that output as the cache key.
- name: "Get Obsidian cache key"
run: |
npx tsx wdio.conf.mts | grep 'obsidian-cache-key:' > obsidian-versions-lock.txt
# Delete the cache created by wdio.conf.mts so it doesn't conflict with restore
rm -rf .obsidian-cache
env:
# Beta versions require an Obsidian Insiders account to download. If you want to
# test beta versions, you'll need add your credentials to GitHub secrets as
# OBSIDIAN_EMAIL and OBSIDIAN_PASSWORD. 2FA needs to be disabled.
# Note that workflows triggered by fork PRs won't have access to GitHub secrets.
OBSIDIAN_EMAIL: ${{ secrets.OBSIDIAN_EMAIL }}
OBSIDIAN_PASSWORD: ${{ secrets.OBSIDIAN_PASSWORD }}
- name: Cache Obsidian
uses: actions/cache@v4
with:
path: .obsidian-cache
key: obsidian-cache-${{ matrix.os }}-${{ hashFiles('obsidian-versions-lock.txt') }}
# On linux runners we need to set up a virtual graphics stack for Obsidian. Here we
# use xvfb as a virtual display server and herbstluftwm as the window manager. (You
# can sometimes get by without the window manager, but some Obsidian features won't
# work properly wihtout it.)
- if: ${{ matrix.os == 'ubuntu-latest' }}
name: "Setup virtual graphics"
run: |
# Some hacks to speed up apt install
sudo rm -rf /etc/apt/sources.list.d/*.list
echo "set man-db/auto-update false" | sudo debconf-communicate
sudo dpkg-reconfigure man-db
sudo apt-get update -q
sudo apt-get install -q herbstluftwm dzen2 x11-xserver-utils
export DISPLAY=:99
echo "DISPLAY=$DISPLAY" >> "$GITHUB_ENV"
Xvfb $DISPLAY -screen 0 1280x1024x24 +extension GLX -noreset &
sleep 1
herbstluftwm &
sleep 1
- name: Run e2e tests
run: npm run test:e2e
env:
WDIO_MAX_INSTANCES: 2
OBSIDIAN_EMAIL: ${{ secrets.OBSIDIAN_EMAIL }}
OBSIDIAN_PASSWORD: ${{ secrets.OBSIDIAN_PASSWORD }}
# If you want to test on the real Obsidian Android app, enable this job. You'll need to
# set up a `"test:android": "wdio run ./wdio.mobile.conf.mts"` script, and install the
# appium dependencies. See https://jesse-r-s-hines.github.io/wdio-obsidian-service/wdio-obsidian-service/README#android
# test-android:
# env:
# AVD_ARGS: "-no-metrics -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none"
# strategy:
# fail-fast: false
# matrix:
# include:
# - obsidian-version: latest
# android-api-level: 36
# android-profile: pixel
# - obsidian-version: earliest
# android-api-level: 36
# android-profile: pixel
# runs-on: ubuntu-latest
# name: test (android, api ${{ matrix.android-api-level }}, profile ${{ matrix.android-profile }}, obsidian ${{ matrix.obsidian-version }})
# defaults:
# run:
# shell: bash
# steps:
# - uses: actions/checkout@v4
# - name: Use Node.js
# uses: actions/setup-node@v4
# with:
# node-version: 24.x
# cache: 'npm'
# - run: npm ci
# - run: npm run build
# - name: "Get Obsidian cache key"
# shell: bash
# run: |
# npx tsx wdio.mobile.conf.mts | grep 'obsidian-cache-key:' > obsidian-versions-lock.txt
# rm -rf .obsidian-cache
# env:
# OBSIDIAN_EMAIL: ${{ secrets.OBSIDIAN_EMAIL }}
# OBSIDIAN_PASSWORD: ${{ secrets.OBSIDIAN_PASSWORD }}
# - name: Cache .obsidian-cache
# uses: actions/cache@v4
# with:
# path: .obsidian-cache
# key: obsidian-cache-android-${{ hashFiles('obsidian-versions-lock.txt') }}
# - name: Enable KVM
# run: |
# echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
# sudo udevadm control --reload-rules
# sudo udevadm trigger --name-match=kvm
# - name: AVD cache
# id: avd-cache
# uses: actions/cache@v4
# with:
# path: |
# ~/.android/avd/*
# ~/.android/adb*
# key: avd-${{ matrix.android-api-level }}-${{ matrix.android-profile }}
# - name: run android tests
# uses: reactivecircus/android-emulator-runner@v2
# with:
# force-avd-creation: false
# avd-name: obsidian_test
# emulator-options: -no-snapshot ${{ env.AVD_ARGS }}
# api-level: ${{ matrix.android-api-level }}
# arch: "x86_64"
# target: google_apis
# profile: ${{ matrix.android-profile }}
# disk-size: 4096M
# heap-size: 512M
# script: npm run test:android
# env:
# OBSIDIAN_VERSIONS: ${{ matrix.obsidian-version }}
# OBSIDIAN_EMAIL: ${{ secrets.OBSIDIAN_EMAIL }}
# OBSIDIAN_PASSWORD: ${{ secrets.OBSIDIAN_PASSWORD }}
# This makes it easier to require all tests to pass on PRs without having to manually
# add every matrix option in the GitHub repo settings.
check:
if: always()
needs: [test-desktop]
runs-on: ubuntu-latest
steps:
- name: Check all tests passed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}