Skip to content

Commit a5433c7

Browse files
feat(deploy): 🛠️ automate Google Site Verification file creation in build step
* Remove inline verification file creation from workflow * Add `set-google-verification.mjs` script to generate verification file in `public/` * Update build script to run verification script before Next.js build
1 parent 592412a commit a5433c7

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎.github/workflows/deploy.yml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ jobs:
3939
env:
4040
NEXT_PUBLIC_BASE_PATH: ${{ github.event.repository.name != github.event.repository.owner.login && format('/{0}', github.event.repository.name) || '' }}
4141

42-
- name: Add Google Site Verification
43-
run: >
44-
echo "google-site-verification: $GOOGLE_VERIFICATION.html" > ./website/out/${GOOGLE_VERIFICATION}.html
45-
4642
- name: Upload artifact
4743
uses: actions/upload-pages-artifact@v3
4844
with:

‎website/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"dev": "next dev",
7-
"build": "next build",
7+
"build": "node scripts/set-google-verification.mjs && next build",
88
"start": "next start",
99
"lint": "eslint"
1010
},
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import fs from 'node:fs';
2+
3+
// Load environment variables from .env file
4+
import 'dotenv/config';
5+
6+
if (!process.env.GOOGLE_VERIFICATION) {
7+
console.error('Error: GOOGLE_VERIFICATION environment variable is not set.');
8+
process.exit(1);
9+
}
10+
11+
const htmlFilePath = `./public/${process.env.GOOGLE_VERIFICATION}.html`;
12+
13+
// Create the HTML file with the verification content
14+
const fileContent = `google-site-verification: ${process.env.GOOGLE_VERIFICATION}.html`;
15+
16+
fs.writeFileSync(htmlFilePath, fileContent, 'utf8');
17+
console.log(`Created verification file at: ${htmlFilePath}`);

0 commit comments

Comments
 (0)