plexi / .github /workflows /wake-up-streamlit.yml
LazyHuman10
Prepare Hugging Face Space deployment
fbe7a99
name: Keep Streamlit Warm
on:
schedule:
- cron: "0 */5 * * *"
workflow_dispatch:
jobs:
warm_app:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install Playwright
run: |
npm init -y
npm install playwright
npx playwright install --with-deps chromium
- name: Wake Streamlit Community Cloud app
env:
APP_URL: https://plexi-study.streamlit.app/
run: |
cat <<'EOF' > wake-streamlit.mjs
import { chromium } from "playwright";
const appUrl = process.env.APP_URL;
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
try {
await page.goto(appUrl, { waitUntil: "domcontentloaded", timeout: 90000 });
const wakeButton = page
.getByRole("button", { name: /yes, get this app back up|wake up/i })
.first();
if (await wakeButton.isVisible({ timeout: 10000 }).catch(() => false)) {
await wakeButton.click();
await page.waitForTimeout(8000);
console.log("App was asleep. Wake-up button clicked.");
} else {
console.log("Wake-up prompt not shown.");
}
await page.waitForSelector(
"[data-testid='stAppViewContainer'], section.main, div[data-testid='stApp']",
{ timeout: 90000 }
);
console.log("App is reachable.");
} finally {
await browser.close();
}
EOF
node wake-streamlit.mjs