Audit Docs Version #422
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Audit Docs Version | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 17 * * *' | |
| permissions: {} | |
| jobs: | |
| audit_docs_version: | |
| name: Audit Docs Version | |
| if: github.repository == 'electron/website' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Setup Node.js | |
| uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 | |
| with: | |
| node-version: '22.13.0' | |
| - run: npm install @electron/[email protected] | |
| - name: Confirm latest version | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| 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({ 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) { | |
| // A bug in `electron-website-updater` sometimes sends up new commits that | |
| // touched any file with `docs` in the name, so allow commits to be newer | |
| const comparison = await github.rest.repos.compareCommitsWithBasehead({ | |
| owner: 'electron', | |
| repo: 'electron', | |
| basehead: `${commit.sha}...${latestDocsSHA}`, | |
| }); | |
| if (comparison.status !== 200) { | |
| throw new Error('Failed to compare commits'); | |
| } | |
| if (comparison.data.behind_by === 0 && comparison.data.ahead_by >= 0) { | |
| core.summary.addRaw('🎉 Docs are up-to-date'); | |
| } else { | |
| 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(); |