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

chore: Allow fetching cross-platform parity-ethereum #501

Merged
merged 3 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ variables:
CARGOFLAGS: ''

cache:
key: "${CI_JOB_NAME}"
key: '${CI_JOB_NAME}'
paths:
- node_modules/
- packages/*/node_modules/


.branches: &branches
only:
- beta
Expand Down Expand Up @@ -79,6 +78,9 @@ win-build:
script:
- yarn install
- yarn build
# `win-build` is a linux machine, so it downloaded a linux parity-ethereum.
# We download a windows one to make it cross-compile for windows.
- rm packages/fether-electron/static/parity* && yarn fetch-parity --win
- yarn release --win
tags:
- linux-docker
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
"yarn": "^1.4.2"
},
"scripts": {
"postinstall": "cd scripts && node ./fetch-latest-parity.js",
"postinstall": "yarn fetch-parity",
"build": "lerna run build",
"preelectron": "yarn build",
"electron": "cd packages/fether-electron && yarn electron",
"fetch-parity": "cd scripts && node ./fetch-latest-parity.js",
"lint-files": "./scripts/lint-files.sh '**/*.js'",
"lint": "yarn lint-files",
"prepackage": "yarn build",
Expand Down
51 changes: 35 additions & 16 deletions scripts/fetch-latest-parity.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,28 @@ const exec = promisify(require('child_process').exec);
const fsChmod = promisify(chmod);
const fsWriteFile = promisify(writeFile);

let os;
switch (process.platform) {
case 'win32':
os = 'windows';
break;
case 'darwin':
os = 'darwin';
break;
default:
os = 'linux';
function getOs () {
if (process.argv.includes('--win')) {
return 'windows';
}
if (process.argv.includes('--mac')) {
return 'darwin';
}
if (process.argv.includes('--linux')) {
return 'linux';
}

switch (process.platform) {
case 'win32':
return 'windows';
case 'darwin':
return 'darwin';
default:
return 'linux';
}
}

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

const STATIC_DIRECTORY = path.join(
'..',
Expand All @@ -48,6 +57,11 @@ if (foundPath) {
// Bundled Parity was found, we check if the version matches the minimum requirements
getBinaryVersion(foundPath)
.then(version => {
if (!version) {
Copy link
Contributor

@axelchalon axelchalon Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, in the future it can use some more commenting, otherwise the underlying logic isn't very clear

console.log("Couldn't get bundled Parity Ethereum version.");
return downloadParity();
}

if (!semver.satisfies(version, versionRequirement)) {
console.log(
'Bundled Parity Ethereum %s is older than required version %s',
Expand Down Expand Up @@ -137,14 +151,19 @@ function downloadParity () {
})
.then(getBinaryVersion)
.then(bundledVersion =>
console.log(`Success: bundled Parity Ethereum ${bundledVersion}`)
console.log(
`Success: bundled Parity Ethereum ${bundledVersion ||
"(couldn't get version)"}`
)
)
);
}

function getBinaryVersion (binaryPath) {
return exec(`${binaryPath} --version`).then(({ stdout, stderr }) => {
if (stderr) throw new Error(stderr);
return stdout.match(/v\d+\.\d+\.\d+/)[0];
});
return exec(`${binaryPath} --version`)
.then(({ stdout, stderr }) => {
if (stderr) throw new Error(stderr);
return stdout.match(/v\d+\.\d+\.\d+/)[0];
})
.catch(error => console.warn(error.message));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe in the future add a note to explain that we're catching the error so that the process still exits with 0 when fetching&packaging the windows binary on linux (ci) (then, the binary version cannot be checked)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 also remove the annoying "command failed" messages

}