more shot-scraper updates #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Credit to Simon Willison for his awesome work: | |
# https://github.com/simonw/shot-scraper-template/blob/main/.github/workflows/shots.yml | |
name: screenshots | |
on: | |
push: | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
shot-scraper: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3.12 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- uses: actions/cache@v3 | |
name: Configure pip caching | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.screenshots.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Cache Playwright browsers | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/ms-playwright/ | |
key: ${{ runner.os }}-browsers | |
- name: Install dependencies | |
run: | | |
pip install -r requirements.screenshots.txt | |
- name: Install Playwright dependencies | |
run: | | |
shot-scraper install | |
- uses: actions/github-script@v7 | |
name: Create shots.yml if missing on first run | |
with: | |
script: | | |
const fs = require('fs'); | |
if (!fs.existsSync('shots.yml')) { | |
const desc = context.payload.repository.description; | |
let line = ''; | |
if (desc && (desc.startsWith('http://') || desc.startsWith('https://'))) { | |
line = `- url: ${desc}` + '\n output: shot.png\n height: 800'; | |
} else { | |
line = '# - url: https://www.example.com/\n# output: shot.png\n# height: 800'; | |
} | |
fs.writeFileSync('shots.yml', line + '\n'); | |
} | |
- name: Take shots | |
run: | | |
shot-scraper multi shots.yml | |
- name: Commit and push | |
run: |- | |
git config user.name "GitHub Action" | |
git config user.email "[email protected]" | |
git add -A | |
timestamp=$(date -u) | |
git commit -m "${timestamp}" || exit 0 | |
git pull --rebase | |
git push |