forked from GoogleChrome/web.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version-check.js
39 lines (33 loc) · 1.07 KB
/
version-check.js
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
/**
* @fileoverview This file compares the current commit SHA against the one
* of the deployed site. If they are different the build is allowed to
* continue, otherwise the build is cancelled.
*/
const fetch = require('node-fetch');
const core = require('@actions/core');
const ERROR_MESSAGE = 'NOT FOUND';
/**
* @returns {Promise<string>}
*/
const getDeployedVersion = () => {
// @ts-ignore
return fetch('https://web.dev/version')
.then((res) => (res.ok ? res.text() : ERROR_MESSAGE))
.catch(() => ERROR_MESSAGE);
};
(async () => {
const deployedVersion = await getDeployedVersion();
const currentVersion = process.env.GITHUB_SHA;
console.log(`Current version: ${currentVersion}`);
console.log(`Deployed version: ${deployedVersion}`);
if (deployedVersion === currentVersion) {
console.log(
'The current and deployed versions are the same, stopping build.',
);
} else {
console.log(
'The current and deployed versions are different, continuing build.',
);
}
core.setOutput('isDifferent', deployedVersion !== currentVersion);
})();