From dc2f83f67dfa201d272ffe036e622d32074690ea Mon Sep 17 00:00:00 2001 From: Rifa Achrinza <25147899+achrinza@users.noreply.github.com> Date: Sun, 3 Nov 2024 02:37:49 +0800 Subject: [PATCH] ci: shell-based test harness Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com> --- .github/workflows/ci.yaml | 38 +++++++++++++----- .gitmodules | 4 ++ cicd/vendor/setup-db2 | 1 + cicd/well-known/prepare-autoinstall.sh | 32 ++++++++++++++++ cicd/well-known/test-harness.sh | 53 ++++++++++++++++++++++++++ test/action.yaml | 2 - 6 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 .gitmodules create mode 160000 cicd/vendor/setup-db2 create mode 100755 cicd/well-known/prepare-autoinstall.sh create mode 100755 cicd/well-known/test-harness.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8272a3a..6660cb4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -103,13 +103,11 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 1 + submodules: true - name: Run test harness - uses: ./test - with: - node-version: ${{ github.matrix.node-version }} - db2-version: ${{ github.matrix.db2-version }} - _internal-mode: true - + env: + DB2_VERSION: ${{ matrix.db2-version }} + run: ./cicd/well-known/test-harness.sh test-ibmdb: name: Cross-test (IBM DB) runs-on: ubuntu-24.04 @@ -133,8 +131,28 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 1 - - name: Run test harness - uses: loopbackio/loopback-ibmdb/test@ci/ghaction-test + path: loopback-connector-db2 + submodules: true + - name: Clone IBM DB base connector repository + run: |- + git clone \ + --branch=ci/ghaction-test \ + --depth=1 \ + https://github.com/loopbackio/loopback-ibmdb.git + cd loopback-ibmdb + git submodule update --init --depth=1 + - name: Setup Node.js + uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 with: - node-version: ${{ github.matrix.node-version }} - db2-version: ${{ github.matrix.db2-version }} + node-version: ${{ matrix.node-version }} + cache: npm + cache-dependency-path: |- + ./loopback-ibmdb/package-lock.json + ./loopback-connector-db2/package-lock.json + - name: Setup and run test harness + env: + DB2_VERSION: ${{ matrix.db2-version }} + run: |- + ./loopback-ibmdb/cicd/well-known/prepare-autoinstall.sh + . ./loopback-ibmdb/cicd/tmp/well-known/set-env/post-prepare-autoinstall.sh + ./loopback-connector-db2/cicd/well-known/test-harness.sh diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f130702 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "cicd/vendor/setup-db2"] + path = cicd/vendor/setup-db2 + url = https://github.com/achrinza/setup-db2.git + branch = v0.1.0 diff --git a/cicd/vendor/setup-db2 b/cicd/vendor/setup-db2 new file mode 160000 index 0000000..1ecca51 --- /dev/null +++ b/cicd/vendor/setup-db2 @@ -0,0 +1 @@ +Subproject commit 1ecca51b69f420b59cf0ada9f66a1a476b4061fe diff --git a/cicd/well-known/prepare-autoinstall.sh b/cicd/well-known/prepare-autoinstall.sh new file mode 100755 index 0000000..d142203 --- /dev/null +++ b/cicd/well-known/prepare-autoinstall.sh @@ -0,0 +1,32 @@ +#!/bin/sh +export POSIXLY_CORRECT=1 +set -euv + +ORIG_DIR="$(pwd)" +cd "$(dirname "$0")/../.." +BASE_DIR="$(pwd)" + +CI_NODEJS_AUTOINSTALL_DIR="$BASE_DIR/cicd/tmp/nodejs-autoinstall" +PREPARE_POSTINSTALL_SCRIPT="$BASE_DIR/cicd/tmp/well-known/set-env/post-prepare-autoinstall.sh" + +STEP_COUNT=1 + +step () { + printf "\n\n============================================================================\n" + printf 'STEP #%d: %s\n' "$STEP_COUNT" "$1" + printf "\n============================================================================\n\n" + STEP_COUNT="$((STEP_COUNT + 1))" +} + +step 'Bootstrap dependencies' +npm ci --prefer-offline --ignore-scripts + +step 'Pack for autoinstall' +mkdir -p "CI_NODEJS_AUTOINSTALL_DIR" +npm pack --pack-destination="$CI_NODEJS_AUTOINSTALL_DIR" + +mkdir -p "$(dirname "$PREPARE_POSTINSTALL_SCRIPT")" +echo "export CI_NODEJS_AUTOINSTALL_DIR=\"$CI_NODEJS_AUTOINSTALL_DIR\"" >"$PREPARE_POSTINSTALL_SCRIPT" +chmod +x "$PREPARE_POSTINSTALL_SCRIPT" + +cd "$ORIG_DIR" diff --git a/cicd/well-known/test-harness.sh b/cicd/well-known/test-harness.sh new file mode 100755 index 0000000..235d04d --- /dev/null +++ b/cicd/well-known/test-harness.sh @@ -0,0 +1,53 @@ +#!/bin/sh +export POSIXLY_CORRECT=1 +set -euv + +export DB2_USERNAME=db2inst1 +export DB2_PASSWORD=P00lGnorts +export DB2_HOSTNAME=localhost +export DB2_PORTNUM=50000 +export DB2_DATABASE=mydb + +ORIG_DIR="$(pwd)" +cd "$(dirname "$0")/../.." +BASE_DIR="$(pwd)" + +CI_NODEJS_AUTOINSTALL_DIR="${CI_NODEJSAUTOINSTALL_DIR:-}" +STARTDB2_SCRIPT="$BASE_DIR/cicd/vendor/setup-db2/start-db2.sh" + +STEP_COUNT=1 + +step () { + printf "\n\n============================================================================\n" + printf 'STEP #%d: %s\n' "$STEP_COUNT" "$1" + printf "\n============================================================================\n\n" + STEP_COUNT="$((STEP_COUNT + 1))" +} + +step 'Bootstrap dependencies' +npm ci --prefer-offline + +step 'Bootstrap overriding dependencies' +if [ -d "$CI_NODEJS_AUTOINSTALL_DIR" ]; then + find \ + "$CI_NODEJS_AUTOINSTALL_DIR" \ + -iname '*.tgz' \ + -exec \ + npm install {} \; +fi +npm install --prefer-offline + +step 'Start DB2 LUW server' +"$STARTDB2_SCRIPT" \ + -l accept \ + -V "$DB2_VERSION" \ + -p 'P00lGnorts' + +step 'Run tests' +npm run pretest --ignore-scripts +npm test --ignore-scripts + +step 'Teardown DB2 LUW server' +"$STARTDB2_SCRIPT" -C + +cd "$ORIG_DIR" diff --git a/test/action.yaml b/test/action.yaml index ccf9739..a8150b3 100644 --- a/test/action.yaml +++ b/test/action.yaml @@ -42,8 +42,6 @@ runs: db2-license: accept db2-version: ${{ matrix.db2-version }} db2-password: P00lGnorts - - name: Setup FakeTTY - uses: Yuri6037/Action-FakeTTY@1abc69c7d530815855caedcd73842bae5687c1a6 # V1.1 - name: Run tests env: DB2_USERNAME: db2inst1