Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit 44d78b0

Browse files
amaury1093Tbaut
authored andcommitted
chore: Allow fetching cross-platform parity-ethereum (#501)
* Allow fetching cross-platform * Update ci * Fix script
1 parent 5fd81f1 commit 44d78b0

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

.gitlab-ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ variables:
1010
CARGOFLAGS: ''
1111

1212
cache:
13-
key: "${CI_JOB_NAME}"
13+
key: '${CI_JOB_NAME}'
1414
paths:
1515
- node_modules/
1616
- packages/*/node_modules/
1717

18-
1918
.branches: &branches
2019
only:
2120
- beta
@@ -79,6 +78,9 @@ win-build:
7978
script:
8079
- yarn install
8180
- yarn build
81+
# `win-build` is a linux machine, so it downloaded a linux parity-ethereum.
82+
# We download a windows one to make it cross-compile for windows.
83+
- rm packages/fether-electron/static/parity* && yarn fetch-parity --win
8284
- yarn release --win
8385
tags:
8486
- linux-docker

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@
4242
"yarn": "^1.4.2"
4343
},
4444
"scripts": {
45-
"postinstall": "cd scripts && node ./fetch-latest-parity.js",
45+
"postinstall": "yarn fetch-parity",
4646
"build": "lerna run build",
4747
"preelectron": "yarn build",
4848
"electron": "cd packages/fether-electron && yarn electron",
49+
"fetch-parity": "cd scripts && node ./fetch-latest-parity.js",
4950
"lint-files": "./scripts/lint-files.sh '**/*.js'",
5051
"lint": "yarn lint-files",
5152
"prepackage": "yarn build",

scripts/fetch-latest-parity.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,28 @@ const exec = promisify(require('child_process').exec);
1818
const fsChmod = promisify(chmod);
1919
const fsWriteFile = promisify(writeFile);
2020

21-
let os;
22-
switch (process.platform) {
23-
case 'win32':
24-
os = 'windows';
25-
break;
26-
case 'darwin':
27-
os = 'darwin';
28-
break;
29-
default:
30-
os = 'linux';
21+
function getOs () {
22+
if (process.argv.includes('--win')) {
23+
return 'windows';
24+
}
25+
if (process.argv.includes('--mac')) {
26+
return 'darwin';
27+
}
28+
if (process.argv.includes('--linux')) {
29+
return 'linux';
30+
}
31+
32+
switch (process.platform) {
33+
case 'win32':
34+
return 'windows';
35+
case 'darwin':
36+
return 'darwin';
37+
default:
38+
return 'linux';
39+
}
3140
}
3241

33-
const ENDPOINT = `https://vanity-service.parity.io/parity-binaries?os=${os}&architecture=x86_64`;
42+
const ENDPOINT = `https://vanity-service.parity.io/parity-binaries?os=${getOs()}&architecture=x86_64`;
3443

3544
const STATIC_DIRECTORY = path.join(
3645
'..',
@@ -48,6 +57,11 @@ if (foundPath) {
4857
// Bundled Parity was found, we check if the version matches the minimum requirements
4958
getBinaryVersion(foundPath)
5059
.then(version => {
60+
if (!version) {
61+
console.log("Couldn't get bundled Parity Ethereum version.");
62+
return downloadParity();
63+
}
64+
5165
if (!semver.satisfies(version, versionRequirement)) {
5266
console.log(
5367
'Bundled Parity Ethereum %s is older than required version %s',
@@ -137,14 +151,19 @@ function downloadParity () {
137151
})
138152
.then(getBinaryVersion)
139153
.then(bundledVersion =>
140-
console.log(`Success: bundled Parity Ethereum ${bundledVersion}`)
154+
console.log(
155+
`Success: bundled Parity Ethereum ${bundledVersion ||
156+
"(couldn't get version)"}`
157+
)
141158
)
142159
);
143160
}
144161

145162
function getBinaryVersion (binaryPath) {
146-
return exec(`${binaryPath} --version`).then(({ stdout, stderr }) => {
147-
if (stderr) throw new Error(stderr);
148-
return stdout.match(/v\d+\.\d+\.\d+/)[0];
149-
});
163+
return exec(`${binaryPath} --version`)
164+
.then(({ stdout, stderr }) => {
165+
if (stderr) throw new Error(stderr);
166+
return stdout.match(/v\d+\.\d+\.\d+/)[0];
167+
})
168+
.catch(error => console.warn(error.message));
150169
}

0 commit comments

Comments
 (0)