Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/submit-google-sitemap.yml
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: |
Comment thread
amaan-bhati marked this conversation as resolved.
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
Comment thread
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
50 changes: 50 additions & 0 deletions .github/workflows/sync-sitemap.yml
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:
Comment thread
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
18 changes: 18 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ module.exports = {
},
async headers() {
return [
{
source: '/sitemap.xml',
headers: [
{
key: 'Cache-Control',
value: 'public, s-maxage=300, stale-while-revalidate=300',
},
],
},
{
source: '/robots.txt',
headers: [
{
key: 'Cache-Control',
value: 'public, s-maxage=86400, stale-while-revalidate=86400',
},
],
},
{
source: '/(.*)',
headers: [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"generate:sitemap": "node scripts/generate-sitemap.mjs",
"test:e2e": "playwright test",
"test:e2e:headed": "playwright test --headed",
"test:e2e:ui": "playwright test --ui",
Expand Down
153 changes: 0 additions & 153 deletions pages/sitemap.xml.tsx

This file was deleted.

Loading
Loading