You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	ci: improve workflow
1. Run tests, iff the other prerequisites are met 2. In case of a translation PR, skip tests not related to translations
This commit is contained in:
		
							
								
								
									
										96
									
								
								.github/scripts/run_ci.sh
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										96
									
								
								.github/scripts/run_ci.sh
									
									
									
									
										vendored
									
									
								
							| @@ -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" | ||||
| @@ -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. | ||||
| @@ -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`. | ||||
| @@ -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 | ||||
| @@ -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 | ||||
| @@ -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 | ||||
| @@ -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) | ||||
| @@ -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 | ||||
|   | ||||
							
								
								
									
										16
									
								
								.github/workflows/github-actions-main.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								.github/workflows/github-actions-main.yml
									
									
									
									
										vendored
									
									
								
							| @@ -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 | ||||
| @@ -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" | ||||
|  | ||||
| @@ -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: | ||||
| @@ -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 | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user