From c2d515725aa0780fcb22d02a159fb4442be785ef Mon Sep 17 00:00:00 2001 From: jasquat Date: Thu, 19 Oct 2023 14:38:40 -0400 Subject: [PATCH] merged backend and frontend github action test files w/ burnettk --- .../workflows/auto-merge-dependabot-prs.yml | 2 +- .github/workflows/frontend_tests.yml | 145 ------------------ .github/workflows/slack_notify.yml | 4 +- .../{backend_tests.yml => tests.yml} | 144 ++++++++++++++++- 4 files changed, 144 insertions(+), 151 deletions(-) delete mode 100644 .github/workflows/frontend_tests.yml rename .github/workflows/{backend_tests.yml => tests.yml} (63%) diff --git a/.github/workflows/auto-merge-dependabot-prs.yml b/.github/workflows/auto-merge-dependabot-prs.yml index 7982c6b4a..2d956f148 100644 --- a/.github/workflows/auto-merge-dependabot-prs.yml +++ b/.github/workflows/auto-merge-dependabot-prs.yml @@ -1,7 +1,7 @@ name: Dependabot auto-merge on: workflow_run: - workflows: ["Backend Tests", "Frontend Tests"] + workflows: ["Tests"] # completed does not mean success of Tests workflow. see below checking github.event.workflow_run.conclusion types: - completed diff --git a/.github/workflows/frontend_tests.yml b/.github/workflows/frontend_tests.yml deleted file mode 100644 index e7e7ffbd7..000000000 --- a/.github/workflows/frontend_tests.yml +++ /dev/null @@ -1,145 +0,0 @@ -name: Frontend Tests - -on: - workflow_run: - workflows: ["Backend Tests"] - # completed does not mean success of Tests workflow. see below checking github.event.workflow_run.conclusion - types: [completed] - -defaults: - run: - working-directory: spiffworkflow-frontend - -# https://docs.github.com/en/actions/using-workflows/reusing-workflows - -jobs: - tests: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - name: Development Code - uses: actions/checkout@v3 - with: - # Disabling shallow clone is recommended for improving relevancy of reporting in sonarcloud - fetch-depth: 0 - ref: ${{ github.event.workflow_run.head_sha }} - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 18.x - - run: npm install - - run: npm run lint - - run: npm test - - run: npm run build --if-present - - name: SonarCloud Scan - # thought about just skipping dependabot - # if: ${{ github.actor != 'dependabot[bot]' }} - # but figured all pull requests seems better, since none of them will have access to sonarcloud. - # however, with just skipping pull requests, the build associated with "Triggered via push" is also associated with the pull request and also fails hitting sonarcloud - # if: ${{ github.event_name != 'pull_request' }} - # so just skip everything but main - if: github.ref_name == 'main' - uses: sonarsource/sonarcloud-github-action@master - with: - projectBaseDir: spiffworkflow-frontend - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - # part about saving PR number and then using it from auto-merge-dependabot-prs from: - # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run - - name: Save PR number - if: ${{ github.event_name == 'pull_request' }} - env: - PR_NUMBER: ${{ github.event.number }} - run: | - mkdir -p ./pr - echo "$PR_NUMBER" > ./pr/pr_number - - uses: actions/upload-artifact@v3 - with: - name: pr_number - path: pr/ - - cypress-run: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - ref: ${{ github.event.workflow_run.head_sha }} - - name: Checkout Samples - uses: actions/checkout@v3 - with: - repository: sartography/sample-process-models - path: sample-process-models - - name: start_keycloak - working-directory: ./spiffworkflow-backend - run: ./keycloak/bin/start_keycloak - - name: start_backend - working-directory: ./spiffworkflow-backend - run: ./bin/build_and_run_with_docker_compose - timeout-minutes: 20 - env: - SPIFFWORKFLOW_BACKEND_LOAD_FIXTURE_DATA: "true" - SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME: "acceptance_tests.yml" - - name: start_frontend - # working-directory: ./spiffworkflow-frontend - run: ./bin/build_and_run_with_docker_compose - - name: wait_for_backend - working-directory: ./spiffworkflow-backend - run: ./bin/wait_for_server_to_be_up 5 - - name: wait_for_frontend - # working-directory: ./spiffworkflow-frontend - run: ./bin/wait_for_frontend_to_be_up 5 - - name: wait_for_keycloak - working-directory: ./spiffworkflow-backend - run: ./keycloak/bin/wait_for_keycloak 5 - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: | - echo "$GITHUB_CONTEXT" - - name: Cypress run - uses: cypress-io/github-action@v5 - with: - working-directory: ./spiffworkflow-frontend - browser: chrome - # only record on push, not pull_request, since we do not have secrets for PRs, - # so the required CYPRESS_RECORD_KEY will not be available. - # we have limited runs in cypress cloud, so only record main builds - # the direct check for github.event_name == 'push' is for if we want to go back to triggering this workflow - # directly, rather than when Backend Tests complete. - # note that github.event.workflow_run is referring to the Backend Tests workflow and another option - # for github.event.workflow_run.event is 'pull_request', which we want to ignore. - record: ${{ github.ref_name == 'main' && ((github.event_name == 'workflow_run' && github.event.workflow_run.event == 'push') || (github.event_name == 'push')) }} - env: - # pass the Dashboard record key as an environment variable - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - # pass GitHub token to allow accurately detecting a build vs a re-run build - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CYPRESS_SPIFFWORKFLOW_FRONTEND_AUTH_WITH_KEYCLOAK: "true" - - name: get_backend_logs_from_docker_compose - if: failure() - working-directory: ./spiffworkflow-backend - run: ./bin/get_logs_from_docker_compose >./log/docker_compose.log - - name: Upload logs - if: failure() - uses: "actions/upload-artifact@v3" - with: - name: spiffworkflow-backend-logs - path: "./spiffworkflow-backend/log/*.log" - - # https://github.com/cypress-io/github-action#artifacts - - name: upload_screenshots - uses: actions/upload-artifact@v3 - if: failure() - with: - name: cypress-screenshots - path: ./spiffworkflow-frontend/cypress/screenshots - # Test run video was always captured, so this action uses "always()" condition - - name: upload_videos - uses: actions/upload-artifact@v3 - if: failure() - with: - name: cypress-videos - path: ./spiffworkflow-frontend/cypress/videos diff --git a/.github/workflows/slack_notify.yml b/.github/workflows/slack_notify.yml index 886f968ad..a3eedfbde 100644 --- a/.github/workflows/slack_notify.yml +++ b/.github/workflows/slack_notify.yml @@ -2,14 +2,14 @@ name: Slack Notification on: workflow_run: - workflows: ["Backend Tests", "Frontend Tests", "Docker Image For Main Builds", "Release Builds", "Build Docs"] + workflows: ["Tests", "Docker Image For Main Builds", "Release Builds", "Build Docs"] types: [completed] jobs: send_notification: runs-on: ubuntu-latest steps: - - name: Notify on Backend Tests failure + - name: Notify on Tests failure if: ${{ github.event.workflow_run.conclusion != 'success' && github.event.workflow_run.conclusion != 'skipped' }} run: | curl -X POST -H 'Content-type: application/json' \ diff --git a/.github/workflows/backend_tests.yml b/.github/workflows/tests.yml similarity index 63% rename from .github/workflows/backend_tests.yml rename to .github/workflows/tests.yml index e3fcdf214..db4f37f31 100644 --- a/.github/workflows/backend_tests.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,4 @@ -name: Backend Tests +name: Tests on: - push @@ -9,7 +9,7 @@ defaults: working-directory: spiffworkflow-backend jobs: - tests: + tests-backend: name: ${{ matrix.session }} ${{ matrix.python }} / ${{ matrix.os }} ${{ matrix.database }} runs-on: ${{ matrix.os }} strategy: @@ -231,7 +231,7 @@ jobs: coverage: runs-on: ubuntu-latest - needs: [tests, run_pre_commit_checks, check_docker_start_script] + needs: [tests-backend, run_pre_commit_checks, check_docker_start_script] steps: - name: Check out the repository uses: actions/checkout@v3.3.0 @@ -295,3 +295,141 @@ jobs: with: name: pr_number path: pr/ + + + tests-frontend: + runs-on: ubuntu-latest + needs: [tests-backend, run_pre_commit_checks, check_docker_start_script] + defaults: + run: + working-directory: spiffworkflow-frontend + steps: + - name: Development Code + uses: actions/checkout@v3 + with: + # Disabling shallow clone is recommended for improving relevancy of reporting in sonarcloud + fetch-depth: 0 + ref: ${{ github.event.workflow_run.head_sha }} + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18.x + - run: npm install + - run: npm run lint + - run: npm test + - run: npm run build --if-present + - name: SonarCloud Scan + # thought about just skipping dependabot + # if: ${{ github.actor != 'dependabot[bot]' }} + # but figured all pull requests seems better, since none of them will have access to sonarcloud. + # however, with just skipping pull requests, the build associated with "Triggered via push" is also associated with the pull request and also fails hitting sonarcloud + # if: ${{ github.event_name != 'pull_request' }} + # so just skip everything but main + if: github.ref_name == 'main' + uses: sonarsource/sonarcloud-github-action@master + with: + projectBaseDir: spiffworkflow-frontend + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + # part about saving PR number and then using it from auto-merge-dependabot-prs from: + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run + - name: Save PR number + if: ${{ github.event_name == 'pull_request' }} + env: + PR_NUMBER: ${{ github.event.number }} + run: | + mkdir -p ./pr + echo "$PR_NUMBER" > ./pr/pr_number + - uses: actions/upload-artifact@v3 + with: + name: pr_number + path: pr/ + + cypress-run: + runs-on: ubuntu-latest + needs: [tests-backend, run_pre_commit_checks, check_docker_start_script] + defaults: + run: + working-directory: spiffworkflow-frontend + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ github.event.workflow_run.head_sha }} + - name: Checkout Samples + uses: actions/checkout@v3 + with: + repository: sartography/sample-process-models + path: sample-process-models + - name: start_keycloak + working-directory: ./spiffworkflow-backend + run: ./keycloak/bin/start_keycloak + - name: start_backend + working-directory: ./spiffworkflow-backend + run: ./bin/build_and_run_with_docker_compose + timeout-minutes: 20 + env: + SPIFFWORKFLOW_BACKEND_LOAD_FIXTURE_DATA: "true" + SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME: "acceptance_tests.yml" + - name: start_frontend + # working-directory: ./spiffworkflow-frontend + run: ./bin/build_and_run_with_docker_compose + - name: wait_for_backend + working-directory: ./spiffworkflow-backend + run: ./bin/wait_for_server_to_be_up 5 + - name: wait_for_frontend + # working-directory: ./spiffworkflow-frontend + run: ./bin/wait_for_frontend_to_be_up 5 + - name: wait_for_keycloak + working-directory: ./spiffworkflow-backend + run: ./keycloak/bin/wait_for_keycloak 5 + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: | + echo "$GITHUB_CONTEXT" + - name: Cypress run + uses: cypress-io/github-action@v5 + with: + working-directory: ./spiffworkflow-frontend + browser: chrome + # only record on push, not pull_request, since we do not have secrets for PRs, + # so the required CYPRESS_RECORD_KEY will not be available. + # we have limited runs in cypress cloud, so only record main builds + # the direct check for github.event_name == 'push' is for if we want to go back to triggering this workflow + # directly, rather than when Backend Tests complete. + # note that github.event.workflow_run is referring to the Backend Tests workflow and another option + # for github.event.workflow_run.event is 'pull_request', which we want to ignore. + record: ${{ github.ref_name == 'main' && ((github.event_name == 'workflow_run' && github.event.workflow_run.event == 'push') || (github.event_name == 'push')) }} + env: + # pass the Dashboard record key as an environment variable + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + # pass GitHub token to allow accurately detecting a build vs a re-run build + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CYPRESS_SPIFFWORKFLOW_FRONTEND_AUTH_WITH_KEYCLOAK: "true" + - name: get_backend_logs_from_docker_compose + if: failure() + working-directory: ./spiffworkflow-backend + run: ./bin/get_logs_from_docker_compose >./log/docker_compose.log + - name: Upload logs + if: failure() + uses: "actions/upload-artifact@v3" + with: + name: spiffworkflow-backend-logs + path: "./spiffworkflow-backend/log/*.log" + + # https://github.com/cypress-io/github-action#artifacts + - name: upload_screenshots + uses: actions/upload-artifact@v3 + if: failure() + with: + name: cypress-screenshots + path: ./spiffworkflow-frontend/cypress/screenshots + # Test run video was always captured, so this action uses "always()" condition + - name: upload_videos + uses: actions/upload-artifact@v3 + if: failure() + with: + name: cypress-videos + path: ./spiffworkflow-frontend/cypress/videos