name: Frontend tests on: pull_request: push: branches: - main - release-*.*.* permissions: {} jobs: detect-changes: name: Detect whether code changed runs-on: ubuntu-latest permissions: contents: read outputs: changed: ${{ steps.detect-changes.outputs.frontend }} steps: - uses: actions/checkout@v4 with: persist-credentials: true # required to get more history in the changed-files action fetch-depth: 2 - name: Detect changes id: detect-changes uses: ./.github/actions/change-detection with: self: .github/workflows/pr-frontend-unit-tests.yml frontend-unit-tests: permissions: contents: read id-token: write # Run this workflow only for PRs from forks; if it gets merged into `main` or `release-*`, # the `frontend-unit-tests-enterprise` workflow will run instead needs: detect-changes if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true && needs.detect-changes.outputs.changed == 'true' runs-on: ubuntu-latest-8-cores name: "Unit tests (${{ matrix.chunk }} / 8)" strategy: fail-fast: false matrix: chunk: [1, 2, 3, 4, 5, 6, 7, 8] steps: - uses: actions/checkout@v4 with: persist-credentials: false - uses: actions/setup-node@v4 with: node-version-file: '.nvmrc' cache: 'yarn' cache-dependency-path: 'yarn.lock' - run: yarn install --immutable --check-cache - run: yarn run test:ci env: TEST_MAX_WORKERS: 2 TEST_SHARD: ${{ matrix.chunk }} TEST_SHARD_TOTAL: 8 frontend-unit-tests-enterprise: permissions: contents: read id-token: write # Run this workflow for non-PR events (like pushes to `main` or `release-*`) OR for internal PRs (PRs not from forks) needs: detect-changes if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false && needs.detect-changes.outputs.changed == 'true' runs-on: ubuntu-latest-8-cores name: "Unit tests (${{ matrix.chunk }} / 8)" strategy: fail-fast: false matrix: chunk: [1, 2, 3, 4, 5, 6, 7, 8] steps: - uses: actions/checkout@v4 with: persist-credentials: false - uses: actions/setup-node@v4 with: node-version-file: '.nvmrc' cache: 'yarn' cache-dependency-path: 'yarn.lock' - name: Setup Enterprise uses: ./.github/actions/setup-enterprise with: github-app-name: 'grafana-ci-bot' - run: yarn install --immutable --check-cache - run: yarn run test:ci env: TEST_MAX_WORKERS: 2 TEST_SHARD: ${{ matrix.chunk }} TEST_SHARD_TOTAL: 8 # This is the job that is actually required by rulesets. # We need to require EITHER the OSS or the Enterprise job to pass. # However, if one is skipped, GitHub won't flat-map the shards, # so they won't be accepted by a ruleset. required-frontend-unit-tests: needs: - frontend-unit-tests - frontend-unit-tests-enterprise # always() is the best function here. # success() || failure() will skip this function if any need is also skipped. # That means conditional test suites will fail the entire requirement check. if: always() name: All frontend unit tests complete runs-on: ubuntu-latest steps: - name: Check test suites env: NEEDS: ${{ toJson(needs) }} run: | FAILURES="$(echo "$NEEDS" | jq 'with_entries(select(.value.result == "failure")) | map_values(.result)')" echo "$FAILURES" if [ "$(echo "$FAILURES" | jq '. | length')" != "0" ]; then exit 1 fi echo "All OK!"