Skip to content

Commit bed733a

Browse files
committed
chore: audit to ensure docs are up-to-date
1 parent 00b73a7 commit bed733a

File tree

4 files changed

+91
-2
lines changed

4 files changed

+91
-2
lines changed
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Audit Docs Version
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 17 * * *'
7+
8+
permissions: {}
9+
10+
jobs:
11+
audit_docs_version:
12+
name: Audit Docs Version
13+
runs-on: ubuntu-latest
14+
steps:
15+
- run: npm install @electron/fiddle-core
16+
- name: Confirm latest version
17+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
18+
with:
19+
script: |
20+
const { setTimeout } = await import('node:timers/promises');
21+
const { ElectronVersions } = await import('${{ github.workspace }}/node_modules/@electron/fiddle-core/dist/index.js');
22+
23+
const DOCS_SHA_REGEX = /<meta name="docs-sha" content="(\w+)">/m;
24+
const DELTA_THRESHOLD_MS = 1000*60*20;
25+
26+
const resp = await fetch('https://electronjs.org');
27+
28+
if (!resp.ok) {
29+
core.setFailed('Could not fetch website');
30+
return;
31+
}
32+
33+
const latestDocsSHA = (await resp.text()).match(DOCS_SHA_REGEX)?.[1];
34+
35+
const versions = await ElectronVersions.create(undefined, { ignoreCache: true });
36+
37+
const { data } = await github.rest.repos.getBranch({
38+
owner: 'electron',
39+
repo: 'electron',
40+
branch: `${versions.latestStable.major}-x-y`,
41+
});
42+
43+
const { date } = data.commit.commit.committer;
44+
const delta = Date.now() - new Date(date).getTime();
45+
46+
// If the commit happened recently, wait a bit for the site
47+
// to deploy before checking so we don't get a false positive
48+
if (delta < DELTA_THRESHOLD_MS) {
49+
await setTimeout(DELTA_THRESHOLD_MS - delta);
50+
}
51+
52+
if (data.commit.sha !== latestDocsSHA) {
53+
core.summary.addRaw('🚨 Docs are NOT up-to-date');
54+
55+
// Set this as failed so it's easy to scan runs to find failures
56+
process.exitCode = 1;
57+
} else {
58+
core.summary.addRaw('🎉 Docs are up-to-date');
59+
}
60+
61+
await core.summary.write();

docs/latest/.sha

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
72115c1948ebe8c31525654440dc4d35d0dbb6b9

docusaurus.config.ts

+24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import fs from 'fs';
12
import path from 'path';
3+
24
import { Config } from '@docusaurus/types';
35
import npm2yarn from '@docusaurus/remark-plugin-npm2yarn';
46
import { themes as prismThemes } from 'prism-react-renderer';
@@ -15,6 +17,17 @@ import jsCodeBlocks from './src/transformers/js-code-blocks';
1517
import fiddleEmbedder from './src/transformers/fiddle-embedder';
1618
import apiHistory from './src/transformers/api-history';
1719

20+
let docsSHA = undefined;
21+
22+
try {
23+
docsSHA = fs.readFileSync(
24+
path.resolve(__dirname, './docs/latest/.sha'),
25+
'utf-8'
26+
);
27+
} catch {
28+
console.warn('No .sha file found in docs/latest directory');
29+
}
30+
1831
const config: Config = {
1932
title: 'Electron',
2033
tagline: 'Build cross-platform desktop apps with JavaScript, HTML, and CSS',
@@ -24,6 +37,17 @@ const config: Config = {
2437
favicon: 'assets/img/favicon.ico',
2538
organizationName: 'electron',
2639
projectName: 'electron',
40+
headTags: docsSHA
41+
? [
42+
{
43+
tagName: 'meta',
44+
attributes: {
45+
name: 'docs-sha',
46+
content: docsSHA,
47+
},
48+
},
49+
]
50+
: [],
2751
markdown: {
2852
mermaid: true,
2953
},

scripts/pre-build.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* right places, and transform it to make it ready to
44
* be used by docusaurus.
55
*/
6+
import { existsSync } from 'fs';
7+
import fs from 'fs/promises';
68
import path from 'path';
79

8-
import { existsSync, remove } from 'fs-extra';
910
import latestVersion from 'latest-version';
1011
import logger from '@docusaurus/logger';
1112

@@ -26,7 +27,7 @@ const DOCS_FOLDER = path.join(__dirname, '..', 'docs', 'latest');
2627
const start = async (source: string): Promise<void> => {
2728
logger.info(`Running ${logger.green('electronjs.org')} pre-build scripts...`);
2829
logger.info(`Deleting previous content at ${logger.green(DOCS_FOLDER)}`);
29-
await remove(DOCS_FOLDER);
30+
await fs.rm(DOCS_FOLDER, { recursive: true, force: true });
3031

3132
const localElectron =
3233
source && (source.includes('/') || source.includes('\\'));
@@ -52,6 +53,8 @@ const start = async (source: string): Promise<void> => {
5253
destination: DOCS_FOLDER,
5354
downloadMatch: '/docs/',
5455
});
56+
57+
await fs.writeFile(path.join(DOCS_FOLDER, '.sha'), source);
5558
} else if (existsSync(source)) {
5659
await copy({
5760
target: source,

0 commit comments

Comments
 (0)