From fbf0bb180a1b057acffe41c4a951cf0047b62fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Tue, 16 Jan 2024 23:04:33 +0100 Subject: [PATCH] WIP --- .../actions/baas-test-server/.eslintrc.json | 5 +++ .github/actions/baas-test-server/action.yml | 41 ++++--------------- .../actions/baas-test-server/start-server.js | 22 +++++++++- .../actions/baas-test-server/stop-server.js | 21 ++++++++++ .github/workflows/test-server.yml | 14 ++++++- integration-tests/baas-test-server/cli.ts | 7 +++- 6 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 .github/actions/baas-test-server/.eslintrc.json create mode 100644 .github/actions/baas-test-server/stop-server.js diff --git a/.github/actions/baas-test-server/.eslintrc.json b/.github/actions/baas-test-server/.eslintrc.json new file mode 100644 index 00000000000..ff83dcd0cf9 --- /dev/null +++ b/.github/actions/baas-test-server/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "parserOptions": { + "sourceType": "module" + } +} \ No newline at end of file diff --git a/.github/actions/baas-test-server/action.yml b/.github/actions/baas-test-server/action.yml index 22d3949841b..465c11ed081 100644 --- a/.github/actions/baas-test-server/action.yml +++ b/.github/actions/baas-test-server/action.yml @@ -9,40 +9,15 @@ inputs: default: master githash: description: Specific githash to use when starting the server (this is used instead of branch if provided) -# outputs: -# container-id: -# description: The id of the container created -# value: ${{ steps.baasaas-start.outputs.container-id }} -# baas-url: -# description: The url of the BaaS server created -# value: ${{ steps.baasaas-start.outputs.baas-url }} -# mongo-url: -# description: The url of the MongoDB instance backing the server created -# value: ${{ steps.baasaas-start.outputs.mongo-url }} +outputs: + container-id: + description: The id of the container created + baas-url: + description: The url of the BaaS server created + mongo-url: + description: The url of the MongoDB instance backing the server created runs: using: node20 main: start-server.js -# runs: -# using: composite -# steps: -# - uses: actions/checkout@v3 -# - uses: actions/setup-node@v3 -# with: -# node-version: 20 -# cache: npm -# - shell: bash -# run: npm ci --ignore-scripts -# - shell: bash -# run: npx baas-test-server baasaas start ${{ inputs.githash }} --branch ${{ inputs.branch }} -# id: baasaas-start -# env: -# BAASAAS_KEY: ${{ inputs.baasaas-key }} -# # Using another action to create a post step, since "composite" actions doesn't support those -# # See https://github.com/actions/runner/issues/1478 -# - name: Stop server -# uses: TLizer/action-with-post-step@v1 -# with: -# main: echo 'Nothing to do right now' -# post: npx baas-test-server baasaas start ${{ inputs.githash }} --branch ${{ inputs.branch }} - + post: stop-server.js diff --git a/.github/actions/baas-test-server/start-server.js b/.github/actions/baas-test-server/start-server.js index 7de00e7f952..be176bd8a3a 100644 --- a/.github/actions/baas-test-server/start-server.js +++ b/.github/actions/baas-test-server/start-server.js @@ -1,3 +1,21 @@ -import cp from "child_process"; +//////////////////////////////////////////////////////////////////////////// +// +// Copyright 2024 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////// -cp.execSync("ls"); +import cp from "node:child_process"; + +cp.execSync("npx baas-test-server baasaas start", { stdio: "inherit" }); diff --git a/.github/actions/baas-test-server/stop-server.js b/.github/actions/baas-test-server/stop-server.js new file mode 100644 index 00000000000..f8d4c344c45 --- /dev/null +++ b/.github/actions/baas-test-server/stop-server.js @@ -0,0 +1,21 @@ +//////////////////////////////////////////////////////////////////////////// +// +// Copyright 2024 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////// + +import cp from "node:child_process"; + +cp.execSync("npx baas-test-server baasaas stop", { stdio: "inherit" }); diff --git a/.github/workflows/test-server.yml b/.github/workflows/test-server.yml index 7d9491137ba..b8708eee796 100644 --- a/.github/workflows/test-server.yml +++ b/.github/workflows/test-server.yml @@ -17,7 +17,19 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Setup node version + uses: actions/setup-node@v3 + with: + node-version: 20 + cache: npm + - name: Install dependencies + run: npm ci --ignore-scripts - name: Start BaaS test server id: baas uses: ./.github/actions/baas-test-server - - run: curl ${{ steps.baas.outputs.baas-url }}/api/private/v1.0/version + with: + apiKey: ${{ secrets.BAASAAS_KEY }} + branch: ${{ inputs.branch }} + githash: ${{ inputs.githash }} + - name: Perform a request to the server + run: curl ${{ steps.baas.outputs.baas-url }}/api/private/v1.0/version diff --git a/integration-tests/baas-test-server/cli.ts b/integration-tests/baas-test-server/cli.ts index 4944020815e..ed2bedf9326 100755 --- a/integration-tests/baas-test-server/cli.ts +++ b/integration-tests/baas-test-server/cli.ts @@ -131,7 +131,10 @@ yargs(hideBin(process.argv)) .command( ["start [githash]"], "Start a container on the BaaSaaS service", - (yargs) => yargs.positional("githash", { type: "string" }).option("branch", { default: "master" }), + (yargs) => + yargs + .positional("githash", { type: "string", default: gha.getInput("githash") ?? undefined }) + .option("branch", { default: gha.getInput("branch") || "master" }), wrapCommand(async (argv) => { await printUserInfo(); const container = await baasaas.startContainer( @@ -158,7 +161,7 @@ yargs(hideBin(process.argv)) .command( ["stop [id]"], "Stop a container running on the BaaSaaS service", - (yargs) => yargs.positional("id", { type: "string" }), + (yargs) => yargs.positional("id", { type: "string", default: gha.getState("container-id") }), wrapCommand(async (argv) => { await printUserInfo(); if (argv.id) {