diff --git a/.circleci/config.yml b/.circleci/config.yml index de97615d..8867fb6b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,7 +15,7 @@ jobs: - v2-yarn-packages-{{ checksum "yarn.lock" }} - run: name: Install Dependencies - command: bash scripts/legacy/install-ci-deps.sh + command: bash scripts/install-ci-deps.sh - save_cache: name: Save Yarn Package Cache key: v2-yarn-packages-{{ checksum "yarn.lock" }} diff --git a/package.json b/package.json index 101f5207..bc24c1c4 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,10 @@ "license": "MIT", "scripts": { "postinstall": "./scripts/postinstall.sh", - "start": "./scripts/legacy/start.sh", - "release": "./scripts/legacy/release.sh", - "dist": "./scripts/legacy/dist.sh", - "dist:dir": "./scripts/legacy/dist-dir.sh", + "start": "./scripts/start.sh", + "release": "./scripts/release.sh", + "dist": "./scripts/dist.sh", + "dist:dir": "./scripts/dist-dir.sh", "compile": "./scripts/compile.sh", "lint": "eslint src webpack .storybook", "flow": "flow", diff --git a/scripts/compile.sh b/scripts/compile.sh new file mode 100755 index 00000000..228efb33 --- /dev/null +++ b/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" \ +< "$HASH_PATH" } + +function hashDiffers { + cachedHash=$(getHash "$1") + hash=$2 + if [ "$cachedHash" == "$hash" ]; then + return 1 + else + return 0 + fi +} diff --git a/scripts/helpers/run-job.sh b/scripts/helpers/run-job.sh new file mode 100644 index 00000000..fd5e51d3 --- /dev/null +++ b/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/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 +} diff --git a/scripts/install-ci-deps.sh b/scripts/install-ci-deps.sh new file mode 100755 index 00000000..fa375466 --- /dev/null +++ b/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 diff --git a/scripts/legacy/compile.sh b/scripts/legacy/compile.sh deleted file mode 100755 index a47eac75..00000000 --- a/scripts/legacy/compile.sh +++ /dev/null @@ -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 diff --git a/scripts/legacy/dist-dir.sh b/scripts/legacy/dist-dir.sh deleted file mode 100755 index 64097c15..00000000 --- a/scripts/legacy/dist-dir.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -yarn compile && DEBUG=electron-builder electron-builder --dir -c.compression=store -c.mac.identity=null diff --git a/scripts/legacy/dist.sh b/scripts/legacy/dist.sh deleted file mode 100755 index 51f4fcee..00000000 --- a/scripts/legacy/dist.sh +++ /dev/null @@ -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 diff --git a/scripts/legacy/install-ci-deps.sh b/scripts/legacy/install-ci-deps.sh deleted file mode 100755 index b547cc5d..00000000 --- a/scripts/legacy/install-ci-deps.sh +++ /dev/null @@ -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 diff --git a/scripts/legacy/postinstall.sh b/scripts/legacy/postinstall.sh deleted file mode 100755 index c7761826..00000000 --- a/scripts/legacy/postinstall.sh +++ /dev/null @@ -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 diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh new file mode 100755 index 00000000..c3de840e --- /dev/null +++ b/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" \ + <&2 exit 1 @@ -21,4 +27,12 @@ fi # TODO check if local git HEAD is EXACTLY our remote master HEAD 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" \ +<