Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/__assert-report-artifact.yml
Original file line number Diff line number Diff line change
@@ -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)]);
}
21 changes: 21 additions & 0 deletions .github/workflows/__shared-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 26 additions & 19 deletions .github/workflows/__test-action-lint.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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');
Expand All @@ -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:
Expand All @@ -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, /<checkstyle\b/);
assert.equal(report.includes('<error'), process.env.SCENARIO === 'failure');

verify-reports:
needs: lint
if: needs.lint.outputs.report-artifact-id != ''
uses: $/.github/workflows/__assert-report-artifact.yml
with:
artifact-id: ${{ needs.lint.outputs.report-artifact-id }}
expected-reports: ${{ needs.lint.outputs.expected-reports }}

individual-comment:
if: inputs.scenario == 'success'
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
64 changes: 29 additions & 35 deletions .github/workflows/__test-action-test.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
name: Internal - Test PHP test action
on:
workflow_call: null
workflow_call:
inputs:
scenario:
description: Integration scenario to run.
required: true
type: string
permissions: {}
jobs:
test:
name: Test (${{ matrix.scenario }})
name: Test (${{ inputs.scenario }})
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- scenario: reports
coverage: github
- scenario: publication-disabled
coverage: ""
- scenario: preparation
coverage: ""
- scenario: composer-command
coverage: ""
- scenario: failing-command
coverage: ""
- scenario: failing-tests
coverage: github
- scenario: no-reports
coverage: ""
outputs:
report-artifact-id: ${{ steps.tests.outputs.report-artifact-id }}
expected-reports: ${{ steps.assert.outputs.expected-reports }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
Expand All @@ -34,7 +24,7 @@ jobs:
id: fixture
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
env:
SCENARIO: ${{ matrix.scenario }}
SCENARIO: ${{ inputs.scenario }}
with:
script: |-
const fs = require('node:fs/promises');
Expand Down Expand Up @@ -72,26 +62,21 @@ jobs:
composer-directories: '["."]'
- name: Act - Run project tests without comment permission
id: tests
continue-on-error: ${{ startsWith(matrix.scenario, 'failing-') }}
# The assertion below checks the exact expected outcome for every scenario.
continue-on-error: true
uses: $/actions/test
with:
working-directory: ${{ steps.fixture.outputs.directory }}
coverage: ${{ matrix.coverage }}
- name: Assert - Download the native report artifact
if: steps.tests.outputs.report-artifact-id != ''
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
artifact-ids: ${{ steps.tests.outputs.report-artifact-id }}
path: downloaded-reports
merge-multiple: true
coverage: ${{ (inputs.scenario == 'reports' || inputs.scenario == 'failing-tests') && 'github' || '' }}
- name: Assert - Reports and project preparation
id: assert
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
env:
DIRECTORY: ${{ steps.fixture.outputs.directory }}
OUTCOME: ${{ steps.tests.outcome }}
SCENARIO: ${{ matrix.scenario }}
SCENARIO: ${{ inputs.scenario }}
ARTIFACT_ID: ${{ steps.tests.outputs.report-artifact-id }}
COVERAGE: ${{ matrix.coverage }}
COVERAGE: ${{ (inputs.scenario == 'reports' || inputs.scenario == 'failing-tests') && 'github' || '' }}
with:
script: |-
const assert = require('node:assert/strict');
Expand All @@ -105,9 +90,9 @@ jobs:
return;
}
assert.match(process.env.ARTIFACT_ID, /^\d+$/);
const files = await (await glob.create('downloaded-reports/**/*', {matchDirectories: false})).glob();
assert.deepEqual(files.map(file => 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, /<testcase\b/);
assert.equal(junit.includes('<failure'), scenario === 'failing-tests');
Expand All @@ -121,7 +106,16 @@ jobs:
assert.equal(fs.readFileSync(path.join(directory, 'prepared.txt'), 'utf8'), 'ready');
}

verify-reports:
needs: test
if: needs.test.outputs.report-artifact-id != ''
uses: $/.github/workflows/__assert-report-artifact.yml
with:
artifact-id: ${{ needs.test.outputs.report-artifact-id }}
expected-reports: ${{ needs.test.outputs.expected-reports }}

individual-comment:
if: inputs.scenario == 'reports'
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
3 changes: 2 additions & 1 deletion docs/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public CI and documentation workflows. The Composer fixture covers automatic and
lockfile and lockfile-free setup, installation hooks, PHPUnit reports, and PHPStan.
Test-action cases cover Composer-owned report generation, coverage publication,
preparation, custom commands, and failure propagation. Dedicated lint and test
workflows retrieve native artifacts from successful and failed commands, check
workflows retrieve native artifacts in dependent jobs after successful or intentionally
failed commands finish. They compare report names and content hashes, check
that hidden project paths work without uploading unrelated files, and verify
empty artifact outputs when no reports are produced. Read-only jobs exercise
the default comment policy; separate jobs verify opt-in comments with collapsed
Expand Down
Loading