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