-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.ci.sh
185 lines (184 loc) · 5.46 KB
/
.ci.sh
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
shCiArtifactUploadCustom() {(set -e
# this function will custom-upload build-artifacts to branch-gh-pages
# .cache - restore
if [ -d .cache ]
then
cp -a .cache/* .
# js-hack - */
fi
# mock npm install
mkdir -p node_modules/v8-coverage-report
cp * node_modules/v8-coverage-report 2>/dev/null || true
# screenshot quickstart
node --input-type=module -e '
import moduleFs from "fs";
import moduleChildProcess from "child_process";
(async function () {
// parallel-task - run-and-screenshot example-shell-commands in README.md
await Promise.all(Array.from(String(
await moduleFs.promises.readFile("README.md", "utf8")
).matchAll(
/\n```shell <!-- shRunWithScreenshotTxt (.*?) -->\n([\S\s]*?\n)```\n/g
)).map(async function ([
ignore, file, script0
]) {
let script = script0;
// modify script - npm install
script = script.replace((
/^npm install v8-coverage-report$/gm
), "# $&");
// modify script - npx
script = script.replace((
/^npx v8-coverage-report/m
), "node ../cli.mjs");
// modify script - cd node-sqlite3
script = script.replace((
/\n\ncd node-sqlite3-\w*?\n/g
), (
" 2>/dev/null || true\n"
+ "$&\n"
+ "git checkout 60a022c511a37788e652c271af23174566a80c30\n"
));
// limit stdout to 100 lines
script = script.trimRight() + " 2>&1 | head -n 100\n";
// printf script
script = (
"(set -e\n"
+ "printf \u0027"
+ script0.trim().replace((
/[%\\]/gm
), "$&$&").replace((
/\u0027/g
), "\u0027\"\u0027\"\u0027").replace((
/^/gm
), "> ")
+ "\n\n\n\u0027\n"
+ script
+ ")\n"
);
await moduleFs.promises.writeFile(file + ".sh", script);
await new Promise(function (resolve) {
moduleChildProcess.spawn(
"sh",
[
"jslint_ci.sh", "shRunWithScreenshotTxt", file,
"sh", file + ".sh"
],
{
stdio: [
"ignore", 1, 2
]
}
).on("exit", resolve);
});
}));
}());
' "$@" # '
# screenshot asset_image_logo
# shImageLogoCreate &
# screenshot html
node --input-type=module -e '
import moduleChildProcess from "child_process";
(async function () {
await Promise.all([
".artifact/apidoc.html",
".artifact/coverage_sqlite3_js/index.html",
".artifact/coverage_sqlite3_js/lib/sqlite3.js.html",
".artifact/coverage_sqlite3_sh/index.html",
".artifact/coverage_sqlite3_sh/lib/sqlite3.js.html"
].map(async function (url) {
await new Promise(function (resolve) {
moduleChildProcess.spawn(
"sh",
[
"jslint_ci.sh", "shBrowserScreenshot", url
],
{
stdio: [
"ignore", 1, 2
]
}
).on("exit", resolve);
});
}));
}());
' "$@" # '
# remove bloated json-coverage-files
rm .artifact/coverage/*.json
rm .artifact/coverage_sqlite3_*/*.json
# js-hack - */
# .cache - save
if [ ! -d .cache ]
then
mkdir .cache
cp -a node-sqlite3-* .cache
fi
)}
shCiBaseCustom() {(set -e
# this function will run base-ci
# update version in README.md, jslint.mjs, package.json from CHANGELOG.md
if [ "$(git branch --show-current)" = alpha ]
then
node --input-type=module -e '
import moduleFs from "fs";
(async function () {
let fileDict;
let fileModified;
let packageDescription;
let versionBeta;
let versionMaster;
fileDict = {};
await Promise.all([
"CHANGELOG.md",
"README.md",
"package.json"
].map(async function (file) {
fileDict[file] = await moduleFs.promises.readFile(file, "utf8");
}));
packageDescription = fileDict["package.json"].match(
/"description": "(.*?)"/
)[1];
Array.from(fileDict["CHANGELOG.md"].matchAll(
/\n\n# (v\d\d\d\d\.\d\d?\.\d\d?(.*?)?)\n/g
)).slice(0, 2).forEach(function ([
ignore, version, isBeta
]) {
versionBeta = versionBeta || version;
versionMaster = versionMaster || (!isBeta && version);
});
await Promise.all([
{
file: "README.md",
src: fileDict["README.md"].replace((
/\bv\d\d\d\d\.\d\d?\.\d\d?\b/m
), versionMaster).replace((
/\n# .*/
), "\n# " + packageDescription)
}, {
file: "package.json",
src: fileDict["package.json"].replace((
/("version": )".*?"/
), "$1" + JSON.stringify(versionBeta.slice(1)))
}
].map(async function ({
file,
src
}) {
let src0 = fileDict[file];
if (src !== src0) {
console.error(`update file ${file}`);
fileModified = file;
await moduleFs.promises.writeFile(file, src);
}
}));
if (fileModified) {
// throw new Error("modified file " + fileModified);
return;
}
}());
' "$@" # '
fi
node jslint.mjs .
# run test with coverage-report
npm run test
)}