From e9e0c59e5e4f796e45d4823bbeea2a598ba8badb Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Tue, 10 Nov 2026 23:28:50 +0100 Subject: [PATCH] fix(ci): verify report artifacts after producer jobs finish --- .../workflows/__assert-report-artifact.yml | 40 ++++++++++++ .github/workflows/__shared-ci.yml | 21 ++++++ .github/workflows/__test-action-lint.yml | 45 +++++++------ .github/workflows/__test-action-test.yml | 64 +++++++++---------- docs/development/README.md | 3 +- 5 files changed, 118 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/__assert-report-artifact.yml diff --git a/.github/workflows/__assert-report-artifact.yml b/.github/workflows/__assert-report-artifact.yml new file mode 100644 index 0000000..a08b71e --- /dev/null +++ b/.github/workflows/__assert-report-artifact.yml @@ -0,0 +1,40 @@ +name: Internal - Assert native report artifact +on: + workflow_call: + inputs: + artifact-id: + description: Native report artifact produced by the scenario. + required: true + type: string + expected-reports: + description: JSON mapping of expected report filenames to their SHA-256 hashes. + required: true + type: string +permissions: {} +jobs: + verify: + runs-on: ubuntu-latest + steps: + # Read artifacts after the producer finishes, as downstream consumers do. + - name: Assert - Download the native report artifact + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + artifact-ids: ${{ inputs.artifact-id }} + path: downloaded-reports + merge-multiple: true + - name: Assert - Only expected reports are uploaded, with unchanged contents + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + EXPECTED_REPORTS: ${{ inputs.expected-reports }} + with: + script: | + const assert = require('node:assert/strict'); + const fs = require('node:fs'); + const path = require('node:path'); + const {createHash} = require('node:crypto'); + const expected = JSON.parse(process.env.EXPECTED_REPORTS); + const files = await (await glob.create('downloaded-reports/**/*', {matchDirectories: false})).glob(); + assert.deepEqual(files.map(file => path.basename(file)).sort(), Object.keys(expected).sort()); + for (const file of files) { + assert.equal(createHash('sha256').update(fs.readFileSync(file)).digest('hex'), expected[path.basename(file)]); + } diff --git a/.github/workflows/__shared-ci.yml b/.github/workflows/__shared-ci.yml index bb7ab99..6b2dbd1 100644 --- a/.github/workflows/__shared-ci.yml +++ b/.github/workflows/__shared-ci.yml @@ -37,12 +37,33 @@ jobs: permissions: contents: read test-action-test: + strategy: + fail-fast: false + matrix: + scenario: + [ + reports, + publication-disabled, + preparation, + composer-command, + failing-command, + failing-tests, + no-reports, + ] uses: $/.github/workflows/__test-action-test.yml + with: + scenario: ${{ matrix.scenario }} permissions: contents: read pull-requests: write test-action-lint: + strategy: + fail-fast: false + matrix: + scenario: [success, failure, no-reports] uses: $/.github/workflows/__test-action-lint.yml + with: + scenario: ${{ matrix.scenario }} permissions: contents: read pull-requests: write diff --git a/.github/workflows/__test-action-lint.yml b/.github/workflows/__test-action-lint.yml index da073a4..644acab 100644 --- a/.github/workflows/__test-action-lint.yml +++ b/.github/workflows/__test-action-lint.yml @@ -1,16 +1,20 @@ name: Internal - Test PHP lint action on: workflow_call: + inputs: + scenario: + description: Integration scenario to run. + required: true + type: string permissions: {} jobs: lint: runs-on: ubuntu-latest permissions: contents: read - strategy: - fail-fast: false - matrix: - scenario: [success, failure, no-reports] + outputs: + report-artifact-id: ${{ steps.lint.outputs.report-artifact-id }} + expected-reports: ${{ steps.assert.outputs.expected-reports }} steps: - name: Arrange - Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -19,7 +23,7 @@ jobs: - name: Arrange - Configure native PHPStan reports uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: - SCENARIO: ${{ matrix.scenario }} + SCENARIO: ${{ inputs.scenario }} with: script: | const fs = require('node:fs/promises'); @@ -42,21 +46,16 @@ jobs: coverage: none - name: Act - Lint without comment permission id: lint - continue-on-error: ${{ matrix.scenario == 'failure' }} + # The assertion below checks the exact expected outcome for every scenario. + continue-on-error: true uses: $/actions/lint with: working-directory: .test-php-lint - - name: Assert - Download the native lint artifact - if: steps.lint.outputs.report-artifact-id != '' - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - with: - artifact-ids: ${{ steps.lint.outputs.report-artifact-id }} - path: downloaded-reports - merge-multiple: true - - name: Assert - Preserve failures and upload only parsed reports + - name: Assert - Preserve failures and identify the native report + id: assert uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: - SCENARIO: ${{ matrix.scenario }} + SCENARIO: ${{ inputs.scenario }} OUTCOME: ${{ steps.lint.outcome }} ARTIFACT_ID: ${{ steps.lint.outputs.report-artifact-id }} with: @@ -69,14 +68,22 @@ jobs: return; } assert.match(process.env.ARTIFACT_ID, /^\d+$/); - const files = await (await glob.create('downloaded-reports/**/*', {matchDirectories: false})).glob(); - assert.equal(files.length, 1); - const report = fs.readFileSync(files[0], 'utf8'); - assert.equal(report, fs.readFileSync('.test-php-lint/phpstan-checkstyle.xml', 'utf8')); + const {createHash} = require('node:crypto'); + const report = fs.readFileSync('.test-php-lint/phpstan-checkstyle.xml', 'utf8'); + core.setOutput('expected-reports', {'phpstan-checkstyle.xml': createHash('sha256').update(report).digest('hex')}); assert.match(report, / path.basename(file)).sort(), process.env.COVERAGE === 'github' ? ['cobertura.xml', 'junit.xml'] : ['junit.xml']); - for (const file of files) assert.equal(fs.readFileSync(file, 'utf8'), fs.readFileSync(path.join(directory, path.basename(file)), 'utf8')); + const {createHash} = require('node:crypto'); + const reportNames = process.env.COVERAGE === 'github' ? ['cobertura.xml', 'junit.xml'] : ['junit.xml']; + core.setOutput('expected-reports', Object.fromEntries(reportNames.map(name => [name, createHash('sha256').update(fs.readFileSync(path.join(directory, name))).digest('hex')]))); const junit = fs.readFileSync(path.join(directory, 'junit.xml'), 'utf8'); assert.match(junit, /