Update PageSpeed Score #78
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: Update PageSpeed Score | |
| on: | |
| # Automatically run after Deploy CI workflow completes successfully | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: | |
| - completed | |
| # Allow manual run from the Actions tab | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| pagespeed: | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main repository | |
| uses: actions/checkout@v4 | |
| - name: Clone PageSpeed script repo | |
| run: git clone https://github.com/0x-br0k3n/readme-pagespeed-insights pagespeed-tool | |
| - name: Install dependencies for PageSpeed script | |
| working-directory: pagespeed-tool | |
| run: npm install | |
| - name: Create .env file with API key | |
| working-directory: pagespeed-tool | |
| run: echo "API_KEY=${{ secrets.API_KEY }}" > .env | |
| - name: Build and start the PageSpeed server in background | |
| working-directory: pagespeed-tool | |
| run: | | |
| npm run build | |
| nohup npm run start & | |
| - name: Wait for server to start | |
| run: sleep 10 | |
| - name: Generate SVGs using curl | |
| run: | | |
| mkdir -p assets/pagespeed | |
| BASE_URL="http://localhost:3000" # The tool will listen to port 3000 | |
| TARGET_URL_GH="https://0x-br0k3n.github.io/java" | |
| TARGET_URL_VERCEL="https://javanotes-br0k3n.vercel.app/" | |
| for theme in dark light; do | |
| for strategy in mobile desktop; do | |
| curl "${BASE_URL}/?url=${TARGET_URL_GH}&theme=${theme}&strategy=${strategy}&categories=performance,accessibility,best-practices,seo" > "assets/pagespeed/${strategy}_${theme}_gh.svg" | |
| curl "${BASE_URL}/?url=${TARGET_URL_VERCEL}&theme=${theme}&strategy=${strategy}&categories=performance,accessibility,best-practices,seo" > "assets/pagespeed/${strategy}_${theme}_vercel.svg" | |
| done | |
| done | |
| - name: Commit and push SVGs | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -f assets/pagespeed/ | |
| git commit -m "Update Pagespeed stats [CI]" || echo "No changes to commit" | |
| git push https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git HEAD:main |