diff --git a/.github/workflows/tests-2.yml b/.github/workflows/tests-2.yml new file mode 100644 index 0000000000..5e8a58aba5 --- /dev/null +++ b/.github/workflows/tests-2.yml @@ -0,0 +1,111 @@ +name: Tests - 2 +on: + pull_request: {} + merge_group: + types: [checks_requested] + push: + branches: [develop, master] + repository_dispatch: + types: [element-web-notify] + workflow_call: + inputs: + disable_coverage: + type: boolean + required: false + description: "Specify true to skip generating and uploading coverage for tests" + matrix-js-sdk-sha: + type: string + required: false + description: "The matrix-js-sdk SHA to use" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + +env: + ENABLE_COVERAGE: ${{ github.event_name != 'merge_group' && inputs.disable_coverage != 'true' }} + # fetchdep.sh needs to know our PR number + PR_NUMBER: ${{ github.event.pull_request.number }} + +permissions: {} + +jobs: + jest_ew: + name: Jest (Element Web) + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + # Run multiple instances in parallel to speed up the tests + runner: [1, 2] + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + with: + repository: ${{ inputs.matrix-js-sdk-sha && 'element-hq/element-web' || github.repository }} + + - name: Yarn cache + uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6 + with: + node-version: "lts/*" + cache: "yarn" + + - name: Install Deps + run: "./scripts/layered.sh" + env: + JS_SDK_GITHUB_BASE_REF: ${{ inputs.matrix-js-sdk-sha }} + + - name: Jest Cache + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: /tmp/jest_cache + key: ${{ hashFiles('**/yarn.lock') }} + + - name: Get number of CPU cores + id: cpu-cores + uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2 + + - name: Run tests + run: | + yarn test \ + --ci \ + ./test/unit-tests/components/views/dialogs/ManualDeviceKeyVerificationDialog-test.tsx + env: + JEST_SONAR_UNIQUE_OUTPUT_NAME: true + + # tell jest to use coloured output + FORCE_COLOR: true + + - name: Move coverage files into place + if: env.ENABLE_COVERAGE == 'true' + run: mv coverage/lcov.info coverage/${{ steps.setupNode.outputs.node-version }}-${{ matrix.runner }}.lcov.info + + - name: Upload Artifact + if: env.ENABLE_COVERAGE == 'true' + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5 + with: + name: coverage-${{ matrix.runner }} + path: | + coverage + !coverage/lcov-report + + complete: + name: jest-tests + needs: jest_ew + if: always() + runs-on: ubuntu-24.04 + permissions: + statuses: write + steps: + - if: needs.jest_ew.result != 'skipped' && needs.jest_ew.result != 'success' + run: exit 1 + + - name: Skip SonarCloud in merge queue + if: github.event_name == 'merge_group' || inputs.disable_coverage == 'true' + uses: guibranco/github-status-action-v2@5530c593759f489bba08272e96986ffc571c1ea1 + with: + authToken: ${{ secrets.GITHUB_TOKEN }} + state: success + description: SonarCloud skipped + context: SonarCloud Code Analysis + sha: ${{ github.sha }} + target_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}