-
Notifications
You must be signed in to change notification settings - Fork 200
feat: implement cronjob based sitemap automation #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amaan-bhati
wants to merge
12
commits into
main
Choose a base branch
from
sitemap-automation-cron
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f0c95c5
feat: implement cronjob based sitemap automation
amaan-bhati b643d3b
feat: address copiotreview#0, fix edge cases, implement calculated re…
amaan-bhati d9756d5
feat: remove accidentally commit file
amaan-bhati 1ea2a82
chore: downgrade node version in workflow, add a console error
amaan-bhati c477e8b
feat: date noramalisation, erorr loggin improvement
amaan-bhati 1eaa655
fix: normalize MAIN_SITE_URL to origin
amaan-bhati b3bef96
fix: add timeout to sitemap wordpress fetch
amaan-bhati 51a876c
fix: use service account auth for google sitemap submission
amaan-bhati 7d284a6
chore: rename sitemap submission log step
amaan-bhati eec8691
Merge branch 'main' into sitemap-automation-cron
nehagup 06a7363
feat: update lastmod fallback, image markup, priority, jwt refactor
amaan-bhati 164cc4f
chore: regenerate sitemap.xml to sync with updated generator output
amaan-bhati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| name: Submit Sitemap to Google | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - public/sitemap.xml | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| submit-google-sitemap: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| GOOGLE_SITEMAP_URL: https://keploy.io/blog/sitemap.xml | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 18 | ||
|
|
||
| - name: Install googleapis | ||
| run: npm install --no-save googleapis | ||
|
|
||
| - name: Validate Google Search Console secrets | ||
| env: | ||
| GOOGLE_SERVICE_ACCOUNT_EMAIL: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_EMAIL }} | ||
| GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY }} | ||
| GOOGLE_SEARCH_CONSOLE_SITE_URL: ${{ secrets.GOOGLE_SEARCH_CONSOLE_SITE_URL }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| for name in GOOGLE_SERVICE_ACCOUNT_EMAIL GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY GOOGLE_SEARCH_CONSOLE_SITE_URL; do | ||
| if [ -z "${!name}" ]; then | ||
| if [ "$name" = "GOOGLE_SEARCH_CONSOLE_SITE_URL" ]; then | ||
| echo "::error::Missing required secret: ${name}. Add it in GitHub Settings > Secrets and variables > Actions. Expected format: the exact Search Console property, for example sc-domain:keploy.io or https://keploy.io/." | ||
| elif [ "$name" = "GOOGLE_SERVICE_ACCOUNT_EMAIL" ]; then | ||
| echo "::error::Missing required secret: ${name}. Add the Google service account email in GitHub Settings > Secrets and variables > Actions, then re-run this workflow." | ||
| else | ||
| echo "::error::Missing required secret: ${name}. Add the Google service account private key in GitHub Settings > Secrets and variables > Actions, then re-run this workflow." | ||
| fi | ||
|
amaan-bhati marked this conversation as resolved.
|
||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| - name: Submit sitemap to Google Search Console | ||
| env: | ||
| GOOGLE_SERVICE_ACCOUNT_EMAIL: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_EMAIL }} | ||
| GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY }} | ||
| GOOGLE_SEARCH_CONSOLE_SITE_URL: ${{ secrets.GOOGLE_SEARCH_CONSOLE_SITE_URL }} | ||
| run: | | ||
| node - <<'EOF' | ||
| const { google } = require('googleapis'); | ||
|
|
||
| // GH Actions stores multi-line secrets with literal \n — normalise them. | ||
| const key = process.env.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY.replace(/\\n/g, '\n'); | ||
|
|
||
| const auth = new google.auth.JWT( | ||
| process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL, | ||
| null, | ||
| key, | ||
| ['https://www.googleapis.com/auth/webmasters'] | ||
| ); | ||
|
|
||
| const sc = google.webmasters({ version: 'v3', auth }); | ||
|
|
||
| sc.sitemaps.submit({ | ||
| siteUrl: process.env.GOOGLE_SEARCH_CONSOLE_SITE_URL, | ||
| feedpath: process.env.GOOGLE_SITEMAP_URL, | ||
| }).then(() => { | ||
| console.log('Submitted', process.env.GOOGLE_SITEMAP_URL, 'to Google Search Console'); | ||
| }).catch((err) => { | ||
| console.error('::error::Google Search Console submission failed:', err.message); | ||
| console.error('Next step: verify the service account email and private key match, ensure the Search Console API is enabled, and confirm the service account has access to the Search Console property.'); | ||
| process.exit(1); | ||
| }); | ||
| EOF | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| name: Sync Sitemap | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 6 * * *" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| sync-sitemap: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| WORDPRESS_API_URL: ${{ vars.WORDPRESS_API_URL || 'https://wp.keploy.io/graphql' }} | ||
| steps: | ||
|
amaan-bhati marked this conversation as resolved.
|
||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 18 | ||
|
|
||
| - name: Generate sitemap.xml | ||
| run: node scripts/generate-sitemap.mjs | ||
|
|
||
| - name: Detect sitemap changes | ||
| id: diff | ||
| run: | | ||
| if git diff --quiet -- public/sitemap.xml; then | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Create pull request | ||
| if: steps.diff.outputs.changed == 'true' | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| branch: automation/sync-sitemap | ||
| commit-message: "chore: sync sitemap.xml" | ||
| title: "chore: sync sitemap.xml" | ||
| body: | | ||
| Updates `public/sitemap.xml` from WordPress. | ||
|
|
||
| Includes new URLs and updated `<lastmod>` values when applicable. | ||
| add-paths: | | ||
| public/sitemap.xml | ||
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.