From 207919f5eb7de8d54ad62fe23b1fa01954fd8ae2 Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Tue, 15 Aug 2023 15:32:30 +0100 Subject: [PATCH] Upload test results to DB right after generation (#4967) ## Problem While adding new test results format, I've also changed the way we upload Allure reports to S3 (https://github.com/neondatabase/neon/pull/4549/commits/722c7956bb932b639759f41f49aadb6115ef2179) to avoid duplicated results from previous runs. But it broke links at earlier results (results are still available but on different URLs). This PR fixes this (by reverting logic in https://github.com/neondatabase/neon/pull/4549/commits/722c7956bb932b639759f41f49aadb6115ef2179 changes), and moves the logic for storing test results into db to allure generate step. It allows us to avoid test results duplicates in the db and saves some time on extra s3 downloads that happened in a different job before the PR. Ref https://neondb.slack.com/archives/C059ZC138NR/p1691669522160229 ## Summary of changes - Move test results storing logic from a workflow to `actions/allure-report-generate` --- .../actions/allure-report-generate/action.yml | 48 ++++++++++++++++++- .github/workflows/build_and_test.yml | 44 ++--------------- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/.github/actions/allure-report-generate/action.yml b/.github/actions/allure-report-generate/action.yml index daa369a1a0..f959833119 100644 --- a/.github/actions/allure-report-generate/action.yml +++ b/.github/actions/allure-report-generate/action.yml @@ -1,6 +1,13 @@ name: 'Create Allure report' description: 'Generate Allure report from uploaded by actions/allure-report-store tests results' +inputs: + store-test-results-into-db: + description: 'Whether to store test results into the database. TEST_RESULT_CONNSTR/TEST_RESULT_CONNSTR_NEW should be set' + type: boolean + required: false + default: false + outputs: base-url: description: 'Base URL for Allure report' @@ -139,9 +146,11 @@ runs: sed -i 's| ${WORKDIR}/index.html @@ -170,6 +179,41 @@ runs: aws s3 rm "s3://${BUCKET}/${LOCK_FILE}" fi + - name: Store Allure test stat in the DB + if: ${{ !cancelled() && inputs.store-test-results-into-db == 'true' }} + shell: bash -euxo pipefail {0} + env: + COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + REPORT_JSON_URL: ${{ steps.generate-report.outputs.report-json-url }} + run: | + export DATABASE_URL=${REGRESS_TEST_RESULT_CONNSTR} + + ./scripts/pysync + + poetry run python3 scripts/ingest_regress_test_result.py \ + --revision ${COMMIT_SHA} \ + --reference ${GITHUB_REF} \ + --build-type unified \ + --ingest ${WORKDIR}/report/data/suites.json + + - name: Store Allure test stat in the DB (new) + if: ${{ !cancelled() && inputs.store-test-results-into-db == 'true' }} + shell: bash -euxo pipefail {0} + env: + COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + BASE_S3_URL: ${{ steps.generate-report.outputs.base-s3-url }} + run: | + export DATABASE_URL=${REGRESS_TEST_RESULT_CONNSTR_NEW} + + ./scripts/pysync + + poetry run python3 scripts/ingest_regress_test_result-new-format.py \ + --reference ${GITHUB_REF} \ + --revision ${COMMIT_SHA} \ + --run-id ${GITHUB_RUN_ID} \ + --run-attempt ${GITHUB_RUN_ATTEMPT} \ + --test-cases-dir ${WORKDIR}/report/data/test-cases + - name: Cleanup if: always() shell: bash -euxo pipefail {0} diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 853f5f2919..a8eab7a86f 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -432,6 +432,11 @@ jobs: if: ${{ !cancelled() }} id: create-allure-report uses: ./.github/actions/allure-report-generate + with: + store-test-results-into-db: true + env: + REGRESS_TEST_RESULT_CONNSTR: ${{ secrets.REGRESS_TEST_RESULT_CONNSTR }} + REGRESS_TEST_RESULT_CONNSTR_NEW: ${{ secrets.REGRESS_TEST_RESULT_CONNSTR_NEW }} - uses: actions/github-script@v6 if: ${{ !cancelled() }} @@ -452,45 +457,6 @@ jobs: report, }) - - name: Store Allure test stat in the DB - if: ${{ !cancelled() && steps.create-allure-report.outputs.report-json-url }} - env: - COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} - REPORT_JSON_URL: ${{ steps.create-allure-report.outputs.report-json-url }} - TEST_RESULT_CONNSTR: ${{ secrets.REGRESS_TEST_RESULT_CONNSTR }} - run: | - ./scripts/pysync - - curl --fail --output suites.json "${REPORT_JSON_URL}" - export BUILD_TYPE=unified - export DATABASE_URL="$TEST_RESULT_CONNSTR" - - poetry run python3 scripts/ingest_regress_test_result.py \ - --revision ${COMMIT_SHA} \ - --reference ${GITHUB_REF} \ - --build-type ${BUILD_TYPE} \ - --ingest suites.json - - - name: Store Allure test stat in the DB (new) - if: ${{ !cancelled() && steps.create-allure-report.outputs.report-json-url }} - env: - COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} - REPORT_JSON_URL: ${{ steps.create-allure-report.outputs.report-json-url }} - TEST_RESULT_CONNSTR: ${{ secrets.REGRESS_TEST_RESULT_CONNSTR_NEW }} - BASE_S3_URL: ${{ steps.create-allure-report.outputs.base-s3-url }} - run: | - aws s3 cp --only-show-errors --recursive ${BASE_S3_URL}/data/test-cases ./test-cases - - ./scripts/pysync - - export DATABASE_URL="$TEST_RESULT_CONNSTR" - poetry run python3 scripts/ingest_regress_test_result-new-format.py \ - --reference ${GITHUB_REF} \ - --revision ${COMMIT_SHA} \ - --run-id ${GITHUB_RUN_ID} \ - --run-attempt ${GITHUB_RUN_ATTEMPT} \ - --test-cases-dir ./test-cases - coverage-report: runs-on: [ self-hosted, gen3, small ] container: