department-of-veterans-affairs/vets-website

View on GitHub
.github/workflows/unit-test-stress-test.yml

Summary

Maintainability
Test Coverage
name: Unit Test Stability Review

on:
  schedule:
    - cron: '0 02 * * 1-5' # 10pm EST/2am UTC, weekdays

jobs:
  testing-reports-prep:
    name: Testing Reports Prep
    runs-on: ubuntu-latest
    continue-on-error: true
    outputs:
      app_list: ${{ env.APPLICATION_LIST }}
    steps:
      - name: Checkout
        uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017

      - name: Install dependencies
        uses: ./.github/workflows/install
        timeout-minutes: 30
        with:
          key: ${{ hashFiles('yarn.lock') }}
          yarn_cache_folder: .cache/yarn
          path: |
            .cache/yarn
            node_modules

      - name: Generate new application list
        run: yarn generate-app-list
      # exports app list and assigns to environmental variable at this step

      - name: Configure AWS credentials
        uses: ./.github/workflows/configure-aws-credentials
        with:
          aws_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws_region: us-gov-west-1

      - name: Get va-vsp-bot token
        uses: ./.github/workflows/inject-secrets
        with:
          ssm_parameter: /devops/VA_VSP_BOT_GITHUB_TOKEN
          env_variable_name: VA_VSP_BOT_GITHUB_TOKEN

      - name: Init Dashboard Data Repo
        uses: ./.github/workflows/init-data-repo

      - name: Set Up BigQuery Creds
        uses: ./.github/workflows/configure-bigquery

      - name: Upload app list to BigQuery
        run: yarn generate-app-list
        working-directory: qa-standards-dashboard-data

  fetch-unit-tests-allow-list:
    name: Fetch Unit Test Stability Allow List
    runs-on: ubuntu-16-cores-latest
    steps:
      - name: Checkout
        uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017

      - name: Configure AWS credentials
        uses: ./.github/workflows/configure-aws-credentials
        with:
          aws_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws_region: us-gov-west-1

      - name: Get va-vsp-bot token
        uses: ./.github/workflows/inject-secrets
        with:
          ssm_parameter: /devops/VA_VSP_BOT_GITHUB_TOKEN
          env_variable_name: VA_VSP_BOT_GITHUB_TOKEN

      - name: Init Dashboard Data Repo
        # uses: department-of-veterans-affairs/platform-release-tools-actions/init-data-repo@main
        uses: ./.github/workflows/init-data-repo

      - name: Set Up BigQuery Creds
        uses: ./.github/workflows/configure-bigquery

      - name: Fetch Unit Test Stability Allow List
        run: yarn get-allow-list
        working-directory: qa-standards-dashboard-data
        env:
          TEST_TYPE: unit_test

      - name: Archive Unit Test Stability Allow List
        if: ${{ always() }}
        uses: ./.github/workflows/upload-artifact
        with:
          name: unit-test-allow-list
          path: qa-standards-dashboard-data/unit_test_allow_list.json

  tests-prep:
    name: Tests Prep
    needs: [fetch-unit-tests-allow-list]
    runs-on: ubuntu-latest
    outputs:
      app_folders: ${{ steps.get-changed-apps.outputs.folders }}
      apps-to-stress-test: ${{ steps.apps-to-stress-test.outputs.apps_to_test }}
      unit-tests-to-stress-test: ${{ steps.unit-tests-to-stress-test.outputs.tests }}
      disallowed-tests: ${{ steps.disallowed-tests.outputs.tests }}

    steps:
      - name: Checkout
        uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017
        with:
          fetch-depth: 0

      - name: Install dependencies
        uses: ./.github/workflows/install
        timeout-minutes: 30
        with:
          key: ${{ hashFiles('yarn.lock') }}
          yarn_cache_folder: .cache/yarn
          path: |
            .cache/yarn
            node_modules

      - name: Get changed applications
        id: get-changed-apps
        uses: ./.github/workflows/get-changed-apps
        with:
          delimiter: ','
          output-type: 'entry_name, url'

      - name: Download Unit Test Stability Allow List
        uses: ./.github/workflows/download-artifact
        with:
          name: unit-test-allow-list
          path: .

      - name: Run Unit Test Selection
        run: node script/github-actions/select-unit-tests.js
        env:
          CHANGED_FILES: ${{ steps.get-changed-apps.outputs.changed_files }}
          IS_STRESS_TEST: true

      - name: Set output of DISALLOWED_TESTS
        if: ${{ always() }}
        id: disallowed-tests
        run: echo "tests=$DISALLOWED_TESTS" >> $GITHUB_OUTPUT

      - name: Set output of UNIT_TESTS_TO_STRESS_TEST
        if: ${{ always() }}
        id: unit-tests-to-stress-test
        run: echo "tests=$UNIT_TESTS_TO_STRESS_TEST" >> $GITHUB_OUTPUT

      - name: Upload artifact of Unit Tests to Stress Test
        if: ${{ steps.unit-tests-to-stress-test.outputs.tests == 'true' }}
        uses: ./.github/workflows/upload-artifact
        with:
          name: unit-tests-to-stress-test
          path: unit_tests_to_stress_test.json

      - name: Set output of APPS_TO_STRESS_TEST
        if: ${{ always() }}
        id: apps-to-stress-test
        run: echo "apps_to_test=$APPS_TO_STRESS_TEST" >> $GITHUB_OUTPUT

  unit-tests-stress-test:
    name: Unit Tests
    runs-on: ubuntu-latest
    needs: [fetch-unit-tests-allow-list, tests-prep]

    env:
      APPS_TO_VERIFY: ${{ needs.tests-prep.outputs.apps-to-stress-test }}
      DISALLOWED_TESTS: '[]'

    strategy:
      fail-fast: false
      max-parallel: 20
      matrix:
        runs:
          [
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            19,
            20,
          ]

    steps:
      - name: Checkout
        uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017
        with:
          fetch-depth: 0

      - name: Install dependencies
        uses: ./.github/workflows/install
        timeout-minutes: 30
        with:
          key: ${{ hashFiles('yarn.lock') }}
          yarn_cache_folder: .cache/yarn
          path: |
            .cache/yarn
            node_modules

      - name: Create test results folder
        run: mkdir -p test-results

      - name: Get changed applications
        id: get-changed-apps
        uses: ./.github/workflows/get-changed-apps
        with:
          delimiter: ','
          output-type: 'folder'

      - name: Download Unit Test Stability Allow List
        uses: ./.github/workflows/download-artifact
        with:
          name: unit-test-allow-list
          path: .

      - name: Download Tests to verify
        uses: ./.github/workflows/download-artifact
        with:
          name: unit-tests-to-stress-test
          path: .

      - name: Run unit tests
        run: yarn test:unit:gha ${APP_FOLDERS:+"{script,$APP_FOLDERS}/**/*.unit.spec.js?(x)"} --coverage --log-level trace
        env:
          MOCHA_FILE: test-results/unit-tests.xml
          APP_FOLDERS: ${{ steps.get-changed-apps.outputs.folders }}
          IS_STRESS_TEST: true
          STEP: ${{ matrix.runs }}

      - name: Archive unit test results
        if: ${{ always() }}
        uses: ./.github/workflows/upload-artifact
        with:
          name: unit-test-stress-test-results-${{ matrix.runs }}
          path: mocha/results

  update-unit-test-allow-list:
    name: Update Unit Test Stability Allow List
    runs-on: ubuntu-latest
    needs: [unit-tests-stress-test, fetch-unit-tests-allow-list]
    if: ${{ always() && (needs.unit-tests-stress-test.result == 'success' || needs.unit-tests-stress-test.result == 'failure') }}
    continue-on-error: true
    env:
      APPLICATION_LIST: ${{ needs.testing-reports-prep.outputs.app_list }}
    steps:
      - name: Checkout
        uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017

      - name: Configure AWS credentials
        uses: ./.github/workflows/configure-aws-credentials
        with:
          aws_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws_region: us-gov-west-1

      - name: Get va-vsp-bot token
        uses: ./.github/workflows/inject-secrets
        with:
          ssm_parameter: /devops/VA_VSP_BOT_GITHUB_TOKEN
          env_variable_name: VA_VSP_BOT_GITHUB_TOKEN

      - name: Init Dashboard Data Repo
        # uses: department-of-veterans-affairs/platform-release-tools-actions/init-data-repo@main
        uses: ./.github/workflows/init-data-repo

      - name: Set Up BigQuery Creds
        uses: ./.github/workflows/configure-bigquery
      - name: Get AWS IAM role
        uses: ./.github/workflows/inject-secrets
        with:
          ssm_parameter: /frontend-team/github-actions/parameters/AWS_FRONTEND_NONPROD_ROLE
          env_variable_name: AWS_FRONTEND_NONPROD_ROLE

      - name: Set UUID for Mochawesome reports
        run: echo "UUID=$(uuidgen)" >> $GITHUB_ENV

      - name: Configure AWS Credentials (2)
        uses: ./.github/workflows/configure-aws-credentials
        with:
          aws_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws_region: us-gov-west-1
          role: ${{ env.AWS_FRONTEND_NONPROD_ROLE }}
          role_duration: 900
          session_name: vsp-frontendteam-githubaction

      - name: Download Unit Test results
        uses: ./.github/workflows/download-artifact
        with:
          pattern: unit-test-stress-test-results-*
          path: qa-standards-dashboard-data/src/allow-list/data
          merge-multiple: true

      - name: Download Unit Test Stability Allow List
        uses: ./.github/workflows/download-artifact
        with:
          name: unit-test-allow-list
          path: qa-standards-dashboard-data

      - name: Copy test results to mochawesome directory
        run: cp -R qa-standards-dashboard-data/src/allow-list/data qa-standards-dashboard-data/src/testing-reports/data

      - name: Update Unit Test Stability Allow List
        run: yarn update-allow-list
        working-directory: qa-standards-dashboard-data
        env:
          TEST_TYPE: unit_test
          IS_CI: false
          GITHUB_WORKFLOW_URL: ${{ github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }}