Skip to content

Commit 7db2daf

Browse files
authored
Merge pull request #1 from reason-in-barcelona/Fix-ci
2 parents 935d041 + a7189c8 commit 7db2daf

File tree

3 files changed

+182
-12
lines changed

3 files changed

+182
-12
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ jobs:
5757
run: esy test
5858

5959
- name: Create npm package
60-
run: esy npm-release
60+
run: esy build
61+
6162
- uses: actions/upload-artifact@v2
6263
with:
6364
name: ${{ matrix.os }}
64-
path: _release/
65+
path: _build/default/bin/Bin.exe
6566

6667
# Cleanup build cache if dependencies have changed
6768
- name: Clean build cache
@@ -152,8 +153,8 @@ jobs:
152153
env:
153154
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
154155
with:
155-
tag_name: ${{ github.ref }}
156-
release_name: Release ${{ github.ref }}
156+
tag_name: ${{ steps.sha.outputs.sha_short }}
157+
release_name: Release ${{ steps.sha.outputs.sha_short }}
157158
draft: false
158159
prerelease: false
159160

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/**
2+
* release-postinstall.js
3+
*
4+
* XXX: We want to keep this script installable at least with node 4.x.
5+
*
6+
* This script is bundled with the `npm` package and executed on release.
7+
* Since we have a 'fat' NPM package (with all platform binaries bundled),
8+
* this postinstall script extracts them and puts the current platform's
9+
* bits in the right place.
10+
*/
11+
12+
var path = require("path");
13+
var cp = require("child_process");
14+
var fs = require("fs");
15+
var platform = process.platform;
16+
17+
var packageJson = require("./package.json");
18+
var binariesToCopy = Object.keys(packageJson.bin)
19+
.map(function (name) {
20+
return packageJson.bin[name];
21+
})
22+
.concat(["esyInstallRelease.js"]);
23+
var foldersToCopy = ["bin", "_export"];
24+
25+
function copyRecursive(srcDir, dstDir) {
26+
var results = [];
27+
var list = fs.readdirSync(srcDir);
28+
var src, dst;
29+
list.forEach(function (file) {
30+
src = path.join(srcDir, file);
31+
dst = path.join(dstDir, file);
32+
33+
var stat = fs.statSync(src);
34+
if (stat && stat.isDirectory()) {
35+
try {
36+
fs.mkdirSync(dst);
37+
} catch (e) {
38+
console.log("directory already exists: " + dst);
39+
console.error(e);
40+
}
41+
results = results.concat(copyRecursive(src, dst));
42+
} else {
43+
try {
44+
fs.writeFileSync(dst, fs.readFileSync(src));
45+
} catch (e) {
46+
console.log("could't copy file: " + dst);
47+
console.error(e);
48+
}
49+
results.push(src);
50+
}
51+
});
52+
return results;
53+
}
54+
55+
/**
56+
* Since os.arch returns node binary's target arch, not
57+
* the system arch.
58+
* Credits: https://github.com/feross/arch/blob/af080ff61346315559451715c5393d8e86a6d33c/index.js#L10-L58
59+
*/
60+
61+
function arch() {
62+
/**
63+
* The running binary is 64-bit, so the OS is clearly 64-bit.
64+
*/
65+
if (process.arch === "x64") {
66+
return "x64";
67+
}
68+
69+
/**
70+
* All recent versions of Mac OS are 64-bit.
71+
*/
72+
if (process.platform === "darwin") {
73+
return "x64";
74+
}
75+
76+
/**
77+
* On Windows, the most reliable way to detect a 64-bit OS from within a 32-bit
78+
* app is based on the presence of a WOW64 file: %SystemRoot%\SysNative.
79+
* See: https://twitter.com/feross/status/776949077208510464
80+
*/
81+
if (process.platform === "win32") {
82+
var useEnv = false;
83+
try {
84+
useEnv = !!(
85+
process.env.SYSTEMROOT && fs.statSync(process.env.SYSTEMROOT)
86+
);
87+
} catch (err) {}
88+
89+
var sysRoot = useEnv ? process.env.SYSTEMROOT : "C:\\Windows";
90+
91+
// If %SystemRoot%\SysNative exists, we are in a WOW64 FS Redirected application.
92+
var isWOW64 = false;
93+
try {
94+
isWOW64 = !!fs.statSync(path.join(sysRoot, "sysnative"));
95+
} catch (err) {}
96+
97+
return isWOW64 ? "x64" : "x86";
98+
}
99+
100+
/**
101+
* On Linux, use the `getconf` command to get the architecture.
102+
*/
103+
if (process.platform === "linux") {
104+
var output = cp.execSync("getconf LONG_BIT", { encoding: "utf8" });
105+
return output === "64\n" ? "x64" : "x86";
106+
}
107+
108+
/**
109+
* If none of the above, assume the architecture is 32-bit.
110+
*/
111+
return "x86";
112+
}
113+
114+
// implementing it b/c we don't want to depend on fs.copyFileSync which appears
115+
116+
function copyFileSync(sourcePath, destPath) {
117+
var data;
118+
try {
119+
data = fs.readFileSync(sourcePath);
120+
} catch (e) {
121+
console.log("Couldn't find " + sourcePath + " trying with .exe");
122+
data = fs.readFileSync(sourcePath + ".exe");
123+
sourcePath = sourcePath + ".exe";
124+
}
125+
var stat = fs.statSync(sourcePath);
126+
fs.writeFileSync(destPath, data);
127+
fs.chmodSync(destPath, stat.mode);
128+
}
129+
130+
var copyPlatformBinaries = (platformPath) => {
131+
var platformBuildPath = path.join(__dirname, "platform-" + platformPath);
132+
133+
foldersToCopy.forEach((folderPath) => {
134+
var sourcePath = path.join(platformBuildPath, folderPath);
135+
var destPath = path.join(__dirname, folderPath);
136+
137+
copyRecursive(sourcePath, destPath);
138+
});
139+
140+
binariesToCopy.forEach((binaryPath) => {
141+
var sourcePath = path.join(platformBuildPath, binaryPath);
142+
var destPath = path.join(__dirname, binaryPath);
143+
if (fs.existsSync(destPath)) {
144+
fs.unlinkSync(destPath);
145+
}
146+
copyFileSync(sourcePath, destPath);
147+
fs.chmodSync(destPath, 0777);
148+
});
149+
};
150+
151+
try {
152+
fs.mkdirSync("_export");
153+
} catch (e) {
154+
console.log("Could not create _export folder");
155+
}
156+
157+
switch (platform) {
158+
case "win32":
159+
if (arch() !== "x64") {
160+
console.warn("error: x86 is currently not supported on Windows");
161+
process.exit(1);
162+
}
163+
164+
copyPlatformBinaries("windows-x64");
165+
break;
166+
case "linux":
167+
case "darwin":
168+
copyPlatformBinaries(platform);
169+
break;
170+
default:
171+
console.warn("error: no release built for the " + platform + " platform");
172+
process.exit(1);
173+
}
174+
175+
require("./esyInstallRelease");

package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414
],
1515
"esy": {
1616
"buildsInSource": "_build",
17-
"build": [
18-
[
19-
"dune",
20-
"build",
21-
"-p",
22-
"ReactRulesOfHooksPpx"
23-
]
24-
],
17+
"build": "dune build -p ReactRulesOfHooksPpx",
2518
"buildDev": [
2619
[
2720
"dune",
@@ -56,6 +49,7 @@
5649
"@esy-ocaml/reason": "facebook/reason:reason.json#773dbcd"
5750
},
5851
"scripts": {
52+
"build": "esy dune build -p ReactRulesOfHooksPpx",
5953
"watch": "esy dune build -p ReactRulesOfHooksPpx --watch",
6054
"test": "esy x Run.exe",
6155
"doc": "esy dune build @doc",

0 commit comments

Comments
 (0)