Build and Generate OG Previews #620
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: Build and Generate OG Previews | |
| on: | |
| schedule: | |
| # Run once per day at 3:00 AM UTC (full regeneration with --force) | |
| - cron: '0 3 * * *' | |
| workflow_dispatch: # Allow manual trigger | |
| push: | |
| branches: [master] | |
| paths: | |
| - 'scripts/generate-og.py' | |
| - 'docs/**/*.md' | |
| - 'docs-new/**/*.md' | |
| jobs: | |
| build-opengraph-previews: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/master') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install ImageMagick | |
| run: sudo apt-get update && sudo apt-get install -y imagemagick | |
| - name: Install Python dependencies | |
| run: pip install pyyaml | |
| - name: Download previous OG previews artifact | |
| uses: dawidd6/action-download-artifact@v6 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| workflow: og-previews.yaml | |
| name: og-preview-images | |
| path: resources/public/og-preview/ | |
| if_no_artifact_found: warn | |
| - name: Check if generate-og.py changed | |
| id: check-script | |
| run: | | |
| # Check if script changed in this push (only works for push events with before ref) | |
| if [ -n "${{ github.event.before }}" ] && [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then | |
| if git diff --name-only ${{ github.event.before }} ${{ github.sha }} 2>/dev/null | grep -q 'scripts/generate-og.py'; then | |
| echo "script_changed=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| fi | |
| echo "script_changed=false" >> $GITHUB_OUTPUT | |
| - name: Generate OG images | |
| run: | | |
| if [ "${{ github.event_name }}" = "schedule" ] || [ "${{ github.event_name }}" = "workflow_dispatch" ] || [ "${{ steps.check-script.outputs.script_changed }}" = "true" ]; then | |
| echo "Full regeneration - regenerating all images" | |
| python3 scripts/generate-og.py --force all | |
| else | |
| echo "Incremental run - generating only new images" | |
| python3 scripts/generate-og.py all | |
| fi | |
| - name: Upload OG previews artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: og-preview-images | |
| path: resources/public/og-preview/* | |
| retention-days: 90 | |
| overwrite: true |