Skip to content

Update deadlines snapshot #913

Update deadlines snapshot

Update deadlines snapshot #913

# Author: Hao Cheng (cb1ock.github.com)
name: Update deadlines snapshot
on:
schedule:
- cron: '0 0 * * *' # Runs at 00:00
# push:
# branches: [ "main" ]
# pull_request:
# branches: [ "main" ]
workflow_dispatch:
permissions:
repository-projects: write
issues: write
contents: write # 修改为 write 权限以允许 push 操作
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }} # 使用 GITHUB_TOKEN 进行身份验证
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install Puppeteer
run: |
npm install puppeteer
- name: Take screenshot
run: |
node -e "const puppeteer = require('puppeteer');
(async () => {
try {
console.log('启动浏览器...');
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
// 设置更大的视口以显示更多内容
await page.setViewport({width: 1280, height: 960});
console.log('开始加载页面...');
// 使用更宽松的等待条件,提高超时时间
await page.goto('https://huggingface.co/spaces/huggingface/ai-deadlines', {
waitUntil: 'domcontentloaded', // 更宽松的等待条件
timeout: 120000 // 增加到120秒
});
console.log('页面基本加载完成');
// 确保 Images 目录存在
await require('fs').promises.mkdir('./Images', { recursive: true }).catch(() => {});
// 先截取当前可见内容(即使不完整)
await page.screenshot({path: './Images/DDL.png'});
console.log('已截取初始页面');
// 尝试等待更多内容加载
try {
await page.waitForSelector('main', {timeout: 15000});
console.log('main元素已加载');
await page.waitForTimeout(3000);
// 截取更新后的页面
await page.screenshot({path: './Images/DDL.png', fullPage: true});
console.log('已截取完整页面');
} catch (innerErr) {
console.log('等待元素超时,使用已有截图: ' + innerErr.message);
}
await browser.close();
console.log('浏览器已关闭');
} catch (err) {
console.error('发生错误: ' + err.message);
// 确保即使出错也返回成功,这样工作流可以继续
process.exit(0);
}
})();"
- name: Push changes
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git add ./Images/DDL.png
git commit -m "Update deadlines snapshot"
git push