From dbeb4d7b5d36eec4a6170568e615c4c02b59371b Mon Sep 17 00:00:00 2001 From: Artem Sorokin <38620398+seemewalkin@users.noreply.github.com> Date: Mon, 17 Nov 2025 09:37:20 +0100 Subject: [PATCH] ci: Fix /build-unit-test command to report checks on PRs (#21893) --- .../workflows/build-unit-test-pr-comment.yml | 5 +- .../workflows/ci-manual-build-unit-tests.yml | 79 ++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-unit-test-pr-comment.yml b/.github/workflows/build-unit-test-pr-comment.yml index 3932172e91f..736135f8261 100644 --- a/.github/workflows/build-unit-test-pr-comment.yml +++ b/.github/workflows/build-unit-test-pr-comment.yml @@ -8,6 +8,7 @@ permissions: pull-requests: read contents: read actions: write + issues: write jobs: validate_and_dispatch: @@ -91,7 +92,9 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} HEAD_SHA: ${{ steps.check_permissions.outputs.headSha }} + PR_NUMBER: ${{ steps.check_permissions.outputs.prNumber }} run: | gh workflow run ci-manual-build-unit-tests.yml \ --repo "${{ github.repository }}" \ - -f ref="${HEAD_SHA}" + -f ref="${HEAD_SHA}" \ + -f pr_number="${PR_NUMBER}" diff --git a/.github/workflows/ci-manual-build-unit-tests.yml b/.github/workflows/ci-manual-build-unit-tests.yml index 2a4adccd99e..dcacc0b9b11 100644 --- a/.github/workflows/ci-manual-build-unit-tests.yml +++ b/.github/workflows/ci-manual-build-unit-tests.yml @@ -6,8 +6,44 @@ on: ref: description: Commit SHA or ref to check out required: true + pr_number: + description: PR number (optional, for check reporting) + required: false + type: string + +permissions: + contents: read + checks: write jobs: + create-check-run: + name: Create Check Run + runs-on: ubuntu-latest + if: inputs.pr_number != '' + outputs: + check_run_id: ${{ steps.create.outputs.check_run_id }} + steps: + - name: Create pending check run on PR + id: create + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { data: checkRun } = await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: 'Build & Unit Tests - Checks', + head_sha: '${{ inputs.ref }}', + status: 'in_progress', + output: { + title: 'Build & Unit Tests - Checks', + summary: 'Running build, unit tests, and lint...' + } + }); + + core.setOutput('check_run_id', checkRun.id); + console.log(`Created check run ${checkRun.id} on commit ${{ inputs.ref }}`); + install-and-build: name: Install & Build runs-on: blacksmith-2vcpu-ubuntu-2204 @@ -47,9 +83,50 @@ jobs: post-build-unit-tests: name: Build & Unit Tests - Checks runs-on: ubuntu-latest - needs: [install-and-build, unit-tests, lint] + needs: [create-check-run, install-and-build, unit-tests, lint] if: always() steps: + - name: Update check run on PR (if triggered from PR comment) + if: inputs.pr_number != '' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const checkRunId = '${{ needs.create-check-run.outputs.check_run_id }}'; + + if (!checkRunId) { + console.log('No check run ID found, skipping update'); + return; + } + + const buildResult = '${{ needs.install-and-build.result }}'; + const testResult = '${{ needs.unit-tests.result }}'; + const lintResult = '${{ needs.lint.result }}'; + + const conclusion = (buildResult === 'success' && testResult === 'success' && lintResult === 'success') + ? 'success' + : 'failure'; + + const summary = ` + **Build**: ${buildResult} + **Unit Tests**: ${testResult} + **Lint**: ${lintResult} + `; + + await github.rest.checks.update({ + owner: context.repo.owner, + repo: context.repo.repo, + check_run_id: parseInt(checkRunId), + status: 'completed', + conclusion: conclusion, + output: { + title: 'Build & Unit Tests - Checks', + summary: summary + } + }); + + console.log(`Updated check run ${checkRunId} with conclusion: ${conclusion}`); + - name: Fail if any job failed if: needs.install-and-build.result == 'failure' || needs.unit-tests.result == 'failure' || needs.lint.result == 'failure' run: exit 1