Skip to content

Commit 5a26426

Browse files
authored
ci: Add CI check for Parse Server options definitions (parse-community#7955)
1 parent 65a6dd1 commit 5a26426

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

.github/workflows/ci.yml

+21
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ jobs:
7070
- name: Install dependencies
7171
run: npm ci
7272
- run: npm run lint
73+
check-definitions:
74+
name: Check Definitions
75+
timeout-minutes: 5
76+
runs-on: ubuntu-18.04
77+
steps:
78+
- uses: actions/checkout@v2
79+
- name: Use Node.js ${{ matrix.NODE_VERSION }}
80+
uses: actions/setup-node@v2
81+
with:
82+
node-version: ${{ matrix.node-version }}
83+
- name: Cache Node.js modules
84+
uses: actions/cache@v2
85+
with:
86+
path: ~/.npm
87+
key: ${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
88+
restore-keys: |
89+
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
90+
- name: Install dependencies
91+
run: npm ci
92+
- name: CI Definitions Check
93+
run: npm run ci:definitionsCheck
7394
check-circular:
7495
name: Circular Dependencies
7596
timeout-minutes: 5

ci/definitionsCheck.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const fs = require('fs').promises;
2+
const { exec } = require('child_process');
3+
const core = require('@actions/core');
4+
const { nextTick } = require('process');
5+
const { AbortController } = require("node-abort-controller");
6+
(async () => {
7+
const [currentDefinitions, currentDocs] = await Promise.all([
8+
fs.readFile('./src/Options/Definitions.js', 'utf8'),
9+
fs.readFile('./src/Options/docs.js', 'utf8'),
10+
]);
11+
exec('npm run definitions');
12+
const ac = new AbortController();
13+
const { signal } = ac;
14+
const watcher = fs.watch('./src/Options/docs.js', {signal});
15+
let i = 0;
16+
// eslint-disable-next-line
17+
for await (const _ of watcher) {
18+
i++;
19+
if (i === 3) {
20+
ac.abort();
21+
break;
22+
}
23+
}
24+
await new Promise(resolve => nextTick(resolve));
25+
const [newDefinitions, newDocs] = await Promise.all([
26+
fs.readFile('./src/Options/Definitions.js', 'utf8'),
27+
fs.readFile('./src/Options/docs.js', 'utf8'),
28+
]);
29+
if (currentDefinitions !== newDefinitions || currentDocs !== newDocs) {
30+
console.error(
31+
'\x1b[31m%s\x1b[0m',
32+
'Definitions files cannot be updated manually. Please update src/Options/index.js then run `npm run definitions` to generate definitions.'
33+
);
34+
core.error('Definitions files cannot be updated manually. Please update src/Options/index.js then run `npm run definitions` to generate definitions.');
35+
process.exit(1);
36+
} else {
37+
process.exit(0);
38+
}
39+
})();

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"mongodb-runner": "4.8.1",
100100
"mongodb-version-list": "1.0.0",
101101
"node-fetch": "3.2.10",
102+
"node-abort-controller": "3.0.1",
102103
"nyc": "15.1.0",
103104
"prettier": "2.0.5",
104105
"semantic-release": "17.4.6",
@@ -107,6 +108,7 @@
107108
"scripts": {
108109
"ci:check": "node ./ci/ciCheck.js",
109110
"ci:checkNodeEngine": "node ./ci/nodeEngineCheck.js",
111+
"ci:definitionsCheck": "node ./ci/definitionsCheck.js",
110112
"definitions": "node ./resources/buildConfigDefinitions.js && prettier --write 'src/Options/*.js'",
111113
"docs": "jsdoc -c ./jsdoc-conf.json",
112114
"lint": "flow && eslint --cache ./",

0 commit comments

Comments
 (0)