Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

feat: auto submit google search console workflow

Dillion Verma0ea46398830c
diff --git a/.github/scripts/submit-sitemap.mjs b/.github/scripts/submit-sitemap.mjs
new file mode 100644
index 00000000..e9a5b346
--- /dev/null
+++ b/.github/scripts/submit-sitemap.mjs
@@ -0,0 +1,36 @@
+import { JWT } from "google-auth-library";
+import { google } from "googleapis";
+
+const { SITE_URL, SITEMAP_URL, GOOGLE_SEARCH_CONSOLE_JSON_KEY } = process.env;
+
+if (!SITE_URL || !SITEMAP_URL || !GOOGLE_SEARCH_CONSOLE_JSON_KEY) {
+ throw new Error("Missing required environment variables");
+}
+
+const keys = JSON.parse(
+ Buffer.from(GOOGLE_SEARCH_CONSOLE_JSON_KEY, "base64").toString("utf-8"),
+);
+
+const client = new JWT({
+ email: keys.client_email,
+ key: keys.private_key,
+ scopes: [
+ "https://www.googleapis.com/auth/webmasters",
+ "https://www.googleapis.com/auth/webmasters.readonly",
+ ],
+});
+
+google.options({ auth: client });
+
+const searchconsole = google.searchconsole("v1");
+
+(async () => {
+ try {
+ await searchconsole.sitemaps.submit({
+ feedpath: SITEMAP_URL,
+ siteUrl: SITE_URL,
+ });
+ } catch (e) {
+ console.log(e);
+ }
+})();
diff --git a/.github/workflows/submit-sitemap.yml b/.github/workflows/submit-sitemap.yml
new file mode 100644
index 00000000..b6844f72
--- /dev/null
+++ b/.github/workflows/submit-sitemap.yml
@@ -0,0 +1,53 @@
+name: Submit Sitemap to Google
+
+on:
+ workflow_run:
+ workflows:
+ - Publish Blog Article
+ types:
+ - completed
+ workflow_dispatch:
+ inputs:
+ sitemap_url:
+ description: "Override sitemap URL (optional)"
+ required: false
+
+permissions: {}
+
+env:
+ SITEMAP_URL: https://magicui.design/sitemap.xml
+ SITE_URL: https://magicui.design/
+
+jobs:
+ submit-sitemap:
+ if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v5
+
+ - uses: pnpm/action-setup@v4
+ with:
+ version: 9.15.0
+ run_install: false
+
+ - name: Setup Node
+ uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ cache: pnpm
+
+ - name: Publish Sitemap
+ env:
+ GOOGLE_SEARCH_CONSOLE_JSON_KEY: ${{ secrets.GOOGLE_SEARCH_CONSOLE_JSON_KEY }}
+ SITE_URL: ${{ env.SITE_URL }}
+ SITEMAP_URL: ${{ inputs.sitemap_url || env.SITEMAP_URL }}
+ run: |
+ if [ -z "${GOOGLE_SEARCH_CONSOLE_JSON_KEY}" ]; then
+ echo "GOOGLE_SEARCH_CONSOLE_JSON_KEY is not set" >&2
+ exit 1
+ fi
+ echo "Submitting via Google Search Console API"
+ corepack enable pnpm
+ pnpm add --no-save googleapis google-auth-library
+ node .github/scripts/submit-sitemap.mjs