Browse Source

Implement `runJob` and refactor some legacy scripts

master
meriadec 7 years ago
parent
commit
5fe7aed24f
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 2
      .circleci/config.yml
  2. 8
      package.json
  3. 43
      scripts/compile.sh
  4. 20
      scripts/dist-dir.sh
  5. 45
      scripts/dist.sh
  6. 0
      scripts/download-analytics.sh
  7. 20
      scripts/helpers/display-env.sh
  8. 48
      scripts/helpers/format.sh
  9. 25
      scripts/helpers/hash.sh
  10. 43
      scripts/helpers/run-job.sh
  11. 14
      scripts/install-ci-deps.sh
  12. 13
      scripts/legacy/compile.sh
  13. 3
      scripts/legacy/dist-dir.sh
  14. 16
      scripts/legacy/dist.sh
  15. 14
      scripts/legacy/install-ci-deps.sh
  16. 45
      scripts/legacy/postinstall.sh
  17. 83
      scripts/postinstall.sh
  18. 0
      scripts/publish-storybook.sh
  19. 16
      scripts/release.sh
  20. 0
      scripts/reset-files.sh
  21. 3
      scripts/start.sh

2
.circleci/config.yml

@ -15,7 +15,7 @@ jobs:
- v2-yarn-packages-{{ checksum "yarn.lock" }} - v2-yarn-packages-{{ checksum "yarn.lock" }}
- run: - run:
name: Install Dependencies name: Install Dependencies
command: bash scripts/legacy/install-ci-deps.sh command: bash scripts/install-ci-deps.sh
- save_cache: - save_cache:
name: Save Yarn Package Cache name: Save Yarn Package Cache
key: v2-yarn-packages-{{ checksum "yarn.lock" }} key: v2-yarn-packages-{{ checksum "yarn.lock" }}

8
package.json

@ -8,10 +8,10 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"postinstall": "./scripts/postinstall.sh", "postinstall": "./scripts/postinstall.sh",
"start": "./scripts/legacy/start.sh", "start": "./scripts/start.sh",
"release": "./scripts/legacy/release.sh", "release": "./scripts/release.sh",
"dist": "./scripts/legacy/dist.sh", "dist": "./scripts/dist.sh",
"dist:dir": "./scripts/legacy/dist-dir.sh", "dist:dir": "./scripts/dist-dir.sh",
"compile": "./scripts/compile.sh", "compile": "./scripts/compile.sh",
"lint": "eslint src webpack .storybook", "lint": "eslint src webpack .storybook",
"flow": "flow", "flow": "flow",

43
scripts/compile.sh

@ -0,0 +1,43 @@
#!/bin/bash
set -e
# shellcheck disable=SC1091
source scripts/helpers/format.sh
# shellcheck disable=SC1091
source scripts/helpers/run-job.sh
GIT_REVISION=$(git rev-parse HEAD)
export GIT_REVISION
export SENTRY_URL='https://db8f5b9b021048d4a401f045371701cb@sentry.io/274561'
export JOBS='max'
echo
formatEnvVar 'GIT_REVISION'
formatEnvVar 'SENTRY_URL'
echo
runJob \
"clearing dist..." \
"dist cleared" \
"failed to clear dist" \
<<EOF
rm -rf dist
EOF
runJob \
"building internal bundle..." \
"internal bundle built" \
"failed to build internal bundle" \
<<EOF
NODE_ENV=production yarn run webpack-cli --mode production --config webpack/internals.config.js
EOF
runJob \
"building main & renderer bundles..." \
"main & renderer bundles built" \
"failed to build main & renderer bundles" \
<<EOF
NODE_ENV=production yarn run electron-webpack
EOF

20
scripts/dist-dir.sh

@ -0,0 +1,20 @@
#!/bin/bash
set -e
# shellcheck disable=SC1091
source scripts/helpers/run-job.sh
# shellcheck disable=SC1091
source scripts/helpers/display-env.sh
yarn compile
runJob \
"building app..." \
"app built successfully" \
"failed to build app" \
"verbose" \
<<EOF
DEBUG=electron-builder electron-builder --dir -c.compression=store -c.mac.identity=null
EOF

45
scripts/dist.sh

@ -0,0 +1,45 @@
#!/bin/bash
set -e
# shellcheck disable=SC1091
source scripts/helpers/run-job.sh
# shellcheck disable=SC1091
source scripts/helpers/display-env.sh
# hilarious fix: to make linux icon we have to remove icon.png from build folder
# some context:
# - https://github.com/electron-userland/electron-builder/issues/2577
# - https://github.com/electron-userland/electron-builder/issues/2269
if [[ $(uname) == 'Linux' ]]; then
runJob \
"dirty fix to handle linux icon..." \
"successfully applied dirty fix to handle linux icon" \
"failed to apply dirty fix to handle linux icon" \
<<EOF
mv build/icon.png /tmp
EOF
fi
yarn compile
runJob \
"building and packaging app..." \
"app built and packaged successfully" \
"failed to build app" \
"verbose" \
<<EOF
DEBUG=electron-builder electron-builder
EOF
# hilarious fix continuation: put back the icon where it was
if [[ $(uname) == 'Linux' ]]; then
runJob \
"cleaning dirty fix to handle linux icon..." \
"successfully applied clean dirty fix to handle linux icon" \
"failed to apply clean dirty fix to handle linux icon" \
<<EOF
mv /tmp/icon.png build
EOF
fi

0
scripts/legacy/download-analytics.sh → scripts/download-analytics.sh

20
scripts/helpers/display-env.sh

@ -0,0 +1,20 @@
#!/bin/bash
# shellcheck disable=SC1091
source scripts/helpers/format.sh
appVersion=$(grep version package.json | sed 's/.*"\(.*\)",$/\1/')
echo
printf " │ \\e[4;1m%s\\e[0;0m\\n" "Ledger Live Desktop - ${appVersion}"
printf " │ \\e[1;30m%s\\e[1;0m\\n" "$(uname -srmo)"
printf " │ \\e[2;1mcommit \\e[0;33m%s\\e[0;0m\\n" "$(git rev-parse HEAD)"
echo
formatEnvVar "CI"
formatEnvVar "NODE_ENV"
formatEnvVar "JOBS"
echo
formatGeneric "node" "$(node --version)"
echo

48
scripts/helpers/format.sh

@ -0,0 +1,48 @@
#!/bin/bash
colSize=20
function formatJobTitle {
echo "[$1]"
echo
}
function formatEnvVar {
key=$1
value=$(eval echo \$"${key}")
color="32"
if [ "$value" == "" ]; then color="34"; value="unset"
elif [ "$value" == "1" ]; then color="32"
elif [ "$value" == "0" ]; then color="35"
else value="'$value'"
fi
printf " %-${colSize}s\\e[2;${color}m%s\\e[1;0m\\n" "$key" "$value"
}
function formatGeneric {
printf " %-${colSize}s\\e[0;2m%s\\e[0m\\n" "$1" "$2"
}
function formatDiscret {
printf "\\e[2;34m%s\\e[2;0m\\n" "$1"
}
function formatSkip {
printf "\\e[2;34m[-] skipping %s (%s)\\e[0;0m\\n" "$1" "$2"
}
function clearLine {
echo -en "\\r\\e[0K"
}
function formatError {
printf "\\e[0;31m[✘] %s\\e[0;0m\\n" "$1"
}
function formatProgress {
printf "\\e[0;35m[⬇] %s\\e[0;0m" "$1"
}
function formatSuccess {
printf "\\e[0;36m[✔] %s\\e[0;0m\\n" "$1"
}

25
scripts/helpers/hash.sh

@ -1,13 +1,16 @@
#!/bin/bash #!/bin/bash
function GET_HASH_PATH { # shellcheck disable=SC1091
source scripts/helpers/format.sh
function _getHashPath {
HASH_NAME=$1 HASH_NAME=$1
echo "./node_modules/.cache/LEDGER_HASH_$HASH_NAME.hash" echo "./node_modules/.cache/LEDGER_HASH_$HASH_NAME.hash"
} }
function GET_HASH { function getHash {
HASH_NAME=$1 HASH_NAME=$1
HASH_PATH=$(GET_HASH_PATH "$HASH_NAME") HASH_PATH=$(_getHashPath "$HASH_NAME")
if [ ! -e "$HASH_PATH" ]; then if [ ! -e "$HASH_PATH" ]; then
echo '' echo ''
else else
@ -16,11 +19,21 @@ function GET_HASH {
fi fi
} }
function SET_HASH { function setHash {
HASH_NAME=$1 HASH_NAME=$1
HASH_CONTENT=$2 HASH_CONTENT=$2
echo "setting hash $HASH_NAME to $HASH_CONTENT" formatSuccess "$HASH_NAME hash set to $HASH_CONTENT"
HASH_PATH=$(GET_HASH_PATH "$HASH_NAME") HASH_PATH=$(_getHashPath "$HASH_NAME")
mkdir -p ./node_modules/.cache mkdir -p ./node_modules/.cache
echo "$HASH_CONTENT" > "$HASH_PATH" echo "$HASH_CONTENT" > "$HASH_PATH"
} }
function hashDiffers {
cachedHash=$(getHash "$1")
hash=$2
if [ "$cachedHash" == "$hash" ]; then
return 1
else
return 0
fi
}

43
scripts/helpers/run-job.sh

@ -0,0 +1,43 @@
#!/bin/bash
# shellcheck disable=SC1091
source scripts/helpers/format.sh
function runJob {
progressMsg=$1
successMsg=$2
errMsg=$3
logLevel=$4
tmpErrFile=$(mktemp)
job=$(</dev/stdin)
formatProgress "$progressMsg"
if [ "$logLevel" == "verbose" ]; then
echo
echo "$job" | bash &
else
echo "$job" | bash >/dev/null 2>"$tmpErrFile" &
fi
childPid=$!
# prevent set -e to exit if child fail
wait $childPid && returnCode=$? || returnCode=$?
if [ "$logLevel" != "verbose" ]; then
clearLine
fi
if [ $returnCode -eq 0 ]; then
formatSuccess "$successMsg"
else
formatError "$errMsg"
formatError "$(cat "$tmpErrFile")"
fi
rm "$tmpErrFile"
return $returnCode
}

14
scripts/install-ci-deps.sh

@ -0,0 +1,14 @@
#!/bin/bash
# shellcheck disable=SC1091
source scripts/helpers/hash.sh
yarnLockHash=$(md5sum package.json | cut -d ' ' -f 1)
cachedYarnLockHash=$(getHash 'yarn.lock')
if [ "$cachedYarnLockHash" == "$yarnLockHash" ]; then
echo "> Skipping yarn install"
else
yarn install
setHash 'yarn.lock' "$yarnLockHash"
fi

13
scripts/legacy/compile.sh

@ -1,13 +0,0 @@
#!/bin/bash
set -e
GIT_REVISION=$(git rev-parse HEAD)
export GIT_REVISION
export SENTRY_URL=https://db8f5b9b021048d4a401f045371701cb@sentry.io/274561
export JOBS=max
rm -rf ./node_modules/.cache dist
yarn
NODE_ENV=production yarn run webpack-cli --mode production --config webpack/internals.config.js
NODE_ENV=production yarn run electron-webpack

3
scripts/legacy/dist-dir.sh

@ -1,3 +0,0 @@
#!/bin/bash
yarn compile && DEBUG=electron-builder electron-builder --dir -c.compression=store -c.mac.identity=null

16
scripts/legacy/dist.sh

@ -1,16 +0,0 @@
#!/bin/bash
# hilarious fix: to make linux icon we have to remove icon.png from build folder
# some context:
# - https://github.com/electron-userland/electron-builder/issues/2577
# - https://github.com/electron-userland/electron-builder/issues/2269
if [[ $(uname) == 'Linux' ]]; then
mv build/icon.png /tmp
fi
yarn compile && DEBUG=electron-builder electron-builder
# hilarious fix continuation: put back the icon where it was
if [[ $(uname) == 'Linux' ]]; then
mv /tmp/icon.png build
fi

14
scripts/legacy/install-ci-deps.sh

@ -1,14 +0,0 @@
#!/bin/bash
# shellcheck disable=SC1091
source scripts/helpers/hash.sh
PACKAGE_JSON_HASH=$(md5sum package.json | cut -d ' ' -f 1)
CACHED_PACKAGE_JSON_HASH=$(GET_HASH 'package.json')
if [ "$CACHED_PACKAGE_JSON_HASH" == "$PACKAGE_JSON_HASH" ]; then
echo "> Skipping yarn install"
else
yarn install
SET_HASH 'package.json' "$PACKAGE_JSON_HASH"
fi

45
scripts/legacy/postinstall.sh

@ -1,45 +0,0 @@
#!/bin/bash
# shellcheck disable=SC1091
source scripts/helpers/hash.sh
function MAIN {
if [ "$CI" != "1" ]; then
REBUILD_ELECTRON_NATIVE_DEPS
fi
INSTALL_FLOW_TYPED
}
function INSTALL_FLOW_TYPED {
LATEST_FLOW_TYPED_COMMIT_HASH=$(curl --silent --header "Accept: application/vnd.github.VERSION.sha" --location https://api.github.com/repos/flowtype/flow-typed/commits/master)
CURRENT_FLOW_TYPED_HASH=$(GET_HASH 'flow-typed')
if [ "$LATEST_FLOW_TYPED_COMMIT_HASH" == "$CURRENT_FLOW_TYPED_HASH" ]; then
echo "> Flow-typed definitions are up to date. Skipping"
else
echo "> Installing flow-typed defs"
flow-typed install -s --overwrite
echo "> Removing broken flow definitions"
rm flow-typed/npm/{react-i18next_v7.x.x.js,styled-components_v3.x.x.js,redux_*,winston*}
SET_HASH 'flow-typed' "$LATEST_FLOW_TYPED_COMMIT_HASH"
fi
}
function REBUILD_ELECTRON_NATIVE_DEPS {
# for strange/fancy os-es
if [[ $(uname) == 'Darwin' ]]; then
PACKAGE_JSON_HASH=$(md5 package.json | cut -d ' ' -f 1)
else
# for normal os-es
PACKAGE_JSON_HASH=$(md5sum package.json | cut -d ' ' -f 1)
fi
CACHED_PACKAGE_JSON_HASH=$(GET_HASH 'package.json')
if [ "$CACHED_PACKAGE_JSON_HASH" == "$PACKAGE_JSON_HASH" ]; then
echo "> Electron native deps are up to date. Skipping"
else
echo "> Installing electron native deps"
DEBUG=electron-builder electron-builder install-app-deps
SET_HASH 'package.json' "$PACKAGE_JSON_HASH"
fi
}
MAIN

83
scripts/postinstall.sh

@ -0,0 +1,83 @@
#!/bin/bash
set -e
# shellcheck disable=SC1091
source scripts/helpers/display-env.sh
# shellcheck disable=SC1091
source scripts/helpers/format.sh
# shellcheck disable=SC1091
source scripts/helpers/hash.sh
# shellcheck disable=SC1091
source scripts/helpers/run-job.sh
latestFlowTypedCommitHash=''
function main {
# native dependencies
if [ "$CI" != "true" ] && hashDiffers yarn.lock "$(getYarnHash)"; then
rebuildElectronNativeDeps
else
formatSkip "native module build" "already up-to-date"
fi
# flow-typed
formatProgress "Checking if flow-typed definitions are up-to-date..."
latestFlowTypedCommitHash=$(curl --silent --header "Accept: application/vnd.github.VERSION.sha" --location https://api.github.com/repos/flowtype/flow-typed/commits/master)
clearLine
if [[ $latestFlowTypedCommitHash =~ ^\{ ]]; then
formatError "Failed to retrieve flow-typed definitions"
echo "$latestFlowTypedCommitHash"
exit 1
else
if hashDiffers flow-typed "$latestFlowTypedCommitHash"; then
installFlowTyped
else
formatSkip "flow-typed installation" "already up-to-date"
fi
fi
echo
}
function installFlowTyped {
runJob \
"Installing flow-typed definitions..." \
"Installed flow-typed definitions" \
"Failed installing flow-typed definitions" \
<<EOF
flow-typed install -s --overwrite
EOF
rm flow-typed/npm/{react-i18next_v7.x.x.js,styled-components_v3.x.x.js,redux_*,winston*}
formatSuccess "Removed broken flow-typed definitions"
setHash flow-typed "$latestFlowTypedCommitHash"
formatSuccess "Installed flow-typed definitions"
}
function rebuildElectronNativeDeps {
runJob \
"Building native electron dependencies..." \
"Successfully builded native modules for electron" \
"Build failed" \
"verbose" \
<<EOF
DEBUG=electron-builder electron-builder install-app-deps
EOF
setHash yarn.lock "$(getYarnHash)"
}
function getYarnHash {
if [[ $(uname) == 'Darwin' ]]; then
yarnHash=$(md5 yarn.lock | cut -d ' ' -f 1)
else
yarnHash=$(md5sum yarn.lock | cut -d ' ' -f 1)
fi
echo "$yarnHash"
}
main

0
scripts/legacy/publish-storybook.sh → scripts/publish-storybook.sh

16
scripts/legacy/release.sh → scripts/release.sh

@ -2,6 +2,12 @@
set -e set -e
# shellcheck disable=SC1091
source scripts/helpers/run-job.sh
# shellcheck disable=SC1091
source scripts/helpers/display-env.sh
if [ -z "$GH_TOKEN" ]; then if [ -z "$GH_TOKEN" ]; then
echo "GH_TOKEN is unset. can't release" >&2 echo "GH_TOKEN is unset. can't release" >&2
exit 1 exit 1
@ -21,4 +27,12 @@ fi
# TODO check if local git HEAD is EXACTLY our remote master HEAD # TODO check if local git HEAD is EXACTLY our remote master HEAD
yarn compile yarn compile
DEBUG=electron-builder yarn run electron-builder build --publish always
runJob \
"building, packaging and publishing app..." \
"app built, packaged and published successfully" \
"failed to build app" \
"verbose" \
<<EOF
DEBUG=electron-builder electron-builder build --publish always
EOF

0
scripts/legacy/reset-files.sh → scripts/reset-files.sh

3
scripts/legacy/start.sh → scripts/start.sh

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
# shellcheck disable=SC1091
source scripts/helpers/display-env.sh
concurrently --raw --kill-others \ concurrently --raw --kill-others \
"cross-env NODE_ENV=development webpack-cli --mode development --watch --config webpack/internals.config.js" \ "cross-env NODE_ENV=development webpack-cli --mode development --watch --config webpack/internals.config.js" \
"cross-env NODE_ENV=development electron-webpack dev" "cross-env NODE_ENV=development electron-webpack dev"
Loading…
Cancel
Save