Skip to content

Commit

Permalink
ci: shell-based test harness
Browse files Browse the repository at this point in the history
Signed-off-by: Rifa Achrinza <[email protected]>
  • Loading branch information
achrinza committed Nov 3, 2024
1 parent 07cdcec commit dc2f83f
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 12 deletions.
38 changes: 28 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions cicd/vendor/setup-db2
Submodule setup-db2 added at 1ecca5
32 changes: 32 additions & 0 deletions cicd/well-known/prepare-autoinstall.sh
Original file line number Diff line number Diff line change
@@ -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"
53 changes: 53 additions & 0 deletions cicd/well-known/test-harness.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 0 additions & 2 deletions test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc2f83f

Please sign in to comment.