Take screenshots #4545
This file contains hidden or 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
| name: Take screenshots | |
| on: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| workflow_dispatch: | |
| concurrency: | |
| group: take-screenshots | |
| cancel-in-progress: false | |
| jobs: | |
| shot-scraper: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.ref == 'refs/heads/main' }} | |
| steps: | |
| - name: Generate App token | |
| uses: actions/create-github-app-token@v1 | |
| id: app-token | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| - uses: actions/checkout@v4 | |
| with: | |
| # Latest main so a queued/long-running shot run doesn't push on top | |
| # of a stale tree. App token authenticates the push as a bypass | |
| # actor on the main ruleset, and the push triggers downstream | |
| # workflows (rust_tests → fly_deploy) naturally. | |
| ref: main | |
| token: ${{ steps.app-token.outputs.token }} | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: "3.10" | |
| - uses: actions/cache@v3 | |
| name: Configure pip caching | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Cache Playwright browsers | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/ms-playwright/ | |
| key: ${{ runner.os }}-browsers | |
| - name: Cache OxiPNG | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cargo/ | |
| key: ${{ runner.os }}-cargo | |
| - name: Install dependencies | |
| run: | | |
| pip install shot-scraper | |
| which oxipng || cargo install oxipng | |
| shot-scraper install | |
| - name: Take retina shots | |
| run: | | |
| shot-scraper multi live.shots.yml --retina | |
| - name: Optimize PNGs | |
| run: |- | |
| oxipng -o 4 -i 0 --strip safe screenshots/**/*.png | |
| - name: Get current date | |
| id: date | |
| run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | |
| - name: Commit and push if there are changes | |
| run: | | |
| git config user.name "${{ steps.app-token.outputs.app-slug }}[bot]" | |
| git config user.email "${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com" | |
| git add screenshots | |
| if git diff --staged --quiet; then | |
| echo "No screenshot changes — nothing to commit" | |
| else | |
| git commit -m "Update Daily Screenshot -- ${{ steps.date.outputs.date }}" | |
| # Rebase onto whatever main looks like *now* in case it moved | |
| # while screenshots were being taken/optimized. | |
| git pull --rebase origin main | |
| git push | |
| fi |