2021-06-10 14:01:55 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# =============================================================================
|
|
|
|
# Setup environment variables
|
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
|
|
|
ROOT_DIR="$SCRIPT_DIR/../.."
|
|
|
|
|
|
|
|
IS_PULL_REQUEST=0
|
|
|
|
IS_DEV_BRANCH=0
|
|
|
|
IS_LINUX=0
|
|
|
|
IS_MACOS=0
|
|
|
|
|
|
|
|
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
|
|
|
|
IS_PULL_REQUEST=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$GITHUB_REF" == "refs/heads/dev" ]; then
|
|
|
|
IS_DEV_BRANCH=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$RUNNER_OS" == "Linux" ]; then
|
|
|
|
IS_LINUX=1
|
|
|
|
IS_MACOS=0
|
|
|
|
else
|
|
|
|
IS_LINUX=0
|
|
|
|
IS_MACOS=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# =============================================================================
|
|
|
|
# Print environment
|
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
echo "GITHUB_WORKFLOW=$GITHUB_WORKFLOW"
|
|
|
|
echo "GITHUB_EVENT_NAME=$GITHUB_EVENT_NAME"
|
|
|
|
echo "GITHUB_REF=$GITHUB_REF"
|
|
|
|
echo "RUNNER_OS=$RUNNER_OS"
|
|
|
|
echo "GIT_TAG_NAME=$GIT_TAG_NAME"
|
2022-01-01 16:24:56 +02:00
|
|
|
echo "BUILD_SEQUENCIAL=$BUILD_SEQUENCIAL"
|
2022-02-23 11:02:13 +02:00
|
|
|
echo "SERVER_REPOSITORY=$SERVER_REPOSITORY"
|
|
|
|
echo "SERVER_TAG_PREFIX=$SERVER_TAG_PREFIX"
|
2021-06-10 14:01:55 +02:00
|
|
|
|
2021-06-10 17:43:09 +02:00
|
|
|
echo "IS_CONTINUOUS_INTEGRATION=$IS_CONTINUOUS_INTEGRATION"
|
2021-06-10 14:01:55 +02:00
|
|
|
echo "IS_PULL_REQUEST=$IS_PULL_REQUEST"
|
|
|
|
echo "IS_DEV_BRANCH=$IS_DEV_BRANCH"
|
|
|
|
echo "IS_LINUX=$IS_LINUX"
|
|
|
|
echo "IS_MACOS=$IS_MACOS"
|
|
|
|
|
|
|
|
echo "Node $( node -v )"
|
|
|
|
echo "Npm $( npm -v )"
|
2021-12-20 17:08:43 +02:00
|
|
|
echo "Yarn $( yarn -v )"
|
2021-06-10 14:01:55 +02:00
|
|
|
|
|
|
|
# =============================================================================
|
|
|
|
# Install packages
|
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
cd "$ROOT_DIR"
|
2021-12-20 17:08:43 +02:00
|
|
|
yarn install
|
2022-08-18 17:28:10 +02:00
|
|
|
testResult=$?
|
|
|
|
if [ $testResult -ne 0 ]; then
|
|
|
|
echo "Yarn installation failed. Search for 'exit code 1' in the log for more information."
|
|
|
|
exit $testResult
|
|
|
|
fi
|
2021-06-10 14:01:55 +02:00
|
|
|
|
|
|
|
# =============================================================================
|
|
|
|
# Run test units. Only do it for pull requests and dev branch because we don't
|
|
|
|
# want it to randomly fail when trying to create a desktop release.
|
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
if [ "$IS_PULL_REQUEST" == "1" ] || [ "$IS_DEV_BRANCH" = "1" ]; then
|
2021-06-25 10:49:06 +02:00
|
|
|
echo "Step: Running tests..."
|
|
|
|
|
2021-11-30 17:37:07 +02:00
|
|
|
# On Linux, we run the Joplin Server tests using PostgreSQL
|
|
|
|
if [ "$IS_LINUX" == "1" ]; then
|
|
|
|
echo "Running Joplin Server tests using PostgreSQL..."
|
|
|
|
sudo docker-compose --file docker-compose.db-dev.yml up -d
|
|
|
|
export JOPLIN_TESTS_SERVER_DB=pg
|
|
|
|
else
|
|
|
|
echo "Running Joplin Server tests using SQLite..."
|
|
|
|
fi
|
|
|
|
|
2021-10-10 13:30:21 +02:00
|
|
|
# Need this because we're getting this error:
|
|
|
|
#
|
|
|
|
# @joplin/lib: FATAL ERROR: Ineffective mark-compacts near heap limit
|
|
|
|
# Allocation failed - JavaScript heap out of memory
|
|
|
|
#
|
|
|
|
# https://stackoverflow.com/questions/38558989
|
|
|
|
export NODE_OPTIONS="--max-old-space-size=4096"
|
2021-12-20 17:08:43 +02:00
|
|
|
yarn run test-ci
|
2021-06-10 14:01:55 +02:00
|
|
|
testResult=$?
|
|
|
|
if [ $testResult -ne 0 ]; then
|
|
|
|
exit $testResult
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# =============================================================================
|
|
|
|
# Run linter for pull requests only. We also don't want this to make the desktop
|
|
|
|
# release randomly fail.
|
|
|
|
# =============================================================================
|
|
|
|
|
2021-11-08 19:10:33 +02:00
|
|
|
if [ "$IS_PULL_REQUEST" == "1" ] || [ "$IS_DEV_BRANCH" = "1" ]; then
|
2021-06-25 10:49:06 +02:00
|
|
|
echo "Step: Running linter..."
|
|
|
|
|
2021-12-20 17:08:43 +02:00
|
|
|
yarn run linter-ci ./
|
2021-06-10 14:01:55 +02:00
|
|
|
testResult=$?
|
|
|
|
if [ $testResult -ne 0 ]; then
|
|
|
|
exit $testResult
|
|
|
|
fi
|
2022-12-27 19:39:30 +02:00
|
|
|
|
|
|
|
yarn run packageJsonLint
|
|
|
|
testResult=$?
|
|
|
|
if [ $testResult -ne 0 ]; then
|
|
|
|
exit $testResult
|
|
|
|
fi
|
2021-06-10 14:01:55 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# =============================================================================
|
|
|
|
# Validate translations - this is needed as some users manually edit .po files
|
|
|
|
# (and often make mistakes) instead of using a proper tool like poedit. Doing it
|
|
|
|
# for Linux only is sufficient.
|
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
if [ "$IS_PULL_REQUEST" == "1" ]; then
|
|
|
|
if [ "$IS_LINUX" == "1" ]; then
|
2021-06-25 10:49:06 +02:00
|
|
|
echo "Step: Validating translations..."
|
|
|
|
|
2021-06-10 14:01:55 +02:00
|
|
|
node packages/tools/validate-translation.js
|
|
|
|
testResult=$?
|
|
|
|
if [ $testResult -ne 0 ]; then
|
|
|
|
exit $testResult
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-11-08 19:10:33 +02:00
|
|
|
# =============================================================================
|
|
|
|
# Check that we didn't lose any string due to gettext not being able to parse
|
|
|
|
# newly modified or added scripts. This is convenient to quickly view on GitHub
|
2022-11-06 16:37:26 +02:00
|
|
|
# what commit may have broken translation building.
|
2021-11-08 19:10:33 +02:00
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
if [ "$IS_PULL_REQUEST" == "1" ] || [ "$IS_DEV_BRANCH" = "1" ]; then
|
2022-11-06 16:37:26 +02:00
|
|
|
if [ "$IS_LINUX" == "1" ]; then
|
2021-11-08 19:10:33 +02:00
|
|
|
echo "Step: Checking for lost translation strings..."
|
|
|
|
|
|
|
|
xgettext --version
|
|
|
|
|
|
|
|
node packages/tools/build-translation.js --missing-strings-check-only
|
|
|
|
testResult=$?
|
|
|
|
if [ $testResult -ne 0 ]; then
|
|
|
|
exit $testResult
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-07-16 12:52:42 +02:00
|
|
|
# =============================================================================
|
|
|
|
# Check .gitignore and .eslintignore files - they should be updated when
|
|
|
|
# new TypeScript files are added by running `yarn run updateIgnored`.
|
|
|
|
# See coding_style.md
|
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
if [ "$IS_PULL_REQUEST" == "1" ]; then
|
|
|
|
if [ "$IS_LINUX" == "1" ]; then
|
|
|
|
echo "Step: Checking for files that should have been ignored..."
|
|
|
|
|
|
|
|
node packages/tools/checkIgnoredFiles.js
|
|
|
|
testResult=$?
|
|
|
|
if [ $testResult -ne 0 ]; then
|
|
|
|
exit $testResult
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-06-10 14:01:55 +02:00
|
|
|
# =============================================================================
|
|
|
|
# Find out if we should run the build or not. Electron-builder gets stuck when
|
|
|
|
# building PRs so we disable it in this case. The Linux build should provide
|
|
|
|
# enough info if the app builds or not.
|
|
|
|
# https://github.com/electron-userland/electron-builder/issues/4263
|
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
if [ "$IS_PULL_REQUEST" == "1" ]; then
|
|
|
|
if [ "$IS_MACOS" == "1" ]; then
|
2021-06-25 10:49:06 +02:00
|
|
|
echo "Step: Not building Electron app"
|
2021-06-10 14:01:55 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# =============================================================================
|
2021-11-08 19:10:33 +02:00
|
|
|
# Build the Electron app or Docker image depending on the current tag.
|
2021-06-10 14:01:55 +02:00
|
|
|
#
|
|
|
|
# If the current tag is a desktop release tag (starts with "v", such as
|
2021-11-08 19:10:33 +02:00
|
|
|
# "v1.4.7"), we build and publish to GitHub. Otherwise we only build but don't
|
|
|
|
# publish to GitHub. It helps finding out any issue in pull requests and dev
|
|
|
|
# branch.
|
2021-06-10 14:01:55 +02:00
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
cd "$ROOT_DIR/packages/app-desktop"
|
|
|
|
|
|
|
|
if [[ $GIT_TAG_NAME = v* ]]; then
|
2021-06-25 10:49:06 +02:00
|
|
|
echo "Step: Building and publishing desktop application..."
|
2023-03-30 19:24:25 +02:00
|
|
|
# cd "$ROOT_DIR/packages/tools"
|
|
|
|
# node bundleDefaultPlugins.js
|
2022-09-01 12:53:58 +02:00
|
|
|
cd "$ROOT_DIR/packages/app-desktop"
|
2023-05-09 13:56:23 +02:00
|
|
|
|
|
|
|
if [ "$IS_MACOS" == "1" ]; then
|
2023-05-09 18:21:40 +02:00
|
|
|
# This is to fix this error:
|
|
|
|
#
|
|
|
|
# Exit code: ENOENT. spawn /usr/bin/python ENOENT
|
|
|
|
#
|
|
|
|
# Ref: https://github.com/electron-userland/electron-builder/issues/6767#issuecomment-1096589528
|
|
|
|
#
|
|
|
|
# It can be removed once we upgrade to electron-builder@23, however we
|
|
|
|
# cannot currently do this due to this error:
|
|
|
|
# https://github.com/laurent22/joplin/issues/8149
|
2023-07-12 17:00:30 +02:00
|
|
|
#
|
|
|
|
# electron-builder@24, however, still expects the python binary to be named
|
|
|
|
# "python" and seems to no longer respect the PYTHON_PATH environment variable.
|
|
|
|
# We work around this by aliasing python.
|
|
|
|
alias python=$(which python3)
|
|
|
|
USE_HARD_LINKS=false yarn run dist
|
2023-05-09 13:56:23 +02:00
|
|
|
else
|
|
|
|
USE_HARD_LINKS=false yarn run dist
|
|
|
|
fi
|
2022-02-23 11:02:13 +02:00
|
|
|
elif [[ $IS_LINUX = 1 ]] && [[ $GIT_TAG_NAME = $SERVER_TAG_PREFIX-* ]]; then
|
2021-06-25 10:49:06 +02:00
|
|
|
echo "Step: Building Docker Image..."
|
2021-06-11 18:24:59 +02:00
|
|
|
cd "$ROOT_DIR"
|
2022-02-23 11:02:13 +02:00
|
|
|
yarn run buildServerDocker --tag-name $GIT_TAG_NAME --push-images --repository $SERVER_REPOSITORY
|
2021-06-10 14:01:55 +02:00
|
|
|
else
|
2021-06-25 10:49:06 +02:00
|
|
|
echo "Step: Building but *not* publishing desktop application..."
|
2023-05-09 18:21:40 +02:00
|
|
|
|
|
|
|
if [ "$IS_MACOS" == "1" ]; then
|
|
|
|
# See above why we need to specify Python
|
2023-07-12 17:00:30 +02:00
|
|
|
alias python=$(which python3)
|
2023-07-13 20:09:45 +02:00
|
|
|
|
|
|
|
# We also want to disable signing the app in this case, because
|
|
|
|
# it randomly fails and we don't even need it
|
|
|
|
# https://www.electron.build/code-signing#how-to-disable-code-signing-during-the-build-process-on-macos
|
|
|
|
export CSC_IDENTITY_AUTO_DISCOVERY=false
|
|
|
|
npm pkg set 'build.mac.identity'=null --json
|
|
|
|
|
2023-07-12 17:00:30 +02:00
|
|
|
USE_HARD_LINKS=false yarn run dist --publish=never
|
2023-05-09 18:21:40 +02:00
|
|
|
else
|
|
|
|
USE_HARD_LINKS=false yarn run dist --publish=never
|
|
|
|
fi
|
2021-06-10 14:01:55 +02:00
|
|
|
fi
|