Skip to content

Commit

Permalink
feat: add shot-scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
monodot committed Jan 18, 2025
1 parent 9e21273 commit a6afe26
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/screenshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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 "Automated"
git config user.email "[email protected]"
git add -A
timestamp=$(date -u)
git commit -m "${timestamp}" || exit 0
git pull --rebase
git push
1 change: 1 addition & 0 deletions requirements.screenshots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shot-scraper
4 changes: 4 additions & 0 deletions shots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- url: https://manikure.netlify.app/
output: application.png
width: 1280
height: 800

0 comments on commit a6afe26

Please sign in to comment.