From 934c07bd9503340687213e206270e203faf928ef Mon Sep 17 00:00:00 2001 From: Shannon Klaus Date: Fri, 8 Nov 2024 13:09:19 -0700 Subject: [PATCH] Continue working on pipeline --- .github/actions/run-ee-server/action.yml | 21 ------ .github/workflows/build-artifacts.yml | 4 -- .github/workflows/dotnet.yml | 2 +- .github/workflows/tests.yml | 69 +++++++++++++++++++ .../wait-for-as-server-to-start.bash | 47 +++++++++++++ 5 files changed, 117 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/tests.yml create mode 100644 .github/workflows/wait-for-as-server-to-start.bash diff --git a/.github/actions/run-ee-server/action.yml b/.github/actions/run-ee-server/action.yml index b0af7d1b..050d9ff9 100644 --- a/.github/actions/run-ee-server/action.yml +++ b/.github/actions/run-ee-server/action.yml @@ -24,27 +24,6 @@ inputs: runs: using: "composite" steps: - - name: Install crudini to manipulate config.conf - # This will only work on the Github hosted runners. - run: pipx install crudini --pip-args "-c ${{ github.workspace }}/.github/workflows/requirements.txt" - working-directory: .github/workflows - shell: bash - - - name: Create config.conf - run: cp config.conf.template config.conf - working-directory: test - shell: bash - - - run: echo SUPERUSER_NAME_AND_PASSWORD="superuser" >> $GITHUB_ENV - shell: bash - - - name: Set credentials in config file - run: | - crudini --existing=param --set config.conf enterprise-edition user ${{ env.SUPERUSER_NAME_AND_PASSWORD }} - crudini --existing=param --set config.conf enterprise-edition password ${{ env.SUPERUSER_NAME_AND_PASSWORD }} - working-directory: test - shell: bash - - name: Log into Docker Hub to get server RC if: ${{ inputs.use-server-rc == 'true' }} run: docker login --username ${{ inputs.docker-hub-username }} --password ${{ inputs.docker-hub-password }} diff --git a/.github/workflows/build-artifacts.yml b/.github/workflows/build-artifacts.yml index b0b2fbb1..d53438dc 100644 --- a/.github/workflows/build-artifacts.yml +++ b/.github/workflows/build-artifacts.yml @@ -1,10 +1,6 @@ name: Build artifacts run-name: Build artifacts (run_tests=${{ inputs.run_tests }}, use-server-rc=${{ inputs.use-server-rc }}, server-tag=${{ inputs.server-tag }}) -# Builds manylinux wheels and source distribution -# Optionally run tests on manylinux wheels -# Then upload artifacts to Github - on: workflow_dispatch: inputs: diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index b5d6de05..ae5eb48c 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -76,7 +76,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 6.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..99835089 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,69 @@ +name: Run tests + +env: + +# Trigger test workflow whenever: +# 1. Commits are pushed directly to the mrt branch +on: + push: + branches: ["mrt"] + pull_request: + branches: ["mrt"] + types: [ + # Default triggers + opened, + synchronize, + reopened, + # Additional triggers + labeled, + unlabeled + ] + workflow_dispatch: + inputs: + test-server-rc: + type: boolean + default: false + required: true + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + fail-fast: false + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 6.0.x + - name: Restore dependencies + run: dotnet restore + - name: Install dependencies + run: dotnet add package NeoLua --version 1.3.14 + - name: Build + run: dotnet build --no-restore + + test-ee: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - uses: ./.github/actions/run-ee-server + with: + use-server-rc: ${{ contains(github.event.pull_request.labels.*.name, 'new-server-features') }} + docker-hub-username: ${{ secrets.DOCKER_HUB_BOT_USERNAME }} + docker-hub-password: ${{ secrets.DOCKER_HUB_BOT_PW }} + + - name: Run tests + run: dotnet test --no-build --verbosity normal + + - name: Show logs if failed + if: ${{ failure() }} + run: | + docker container logs aerospike + cat ./configs/aerospike.conf diff --git a/.github/workflows/wait-for-as-server-to-start.bash b/.github/workflows/wait-for-as-server-to-start.bash new file mode 100644 index 00000000..c43e17da --- /dev/null +++ b/.github/workflows/wait-for-as-server-to-start.bash @@ -0,0 +1,47 @@ +#!/bin/bash + +set -x +# Makes sure that if the "docker exec" command fails, it is not ignored +set -o pipefail + +container_name=$1 +is_security_enabled=$2 + +if [[ $is_security_enabled == true ]]; then + # We need to pass credentials to asinfo if server requires it + # TODO: passing in credentials via command line flags since I can't figure out how to use --instance with global astools.conf + user_credentials="--user=admin --password=admin" +fi + +while true; do + # An unset variable will have a default empty value + # Intermediate step is to print docker exec command's output in case it fails + # Sometimes, errors only appear in stdout and not stderr, like if asinfo throws an error because of no credentials + # (This is a bug in asinfo since all error messages should be sent to stderr) + # But piping and passing stdin to grep will hide the first command's stdout. + # grep doesn't have a way to print all lines passed as input. + # ack does have an option but it doesn't come installed by default + # shellcheck disable=SC2086 # The flags in user credentials should be separate anyways. Not one string + echo "Checking if we can reach the server via the service port..." + if docker exec "$container_name" asinfo $user_credentials -v status | tee >(cat) | grep -qE "^ok"; then + # Server is ready when asinfo returns ok + echo "Can reach server now." + # docker container inspect "$container_name" + break + fi + + echo "Server didn't return ok via the service port. Polling again..." +done + +# Although the server may be reachable via the service port, the cluster may not be fully initialized yet. +# If we try to connect too soon (e.g right after "status" returns ok), the client may throw error code -1 +while true; do + echo "Waiting for server to stabilize (i.e return a cluster key)..." + # We assume that when an ERROR is returned, the cluster is not stable yet (i.e not fully initialized) + if docker exec "$container_name" asinfo $user_credentials -v cluster-stable 2>&1 | (! grep -qE "^ERROR"); then + echo "Server is in a stable state." + break + fi + + echo "Server did not return a cluster key. Polling again..." +done