From 2f18e2d78734ce6030fad8e61613b623a51feac4 Mon Sep 17 00:00:00 2001 From: DelanoWAF <112384635+DelanoWAF@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:50:25 +0100 Subject: [PATCH] ci: automatically run Larva tests as part of CI workflows (#479) [skip ci] * ci: add larva autorun workflow * add temp workflow * check ci change * move ci in order * docker instead of compose * reuse docker compose from ci * retry docker-compose * increase timeout * refactor: set version to latest * remove excess file * change ci order * undo stage change * attempt failed test trigger * add more failed tests * force logging * force more test failures * force another failure * change startup * change order * force log * set proper command and version * rebuild * keep only zaakbrug * add logging * undo logging * reset to base state * Revert "force log" This reverts commit 4805710bb9acb6fe9bba1366d1dd3eb465e3ebd3. * Revert "force another failure" This reverts commit 4f1cd85727173c3122afa60dd9070d41d1fb6f8f. * Revert "force more test failures" This reverts commit a971abb42fcd10ef30154fc207efb6043e1e855d. * Revert "add more failed tests" This reverts commit f312b8b529e730bbba716e54748388b844b37874. * Revert "attempt failed test trigger" This reverts commit f0623b450b7b0c5cd50134eb3ca4d14bf11ce53e. * use image-id instead for reliability * increase timeout and fix container-id reference * fix container-id setter * generate larva result as github summary * filter results 1 * filters results 2 * filter result 3 * filter results 4 * give up on filtering result * run larva before soapui for fail fast * add larva to release workflow too --------- Co-authored-by: MLenterman --- .github/workflows/ci.yml | 11 ++- .github/workflows/release.yml | 9 ++ .github/workflows/run-larva-scenarios.yml | 103 ++++++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/run-larva-scenarios.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 965024ad..1b991fa4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,11 +42,20 @@ jobs: upload-sarif-to-security: false run-frank-till-healthy-enabled: false + run-larva-scenarios: + uses: ./.github/workflows/run-larva-scenarios.yml + needs: + - version-next + - ci + with: + image-id: ${{ needs.ci.outputs.image-id }} + run-soapui-tests: runs-on: ubuntu-latest needs: - version-next - ci + - run-larva-scenarios steps: - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 with: @@ -108,4 +117,4 @@ jobs: if: always() with: name: reports-soapui-testreports - path: ./*/reports + path: ./*/reports \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3992bcca..9fcba44f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -52,11 +52,20 @@ jobs: upload-sarif-to-security: false run-frank-till-healthy-enabled: false + run-larva-scenarios: + uses: ./.github/workflows/run-larva-scenarios.yml + needs: + - version-next + - ci + with: + image-id: ${{ needs.ci.outputs.image-id }} + run-soapui-tests: runs-on: ubuntu-latest needs: - analyze-commits - ci + - run-larva-scenarios steps: - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 with: diff --git a/.github/workflows/run-larva-scenarios.yml b/.github/workflows/run-larva-scenarios.yml new file mode 100644 index 00000000..cb835dbe --- /dev/null +++ b/.github/workflows/run-larva-scenarios.yml @@ -0,0 +1,103 @@ +name: Run Larva Scenarios + +on: + workflow_call: + inputs: + image-id: + type: string + description: > + Docker image id of the loaded image to use. + + Note that the Docker image needs to be available to the Docker runtime already. + required: false + docker-image-tag: + type: string + description: > + Docker image tag of the loaded image to use. For example: 'wearefrank/zaakbrug:1.2.0'. + + Note that the Docker image needs to be available to the Docker runtime already. + required: false + +jobs: + run-larva-scenarios: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #4.1.7 + + - name: Download Docker tar + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 #4.1.8 + with: + name: build-docker-image + + - name: Load Docker tar + shell: bash + run: | + docker load --input image.tar + docker image ls -a + + - name: Start Application + id: docker-run + shell: bash + run: | + echo "container-id=$(docker run -d -p 8080:8080 -e dtap.stage=LOC ${{ inputs.image-id || inputs.docker-image-tag }})" >> "$GITHUB_OUTPUT" + timeout-minutes: 2 + + - name: Wait for Application to be Healthy + shell: bash + run: | + start_time=$(date +%s) + timeout=300 + while true; do + if [ "$(docker inspect --format='{{json .State.Health.Status}}' ${{steps.docker-run.outputs.container-id}})" = '"healthy"' ]; then + echo "Application is healthy." + break + fi + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) + if [ $elapsed_time -ge $timeout ]; then + echo "Application did not become healthy within $timeout seconds. Failing the job." + exit 1 + fi + echo "Waiting for application to be healthy..." + sleep 5 + done + timeout-minutes: 6 + + - name: Trigger Larva Tool + shell: bash + run: | + curl -X POST 'http://localhost:8080/iaf/larva/index.jsp' \ + --header 'Content-Type: application/x-www-form-urlencoded' \ + --data-urlencode 'scenariosrootdirectory=/opt/frank/testtool' \ + --data-urlencode 'waitbeforecleanup=100' \ + --data-urlencode 'loglevel=WRONG_PIPELINE_MESSAGES_PREPARED_FOR_DIFF' \ + --data-urlencode 'execute=/opt/frank/testtool' \ + --data-urlencode 'submit=start' > results.html + + - name: Check if all scenarios passed + shell: bash + run: | + if ! grep -q 'All scenarios passed' results.html; then + echo "Not all scenarios passed. Failing the job." + exit 1 + fi + + - name: Generate Result in Markdown + uses: docker://pandoc/core:3.5 + if: ${{ always() }} + with: + args: -s results.html --from html -o results.md --to gfm --standalone + + - name: Add Larva Result To GitHub Actions Summary + shell: bash + if: ${{ always() }} + run: | + cat results.md >> $GITHUB_STEP_SUMMARY + + - name: Cleanup + shell: bash + if: ${{ always() }} + run: | + docker stop ${{ steps.docker-run.outputs.container-id }} + docker rm --volumes ${{ steps.docker-run.outputs.container-id }} \ No newline at end of file