Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: improve workflow #11464

Closed
wants to merge 1 commit into from
Closed
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
96 changes: 57 additions & 39 deletions .github/scripts/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ echo "GIT_TAG_NAME=$GIT_TAG_NAME"
echo "BUILD_SEQUENCIAL=$BUILD_SEQUENCIAL"
echo "SERVER_REPOSITORY=$SERVER_REPOSITORY"
echo "SERVER_TAG_PREFIX=$SERVER_TAG_PREFIX"
echo "PR_TITLE=$PR_TITLE"

echo "IS_CONTINUOUS_INTEGRATION=$IS_CONTINUOUS_INTEGRATION"
echo "IS_PULL_REQUEST=$IS_PULL_REQUEST"
Expand All @@ -81,40 +82,6 @@ if [ $testResult -ne 0 ]; then
exit $testResult
fi

# =============================================================================
# Run test units
# =============================================================================

if [ "$RUN_TESTS" == "1" ]; then
echo "Step: Running tests..."

# 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
cmdResult=$?
if [ $cmdResult -ne 0 ]; then
exit $cmdResult
fi
export JOPLIN_TESTS_SERVER_DB=pg
else
echo "Running Joplin Server tests using SQLite..."
fi

# 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=32768"
yarn test-ci
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.
Expand Down Expand Up @@ -172,6 +139,23 @@ if [ "$RUN_TESTS" == "1" ]; then
fi
fi

# =============================================================================
# Check whether this is a translation PR. There is no need to run the entire
# pipeline in such a case, thus exit early.
# =============================================================================

if [ "$RUN_TESTS" == "1" ]; then
# Due to the ancient bash release in macOS, the following is required, instead
# of using ${var,,}
PR_TITLE=$(echo $PR_TITLE |tr '[:upper:]' '[:lower:]')
echo "Step: Checking for translation PR..."

if [[ "$PR_TITLE" =~ ^.*(translation|(add|fix|update) .*language|\.po)( .*)?$ ]]; then
echo "It is a translation PR. Exit early."
exit 0
fi
fi

# =============================================================================
# Check .gitignore and .eslintignore files - they should be updated when
# new TypeScript files are added by running `yarn updateIgnored`.
Expand All @@ -185,7 +169,7 @@ if [ "$IS_LINUX" == "1" ]; then
# so that checkIgnoredFiles works.
git restore .gitignore .eslintignore

node packages/tools/checkIgnoredFiles.js
node packages/tools/checkIgnoredFiles.js
testResult=$?
if [ $testResult -ne 0 ]; then
exit $testResult
Expand Down Expand Up @@ -224,6 +208,40 @@ if [ "$IS_LINUX" == "1" ]; then
fi
fi

# =============================================================================
# Run test units
# =============================================================================

if [ "$RUN_TESTS" == "1" ]; then
echo "Step: Running tests..."

# 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
cmdResult=$?
if [ $cmdResult -ne 0 ]; then
exit $cmdResult
fi
export JOPLIN_TESTS_SERVER_DB=pg
else
echo "Running Joplin Server tests using SQLite..."
fi

# 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=32768"
yarn test-ci
testResult=$?
if [ $testResult -ne 0 ]; then
exit $testResult
fi
fi

# =============================================================================
# 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
Expand Down Expand Up @@ -257,7 +275,7 @@ if [ "$IS_DESKTOP_RELEASE" == "1" ]; then

if [ "$IS_MACOS" == "1" ]; then
# 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
Expand All @@ -273,14 +291,14 @@ if [ "$IS_DESKTOP_RELEASE" == "1" ]; then
USE_HARD_LINKS=false yarn dist
else
USE_HARD_LINKS=false yarn dist
fi
fi
elif [[ $IS_LINUX = 1 ]] && [ "$IS_SERVER_RELEASE" == "1" ]; then
echo "Step: Building Docker Image..."
cd "$ROOT_DIR"
yarn buildServerDocker --tag-name $GIT_TAG_NAME --push-images --repository $SERVER_REPOSITORY
else
echo "Step: Building but *not* publishing desktop application..."

if [ "$IS_MACOS" == "1" ]; then
# See above why we need to specify Python
alias python=$(which python3)
Expand All @@ -290,7 +308,7 @@ else
# 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

USE_HARD_LINKS=false yarn dist --publish=never
else
USE_HARD_LINKS=false yarn dist --publish=never
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/github-actions-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
run: |
# https://yarnpkg.com/getting-started/install
corepack enable

# Login to Docker only if we're on a server release tag. If we run this on
# a pull request it will fail because the PR doesn't have access to
# secrets
Expand Down Expand Up @@ -115,6 +115,7 @@ jobs:
SERVER_REPOSITORY: joplin/server
SERVER_TAG_PREFIX: server
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
"${GITHUB_WORKSPACE}/.github/scripts/run_ci.sh"

Expand Down Expand Up @@ -189,7 +190,7 @@ jobs:
# Basic test to ensure that the created build is valid. It should exit with
# code 0 if it works.
docker run joplin/server:0.0.0-beta node dist/app.js migrate list

- name: Check HTTP request
run: |
# Need to pass environment variables:
Expand All @@ -201,23 +202,22 @@ jobs:
# Check if status code is correct
# if the actual_status DOES NOT include the expected_status
# it exits the process with code 1

expected_status="HTTP/1.1 200 OK"
actual_status=$(curl -I -X GET http://localhost:22300/api/ping | head -n 1)
if [[ ! "$actual_status" =~ "$expected_status" ]]; then
if [[ ! "$actual_status" =~ "$expected_status" ]]; then
echo 'Failed while checking the status code after request to /api/ping'
echo 'expected: ' $expected_status
echo 'actual: ' $actual_status
exit 1;
exit 1;
fi

# Check if the body response is correct
# if the actual_body is different of expected_body exit with code 1
expected_body='{"status":"ok","message":"Joplin Server is running"}'
actual_body=$(curl http://localhost:22300/api/ping)

if [[ "$actual_body" != "$expected_body" ]]; then
echo 'Failed while checking the body response after request to /api/ping'
exit 1;
fi

Loading