From 2c067aa1bbd23c10b5cf09e68c435c141c66e01f Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 22 Jun 2023 14:42:33 +0200 Subject: [PATCH] Fixed hack to kill Ghost after boot in tests - in the migration tests we need to boot Ghost and then kill it afterwards - because there was no easy way to do this, the workflow waits for 20s and then kills the last process ID - aside from being a terrible idea, it means we're also just arbitrarily waiting for 20s, which burns time when it takes shorter to boot Ghost - this commit implements an environment variable that will kill the server once it has run the whole boot process, and then fixes the workflow to use that --- .github/workflows/test.yml | 7 +++---- ghost/core/core/boot.js | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5dfd4083ea..b9a1fff042 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -128,10 +128,9 @@ jobs: - run: yarn --prefer-offline - name: Run Ghost and then kill it - working-directory: ghost/core - run: | - node index.js & - sleep 20 && { kill $! && wait $!; } 2>/dev/null + run: yarn workspace ghost run start + env: + GHOST_TESTS_KILL_SERVER_AFTER_BOOT: true - run: sqlite3 ${{ env.database__connection__filename }} "DELETE FROM migrations WHERE version LIKE '5.%';" if: matrix.env.DB == 'sqlite3' diff --git a/ghost/core/core/boot.js b/ghost/core/core/boot.js index 6b05432685..9c42a3c5a9 100644 --- a/ghost/core/core/boot.js +++ b/ghost/core/core/boot.js @@ -534,6 +534,14 @@ async function bootGhost({backend = true, frontend = true, server = true} = {}) // Step 7 - Init our background services, we don't wait for this to finish initBackgroundServices({config}); + // Step 8 - Kill the process - what?? + // During the migration tests, we want to boot ghost, run migrations, then shut down + // This is the easiest way to get Ghost to boot and then kill itself + if (process.env.GHOST_TESTS_KILL_SERVER_AFTER_BOOT === 'true') { + debug('Killing Ghost Server after boot'); + process.exit(0); + } + // We return the server purely for testing purposes if (server) { debug('End Boot: Returning Ghost Server');