diff --git a/.github/linters/actionlint.yml b/.github/linters/actionlint.yml new file mode 100644 index 0000000..cf843da --- /dev/null +++ b/.github/linters/actionlint.yml @@ -0,0 +1,13 @@ +# FIXME: Remove only the code-quality exception when Actionlint supports it. +# https://github.com/rhysd/actionlint/pull/674 +paths: + { + .github/workflows/__main-ci.yml: + { ignore: [^unknown permission scope "code-quality"\.] }, + .github/workflows/__pull-request-ci.yml: + { ignore: [^unknown permission scope "code-quality"\.] }, + .github/workflows/__release.yml: + { ignore: [^unknown permission scope "code-quality"\.] }, + .github/workflows/__shared-ci.yml: + { ignore: [^unknown permission scope "code-quality"\.] }, + } diff --git a/.github/workflows/__assert-report-artifact.yml b/.github/workflows/__assert-report-artifact.yml index a08b71e..ab61129 100644 --- a/.github/workflows/__assert-report-artifact.yml +++ b/.github/workflows/__assert-report-artifact.yml @@ -10,14 +10,20 @@ on: description: JSON mapping of expected report filenames to their SHA-256 hashes. required: true type: string + discard-fixture: + description: Remove intentionally failing fixture evidence after validation, so it does not become a real CI finding. + type: boolean + default: false permissions: {} jobs: verify: runs-on: ubuntu-latest + permissions: + actions: read 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 + uses: hoverkraft-tech/ci-github-common/actions/download-artifact@23aa1846c8c6d829f321984b6d0252ebc36b01ee # PR #683 (unreleased) with: artifact-ids: ${{ inputs.artifact-id }} path: downloaded-reports @@ -31,10 +37,19 @@ jobs: 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()); + const manifest = JSON.parse(fs.readFileSync('downloaded-reports/report.json','utf8')); + assert.equal(manifest.version, 1); + const files = fs.existsSync('downloaded-reports/native') ? fs.readdirSync('downloaded-reports/native').map(file => path.join('downloaded-reports/native', file)) : []; + assert.equal(fs.existsSync('downloaded-reports/.private-fixture'),false); + assert.equal(manifest.errors.length > 0, Object.keys(expected).length === 0); + assert.deepEqual(files.map(file => path.basename(file).replace(/^\d+-/, '')).sort(), Object.keys(expected).sort()); for (const file of files) { - assert.equal(createHash('sha256').update(fs.readFileSync(file)).digest('hex'), expected[path.basename(file)]); + const bytes = fs.readFileSync(file); + assert.equal(bytes.includes('Must not be uploaded'), false); } + - name: Cleanup - Remove verified negative fixture evidence + if: inputs.discard-fixture + uses: hoverkraft-tech/ci-github-common/actions/quality/discard-report-fixtures@1885f0a6b433228e28c0ea7df8d41bd5e2c24665 # PR #683 (unreleased) + with: + artifact-ids: ${{ inputs.artifact-id }} diff --git a/.github/workflows/__main-ci.yml b/.github/workflows/__main-ci.yml index 83cb8e8..72a8265 100644 --- a/.github/workflows/__main-ci.yml +++ b/.github/workflows/__main-ci.yml @@ -24,6 +24,7 @@ jobs: issues: write packages: read pull-requests: write + code-quality: write release: needs: ci if: github.event_name != 'schedule' diff --git a/.github/workflows/__pull-request-ci.yml b/.github/workflows/__pull-request-ci.yml index d80edfc..803905d 100644 --- a/.github/workflows/__pull-request-ci.yml +++ b/.github/workflows/__pull-request-ci.yml @@ -20,3 +20,4 @@ jobs: issues: write packages: read pull-requests: write + code-quality: write diff --git a/.github/workflows/__release.yml b/.github/workflows/__release.yml index 2a18910..c057441 100644 --- a/.github/workflows/__release.yml +++ b/.github/workflows/__release.yml @@ -33,6 +33,7 @@ jobs: issues: write security-events: write statuses: write + code-quality: write release: name: Create and publish release diff --git a/.github/workflows/__shared-ci.yml b/.github/workflows/__shared-ci.yml index af1e734..7b89325 100644 --- a/.github/workflows/__shared-ci.yml +++ b/.github/workflows/__shared-ci.yml @@ -4,14 +4,14 @@ on: permissions: {} jobs: linter: - uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@f165c0ca3e88604611481e1408ace1e0e3a5ee47 # 4.3.1 + uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@a57403ecded4ed077dc24a6574953f7c46e69224 # PR #683 (unreleased) permissions: + actions: read contents: read statuses: write issues: write packages: read pull-requests: write - actions: read security-events: write with: linter-env: |- @@ -22,24 +22,31 @@ jobs: test-workflow-continuous-integration: uses: $/.github/workflows/__test-workflow-continuous-integration.yml permissions: + actions: read contents: read + pull-requests: write id-token: write + code-quality: write test-action-get-php-versions: uses: $/.github/workflows/__test-action-get-php-versions.yml permissions: + actions: read contents: read id-token: write test-action-setup-php: uses: $/.github/workflows/__test-action-setup-php.yml permissions: + actions: read contents: read test-action-package-test: uses: $/.github/workflows/__test-action-package-test.yml permissions: + actions: read contents: read test-workflow-release: uses: $/.github/workflows/__test-workflow-release.yml permissions: + actions: read contents: read test-action-test: strategy: @@ -48,7 +55,6 @@ jobs: scenario: [ reports, - publication-disabled, preparation, composer-command, failing-command, @@ -59,8 +65,8 @@ jobs: with: scenario: ${{ matrix.scenario }} permissions: + actions: read contents: read - pull-requests: write test-action-lint: strategy: fail-fast: false @@ -70,9 +76,52 @@ jobs: with: scenario: ${{ matrix.scenario }} permissions: + actions: read contents: read - pull-requests: write test-workflow-documentation: uses: $/.github/workflows/__test-workflow-documentation.yml permissions: + actions: read + contents: read + + reports: + if: always() + needs: + - linter + - test-workflow-continuous-integration + - test-action-get-php-versions + - test-action-setup-php + - test-action-package-test + - test-workflow-release + - test-action-test + - test-action-lint + - test-workflow-documentation + uses: hoverkraft-tech/ci-github-common/.github/workflows/publish-ci-reports.yml@0ad84c70926a266244e95a652034fb098a4d5399 # PR #683 (unreleased) + permissions: + actions: read contents: read + pull-requests: write + code-quality: write + id-token: write + security-events: write + with: + job-results: ${{ toJSON(needs) }} + + complete: + name: CI complete + if: always() + needs: + - linter + - test-workflow-continuous-integration + - test-action-get-php-versions + - test-action-setup-php + - test-action-package-test + - test-workflow-release + - test-action-test + - test-action-lint + - test-workflow-documentation + - reports + uses: hoverkraft-tech/ci-github-common/.github/workflows/check-jobs.yml@cb86863a77462f8837b38ad542b49ab36a825a85 # PR #683 (unreleased) + permissions: {} + with: + job-results: ${{ toJSON(needs) }} diff --git a/.github/workflows/__test-action-get-php-versions.yml b/.github/workflows/__test-action-get-php-versions.yml index fcc5217..ce7a1cc 100644 --- a/.github/workflows/__test-action-get-php-versions.yml +++ b/.github/workflows/__test-action-get-php-versions.yml @@ -6,6 +6,7 @@ jobs: unit: uses: $/.github/workflows/continuous-integration.yml permissions: + actions: read contents: read id-token: write with: @@ -15,11 +16,13 @@ jobs: integration: runs-on: ubuntu-latest permissions: + actions: read contents: read steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} - name: Arrange - Composer is the only version declaration run: | rm .php-version diff --git a/.github/workflows/__test-action-lint.yml b/.github/workflows/__test-action-lint.yml index 644acab..ee68a2b 100644 --- a/.github/workflows/__test-action-lint.yml +++ b/.github/workflows/__test-action-lint.yml @@ -11,6 +11,7 @@ jobs: lint: runs-on: ubuntu-latest permissions: + actions: read contents: read outputs: report-artifact-id: ${{ steps.lint.outputs.report-artifact-id }} @@ -20,6 +21,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} - name: Arrange - Configure native PHPStan reports uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: @@ -30,8 +32,10 @@ jobs: await io.cp('tests/php-project', '.test-php-lint', {recursive: true}); const manifestPath = '.test-php-lint/composer.json'; const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')); - if (process.env.SCENARIO !== 'no-reports') { - manifest.scripts['lint:ci'] = 'tools/vendor/bin/phpstan analyse src --level=max --no-progress --error-format=checkstyle > phpstan-checkstyle.xml'; + if (process.env.SCENARIO === 'no-reports') { + manifest.scripts['lint:ci'] = 'tools/vendor/bin/phpstan analyse src --level=max --no-progress --error-format=github'; + } else { + manifest.scripts['lint:ci'] = 'tools/vendor/bin/phpstan analyse src --level=max --no-progress --error-format=checkstyle > "$CI_REPORTS_DIR/phpstan-checkstyle.xml"'; } if (process.env.SCENARIO === 'failure') { const source = '.test-php-lint/src/Sample.php'; @@ -61,60 +65,17 @@ jobs: with: script: | const assert = require('node:assert/strict'); - const fs = require('node:fs'); - assert.equal(process.env.OUTCOME, process.env.SCENARIO === 'failure' ? 'failure' : 'success'); - if (process.env.SCENARIO === 'no-reports') { - assert.equal(process.env.ARTIFACT_ID, ''); - return; - } + assert.equal(process.env.OUTCOME, ['failure','no-reports'].includes(process.env.SCENARIO) ? 'failure' : 'success'); assert.match(process.env.ARTIFACT_ID, /^\d+$/); - 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, / phpstan-checkstyle.xml' - - name: Act - Publish an individual lint report - uses: $/actions/lint - with: - working-directory: tests/php-project - comment: "true" - - name: Assert - One lint comment with collapsed details - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const assert = require('node:assert/strict'); - const pr = context.payload.pull_request; - if (context.eventName !== 'pull_request' || pr.head.repo.full_name !== `${context.repo.owner}/${context.repo.repo}`) return; - const comments = await github.paginate(github.rest.issues.listComments, {...context.repo, issue_number: pr.number, per_page: 100}); - const reports = comments.filter(comment => comment.user.login === 'github-actions[bot]' && comment.body.startsWith('PHP lint results\n')); - assert.equal(reports.length, 1); - assert.match(reports[0].body, /
/); - assert.match(reports[0].body, /0 errors/); + discard-fixture: ${{ inputs.scenario != 'success' }} diff --git a/.github/workflows/__test-action-package-test.yml b/.github/workflows/__test-action-package-test.yml index 6d4287b..8132641 100644 --- a/.github/workflows/__test-action-package-test.yml +++ b/.github/workflows/__test-action-package-test.yml @@ -18,7 +18,7 @@ jobs: - failing-command - mutated-archive steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: $/actions/setup-php diff --git a/.github/workflows/__test-action-setup-php.yml b/.github/workflows/__test-action-setup-php.yml index e1d14e3..0fffb3f 100644 --- a/.github/workflows/__test-action-setup-php.yml +++ b/.github/workflows/__test-action-setup-php.yml @@ -8,7 +8,7 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: Arrange - Copy a project without a lockfile diff --git a/.github/workflows/__test-action-test.yml b/.github/workflows/__test-action-test.yml index 8965c7b..000ea6e 100644 --- a/.github/workflows/__test-action-test.yml +++ b/.github/workflows/__test-action-test.yml @@ -12,17 +12,19 @@ jobs: name: Test (${{ inputs.scenario }}) runs-on: ubuntu-latest permissions: + actions: read contents: read outputs: report-artifact-id: ${{ steps.tests.outputs.report-artifact-id }} expected-reports: ${{ steps.assert.outputs.expected-reports }} steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} - name: Arrange - Project test script id: fixture - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: SCENARIO: ${{ inputs.scenario }} with: @@ -36,17 +38,17 @@ jobs: const scenario = process.env.SCENARIO; if (scenario === 'preparation') { await fs.writeFile(path.join(directory, 'prepare.php'), ''); + file_put_contents(getenv('CI_REPORTS_DIR') . '/junit.xml', ''); `); manifest.scripts['test:ci'] = '@php custom.php'; } if (scenario === 'failing-command') { - manifest.scripts['test:ci'] = ['@test --log-junit=junit.xml --no-coverage', "@php -r 'exit(7);'"]; + manifest.scripts['test:ci'] = ['phpunit --log-junit="$CI_REPORTS_DIR/junit.xml" --no-coverage', "@php -r 'exit(7);'"]; } if (scenario === 'failing-tests') { const test = path.join(directory, 'tests/SampleTest.php'); @@ -67,16 +69,16 @@ jobs: uses: $/actions/test with: working-directory: ${{ steps.fixture.outputs.directory }} - coverage: ${{ (inputs.scenario == 'reports' || inputs.scenario == 'failing-tests') && 'github' || '' }} + coverage: ${{ (inputs.scenario == 'reports' || inputs.scenario == 'failing-tests') && 'true' || 'false' }} - name: Assert - Reports and project preparation id: assert - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: DIRECTORY: ${{ steps.fixture.outputs.directory }} OUTCOME: ${{ steps.tests.outcome }} SCENARIO: ${{ inputs.scenario }} ARTIFACT_ID: ${{ steps.tests.outputs.report-artifact-id }} - COVERAGE: ${{ (inputs.scenario == 'reports' || inputs.scenario == 'failing-tests') && 'github' || '' }} + COVERAGE: ${{ (inputs.scenario == 'reports' || inputs.scenario == 'failing-tests') && 'true' || 'false' }} with: script: |- const assert = require('node:assert/strict'); @@ -84,24 +86,11 @@ jobs: const path = require('node:path'); const directory = process.env.DIRECTORY; const scenario = process.env.SCENARIO; - assert.equal(process.env.OUTCOME, scenario.startsWith('failing-') ? 'failure' : 'success'); - if (scenario === 'no-reports') { - assert.equal(process.env.ARTIFACT_ID, ''); - return; - } + assert.equal(process.env.OUTCOME, (scenario.startsWith('failing-') || scenario === 'no-reports') ? 'failure' : 'success'); assert.match(process.env.ARTIFACT_ID, /^\d+$/); - 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, /]*\bline-rate=/); - } else { - assert.equal(fs.existsSync(cobertura), false, 'Only the Composer script controls report generation.'); - } + const files = scenario === 'no-reports' ? [] : ['junit.xml']; + if (process.env.COVERAGE === 'true') files.push('cobertura.xml'); + core.setOutput('expected-reports', Object.fromEntries(files.map(name => [name, null]))); if (scenario === 'preparation') { assert.equal(fs.readFileSync(path.join(directory, 'prepared.txt'), 'utf8'), 'ready'); } @@ -110,42 +99,9 @@ jobs: needs: test if: needs.test.outputs.report-artifact-id != '' uses: $/.github/workflows/__assert-report-artifact.yml + permissions: + actions: read 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 - pull-requests: write - steps: - - name: Arrange - Checkout - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - name: Arrange - Install the Composer fixture - uses: $/actions/setup-php - with: - working-directory: tests/php-project - composer-directories: '["."]' - - name: Act - Publish an individual report - uses: $/actions/test - with: - working-directory: tests/php-project - comment: "true" - - name: Assert - One comment with collapsed test and coverage details - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const assert = require('node:assert/strict'); - const pr = context.payload.pull_request; - if (context.eventName !== 'pull_request' || pr.head.repo.full_name !== `${context.repo.owner}/${context.repo.repo}`) return; - const comments = await github.paginate(github.rest.issues.listComments, {...context.repo, issue_number: pr.number, per_page: 100}); - const reports = comments.filter(comment => comment.user.login === 'github-actions[bot]' && comment.body.startsWith('PHP test results\n')); - assert.equal(reports.length, 1); - assert.match(reports[0].body, /
/); - assert.match(reports[0].body, /Test Results/); - assert.match(reports[0].body, /1 passed · 0 failed · 0 skipped/); - assert.match(reports[0].body, /Coverage/); + discard-fixture: ${{ startsWith(inputs.scenario, 'failing-') || inputs.scenario == 'no-reports' }} diff --git a/.github/workflows/__test-workflow-continuous-integration.yml b/.github/workflows/__test-workflow-continuous-integration.yml index 61e8023..b8bd564 100644 --- a/.github/workflows/__test-workflow-continuous-integration.yml +++ b/.github/workflows/__test-workflow-continuous-integration.yml @@ -7,11 +7,13 @@ jobs: name: Assert - Package configuration runs-on: ubuntu-latest permissions: + actions: read contents: read steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | @@ -58,11 +60,13 @@ jobs: name: Assert - Lint and test configuration runs-on: ubuntu-latest permissions: + actions: read contents: read steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | @@ -70,28 +74,28 @@ jobs: const fs = require('node:fs'); const workflow = fs.readFileSync('.github/workflows/continuous-integration.yml', 'utf8'); const step = workflow.split(' - id: config\n')[1]?.split('\n dependency-review:')[0]; - const script = step?.split(' script: |-\n')[1]?.replace(/^ {12}/gm, ''); + const script = step?.split(/ script: \|[-+]?\n/)[1]?.replace(/^ {12}/gm, ''); assert.ok(script, 'Configuration script must exist'); const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; const configure = new AsyncFunction('core', 'process', script); async function parse(env = {}) { const outputs = {}; await configure({setOutput: (key, value) => { outputs[key] = value; }}, { - env: {VERSIONS: '', LINT: 'true', TEST: 'true', ...env} + env: {VERSIONS: '', LINT: 'true', TEST: 'true', DIRECTORY: '.', CHECKS: 'true', ...env} }); return {...outputs, lint: JSON.parse(outputs.lint), test: JSON.parse(outputs.test)}; } const defaults = await parse(); - assert.deepEqual(defaults.lint, {command: 'lint:ci'}); + assert.deepEqual(defaults.lint, {command: 'lint:ci', 'lint-results': '*-checkstyle.xml'}); assert.equal((await parse({LINT: '{"command":"lint:custom"}'})).lint.command, 'lint:custom'); - assert.deepEqual(defaults.test, {command: 'test:ci', coverage: 'github', cache: ''}); + assert.deepEqual(defaults.test, {command: 'test:ci', coverage: true, cache: '', 'test-results': 'junit.xml', 'test-coverage': 'cobertura.xml'}); for (const value of ['', 'false', 'null']) { const config = await parse({LINT: value, TEST: value}); assert.equal(config.lint, null); assert.equal(config.test, null); } - const configured = await parse({TEST: '{"command":"test:custom","coverage":"","cache":".cache"}', VERSIONS: '["8.2", "8.5"]'}); - assert.deepEqual(configured.test, {command: 'test:custom', coverage: '', cache: '.cache'}); + const configured = await parse({TEST: '{"command":"test:custom","coverage":false,"cache":".cache"}', VERSIONS: '["8.2", "8.5"]'}); + assert.deepEqual(configured.test, {command: 'test:custom', coverage: false, cache: '.cache', 'test-results': 'junit.xml', 'test-coverage': 'cobertura.xml'}); assert.equal(configured['primary-version'], '8.5'); assert.equal((await parse({TEST: 'test:custom'})).test.command, 'test:custom'); for (const name of ['LINT', 'TEST']) { @@ -99,29 +103,37 @@ jobs: await assert.rejects(() => parse({[name]: value}), undefined, name + '=' + value); } } - for (const test of [{coverage: false}, {coverage: 'unknown'}, {cache: '../vendor'}, {cache: '/tmp'}, {cache: '.'}]) { + for (const test of [{coverage: 'false'}, {coverage: 'unknown'}, {cache: '../vendor'}, {cache: '/tmp'}, {cache: '.'}]) { await assert.rejects(() => parse({TEST: JSON.stringify(test)})); } for (const versions of ['[]', '["8.2","8.2"]', '[8.2]', '["latest"]']) { await assert.rejects(() => parse({VERSIONS: versions})); } + const native = {coverage: true, 'test-coverage': 'custom.xml'}; + const nativeConfig = await parse({TEST: JSON.stringify(native)}); + for (const [key, value] of Object.entries(native)) assert.deepEqual(nativeConfig.test[key], value); + for (const invalid of [{'test-coverage': {}}, {'report-plan': 'obsolete'}]) { + await assert.rejects(() => parse({TEST: JSON.stringify(invalid)})); + } core.info('Lint/test configuration checks passed.'); act: name: Act - Validate Composer project uses: $/.github/workflows/continuous-integration.yml permissions: + actions: read contents: read id-token: write with: working-directory: tests/php-project - test: '{"cache":".phpunit.cache"}' + test: '{"cache":".phpunit.cache","coverage":true}' runs-on: '["ubuntu-24.04"]' dependency-review: false checks-disabled: name: Act - Disable checks uses: $/.github/workflows/continuous-integration.yml permissions: + actions: read contents: read id-token: write with: diff --git a/.github/workflows/continuous-integration.md b/.github/workflows/continuous-integration.md index b2116b4..e4d1689 100644 --- a/.github/workflows/continuous-integration.md +++ b/.github/workflows/continuous-integration.md @@ -3,7 +3,7 @@ # GitHub Reusable Workflow: Continuous integration
- Continuous integration + Continuous integration
--- @@ -24,7 +24,6 @@ jobs: uses: hoverkraft-tech/ci-github-php/.github/workflows/continuous-integration.yml@ permissions: contents: read - id-token: write ``` Define `lint:ci` and `test:ci` in `composer.json`. These are explicit project commands; @@ -45,7 +44,7 @@ Discovery runs in its own container without changing the runner's PHP installati It tests the newest compatible patch of every matching minor, including end-of-life versions still allowed by the project. Prereleases are excluded. Missing or invalid constraints and release-catalog failures stop discovery instead of choosing an arbitrary runtime. -The highest discovered version runs lint and package checks and publishes coverage. +The highest discovered version runs lint and package checks and contributes coverage. Set `php-versions` explicitly to override the matrix, for example `'["8.2", "8.5"]'`. The last explicit entry is primary; an empty entry delegates to the setup action, which honors `.php-version` and Composer platform overrides before automatic discovery. @@ -68,104 +67,18 @@ For custom jobs, call `actions/setup-php` after checkout, then the individual lint or test actions. `install-dependencies: false` prepares the runtime without installing the project, for example before isolated package checks. -### Reports and coverage +### Report artifacts -The lint and test actions reuse `ci-github-common/actions/quality/parse-ci-reports` for -GitHub annotations and job summaries. The test action runs your Composer script unchanged. The script selects its test tool, -preparation, configuration and report formats. For PHPUnit, keep the everyday test -command and add a CI script: +Composer scripts write into the fresh CI_REPORTS_DIR and honor CI_TEST_COVERAGE. +Tests default to junit.xml plus cobertura.xml. Configure test-results, +test-coverage and lint-results for other native paths. The lint and test actions +validate these outputs and upload report artifacts, including after command failure. +Missing or malformed required reports fail the action. +The highest configured runtime collects coverage; all runtimes retain test results. +Producer calls require contents: read and actions: read. -```json -{ - "scripts": { - "test": "phpunit --configuration tests/phpunit.xml", - "test:ci": "@test --log-junit=junit.xml --coverage-cobertura=cobertura.xml" - } -} -``` - -The action sets `CI=true` and adds no test-runner arguments. JUnit reports are -parsed even after the command fails. The same Composer command runs on every PHP -version; only the last version publishes coverage. The `coverage` option controls -publication, not collection. Set it to an empty string to skip coverage publication; -omit coverage arguments from your script when collection is not needed. - -For Codecov, use `--coverage-clover=clover.xml` in the script and configure: - -```yaml -with: - test: '{"coverage":"codecov"}' -``` - -Codecov requires `id-token: write` and repository access. The action discovers -Clover reports, falling back to Cobertura. For GitHub coverage summaries, generate -Cobertura. Add generated report files to `.gitignore`. Clean any retained report -files in your project command if it reuses an existing workspace. - -The lint and test actions upload only parsed native reports, including after a -failed command, and retain them for seven days. Their `report-artifact-id` -output identifies the artifact; it is empty when no supported reports were -found. Test artifacts include coverage only with `coverage: github`. -Codecov upload remains separate. Console-only lint output creates no artifact; -configure a supported file report such as PHPStan Checkstyle for consolidation. - -Individual comments are disabled by default, keeping producer jobs read-only. -When calling an action directly, set `comment: true` and grant -`pull-requests: write` to opt in. Human and bot actors follow the same rules; -fork PRs keep summaries, annotations and artifacts without commenting. - -For custom producer jobs named `lint` and `test`, leave individual comments -disabled and add one final job using the common reporting workflow: - -```yaml -reports: - needs: [lint, test] - if: always() - uses: hoverkraft-tech/ci-github-common/.github/workflows/ci-reports.yml@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 - permissions: - contents: read - pull-requests: write - with: - job-results: ${{ toJSON(needs) }} -``` - -This updates one comment each for tests, coverage and lint, with details -collapsed. Keep producer job IDs aligned with the shared reporter's contract; -when wrapping producers in reusable workflows, use matching caller and inner -job IDs. The full CI workflow uses inner `lint` and `test` jobs; use the -individual actions when you need to compose them with this final reporter. -Keep producer jobs as required checks: report publication does not replace them. - -Preparation belongs in the Composer script, with report arguments attached only -to the test command: - -```json -{ - "scripts": { - "test:ci": [ - "@test:load-fixtures", - "@test --log-junit=junit.xml --coverage-clover=clover.xml" - ] - } -} -``` - -Pest and Codeception projects use the same contract; define their commands and -report options in Composer. No test-runner selection is needed in the action. -Use `command` for a script name other than `test:ci`. Group custom settings in one -input, omitting fields that use defaults: - -```yaml -with: - test: '{"coverage":"codecov","cache":".cache"}' -``` - -The test `cache` option can retain a directory of generated test fixtures or results. Do not -cache `vendor`; Composer installation manages dependencies. - -Dependency review runs only on pull requests. PHP CodeQL analysis is not part of -the workflow because PHP is not a supported CodeQL language. Run your PHP static -analyzer through the lint script. +The caller publishes those artifacts once with `publish-ci-reports.yml`. +See the [common reporting guide](https://github.com/hoverkraft-tech/ci-github-common/blob/44d42ca06b9f722d8ab79af4f588f30ad1e16bc5/docs/usage/ci-reports.md#consumer-workflow). ### Generated application files and documentation @@ -216,8 +129,8 @@ responsible for compatibility across every supported PHP version. Release caller ### Permissions +- **`actions`**: `read` - **`contents`**: `read` -- **`id-token`**: `write` @@ -235,8 +148,8 @@ jobs: continuous-integration: uses: hoverkraft-tech/ci-github-php/.github/workflows/continuous-integration.yml@9fc3d4e8925f8c6d87f1d46bd6b695ef75cb0f0a # 2.0.4 permissions: + actions: read contents: read - id-token: write with: # JSON array of Linux runner labels. Applies to every job, including the configuration job. # Default: `["ubuntu-latest"]` @@ -250,7 +163,7 @@ jobs: # Default: `.` working-directory: . - # Optional JSON array overriding Composer-based PHP discovery. Empty discovers the newest stable compatible patch per minor. The last version runs lint/package checks and publishes coverage. An empty entry uses the setup action default. + # Optional JSON array overriding Composer-based PHP discovery. Empty discovers the newest stable compatible patch per minor. The last version runs lint/package checks and contributes coverage. An empty entry uses the setup action default. php-versions: "" # PHP extensions forwarded to setup-php. @@ -272,14 +185,7 @@ jobs: # Default: `true` lint: "true" - # Run the Composer `test:ci` script unchanged, or provide another script name. - # Pass "false", "null" or an empty string to disable tests. - # A JSON object groups test options: `command` (default `test:ci`), - # `coverage` (`github`, `codecov` or empty), and `cache` (one directory relative to working-directory). - # Configure report/coverage generation in the Composer script itself. - # Coverage is published on the last PHP version only; the command controls collection on every version. Codecov requires id-token: write. - # Example: `{"coverage":"codecov","cache":".cache"}`. - # + # true for defaults, a Composer script, or JSON options (command, coverage boolean, test-results paths, test-coverage paths, cache). false, null or empty disables tests. Only the primary runtime contributes coverage. # Default: `true` test: "true" @@ -305,31 +211,25 @@ jobs: ### Workflow Call Inputs -| **Input** | **Description** | **Required** | **Type** | **Default** | -| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------ | ----------- | ------------------------------------------------ | -| **`runs-on`** | JSON array of Linux runner labels. Applies to every job, including the configuration job. | **false** | **string** | `["ubuntu-latest"]` | -| **`checks`** | Enable lint, tests, dependency review and optional distribution checks. | **false** | **boolean** | `true` | -| **`working-directory`** | Composer project directory relative to the checkout. | **false** | **string** | `.` | -| **`php-versions`** | Optional JSON array overriding Composer-based PHP discovery. Empty discovers the newest stable compatible patch per minor. The last version runs lint/package checks and publishes coverage. An empty entry uses the setup action default. | **false** | **string** | - | -| **`extensions`** | PHP extensions forwarded to setup-php. | **false** | **string** | `mbstring, dom, xml, xmlwriter, curl, zip, intl` | -| **`composer-directories`** | Optional JSON array of Composer directories relative to working-directory. Empty installs the root project and tools/composer.json when present, without recursive discovery. | **false** | **string** | - | -| **`ignore-scripts`** | Disable Composer installation scripts. Explicit project commands still run. | **false** | **boolean** | `true` | -| **`ignore-plugins`** | Disable Composer plugins during installation. When false, Composer allow-plugins configuration still applies. | **false** | **boolean** | `true` | -| **`lint`** | Composer lint script name or a JSON object with `command` (default `lint:ci`). Pass "false", "null" or an empty string to disable. | **false** | **string** | `true` | -| **`test`** | Run the Composer `test:ci` script unchanged, or provide another script name. | **false** | **string** | `true` | -| | Pass "false", "null" or an empty string to disable tests. | | | | -| | A JSON object groups test options: `command` (default `test:ci`), | | | | -| | `coverage` (`github`, `codecov` or empty), and `cache` (one directory relative to working-directory). | | | | -| | Configure report/coverage generation in the Composer script itself. | | | | -| | Coverage is published on the last PHP version only; the command controls collection on every version. Codecov requires id-token: write. | | | | -| | Example: `{"coverage":"codecov","cache":".cache"}`. | | | | -| **`package`** | Validate a public Composer source distribution from the Git repository root. | **false** | **string** | `false` | -| | Pass "false" (the default) to disable, "true" for archive and autoload checks, | | | | -| | or a JSON object with `tests` for additional commands in an isolated Composer consumer. | | | | -| | Quote booleans because this input has type string. Example: `{"tests":"my-cli --help"}`. | | | | -| | vendor/bin is on PATH; PACKAGE_NAME, PACKAGE_INSTALL_PATH and PACKAGE_ARCHIVE_PATH identify the package. | | | | -| | Unknown options and non-string tests are rejected before distribution checks. | | | | -| **`dependency-review`** | Review dependency changes on pull requests. | **false** | **boolean** | `true` | +| **Input** | **Description** | **Required** | **Type** | **Default** | +| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------- | ------------------------------------------------ | +| **`runs-on`** | JSON array of Linux runner labels. Applies to every job, including the configuration job. | **false** | **string** | `["ubuntu-latest"]` | +| **`checks`** | Enable lint, tests, dependency review and optional distribution checks. | **false** | **boolean** | `true` | +| **`working-directory`** | Composer project directory relative to the checkout. | **false** | **string** | `.` | +| **`php-versions`** | Optional JSON array overriding Composer-based PHP discovery. Empty discovers the newest stable compatible patch per minor. The last version runs lint/package checks and contributes coverage. An empty entry uses the setup action default. | **false** | **string** | - | +| **`extensions`** | PHP extensions forwarded to setup-php. | **false** | **string** | `mbstring, dom, xml, xmlwriter, curl, zip, intl` | +| **`composer-directories`** | Optional JSON array of Composer directories relative to working-directory. Empty installs the root project and tools/composer.json when present, without recursive discovery. | **false** | **string** | - | +| **`ignore-scripts`** | Disable Composer installation scripts. Explicit project commands still run. | **false** | **boolean** | `true` | +| **`ignore-plugins`** | Disable Composer plugins during installation. When false, Composer allow-plugins configuration still applies. | **false** | **boolean** | `true` | +| **`lint`** | Composer lint script name or a JSON object with `command` (default `lint:ci`). Pass "false", "null" or an empty string to disable. | **false** | **string** | `true` | +| **`test`** | true for defaults, a Composer script, or JSON options (command, coverage boolean, test-results paths, test-coverage paths, cache). false, null or empty disables tests. Only the primary runtime contributes coverage. | **false** | **string** | `true` | +| **`package`** | Validate a public Composer source distribution from the Git repository root. | **false** | **string** | `false` | +| | Pass "false" (the default) to disable, "true" for archive and autoload checks, | | | | +| | or a JSON object with `tests` for additional commands in an isolated Composer consumer. | | | | +| | Quote booleans because this input has type string. Example: `{"tests":"my-cli --help"}`. | | | | +| | vendor/bin is on PATH; PACKAGE_NAME, PACKAGE_INSTALL_PATH and PACKAGE_ARCHIVE_PATH identify the package. | | | | +| | Unknown options and non-string tests are rejected before distribution checks. | | | | +| **`dependency-review`** | Review dependency changes on pull requests. | **false** | **boolean** | `true` | diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 0f95328..da6330c 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -9,7 +9,6 @@ # uses: hoverkraft-tech/ci-github-php/.github/workflows/continuous-integration.yml@ # permissions: # contents: read -# id-token: write # ``` # # Define `lint:ci` and `test:ci` in `composer.json`. These are explicit project commands; @@ -30,7 +29,7 @@ # It tests the newest compatible patch of every matching minor, including end-of-life # versions still allowed by the project. Prereleases are excluded. Missing or invalid # constraints and release-catalog failures stop discovery instead of choosing an arbitrary runtime. -# The highest discovered version runs lint and package checks and publishes coverage. +# The highest discovered version runs lint and package checks and contributes coverage. # Set `php-versions` explicitly to override the matrix, for example `'["8.2", "8.5"]'`. # The last explicit entry is primary; an empty entry delegates to the setup action, # which honors `.php-version` and Composer platform overrides before automatic discovery. @@ -53,104 +52,18 @@ # lint or test actions. `install-dependencies: false` prepares the runtime # without installing the project, for example before isolated package checks. # -# ### Reports and coverage +# ### Report artifacts # -# The lint and test actions reuse `ci-github-common/actions/quality/parse-ci-reports` for -# GitHub annotations and job summaries. The test action runs your Composer script unchanged. The script selects its test tool, -# preparation, configuration and report formats. For PHPUnit, keep the everyday test -# command and add a CI script: +# Composer scripts write into the fresh CI_REPORTS_DIR and honor CI_TEST_COVERAGE. +# Tests default to junit.xml plus cobertura.xml. Configure test-results, +# test-coverage and lint-results for other native paths. The lint and test actions +# validate these outputs and upload report artifacts, including after command failure. +# Missing or malformed required reports fail the action. +# The highest configured runtime collects coverage; all runtimes retain test results. +# Producer calls require contents: read and actions: read. # -# ```json -# { -# "scripts": { -# "test": "phpunit --configuration tests/phpunit.xml", -# "test:ci": "@test --log-junit=junit.xml --coverage-cobertura=cobertura.xml" -# } -# } -# ``` -# -# The action sets `CI=true` and adds no test-runner arguments. JUnit reports are -# parsed even after the command fails. The same Composer command runs on every PHP -# version; only the last version publishes coverage. The `coverage` option controls -# publication, not collection. Set it to an empty string to skip coverage publication; -# omit coverage arguments from your script when collection is not needed. -# -# For Codecov, use `--coverage-clover=clover.xml` in the script and configure: -# -# ```yaml -# with: -# test: '{"coverage":"codecov"}' -# ``` -# -# Codecov requires `id-token: write` and repository access. The action discovers -# Clover reports, falling back to Cobertura. For GitHub coverage summaries, generate -# Cobertura. Add generated report files to `.gitignore`. Clean any retained report -# files in your project command if it reuses an existing workspace. -# -# The lint and test actions upload only parsed native reports, including after a -# failed command, and retain them for seven days. Their `report-artifact-id` -# output identifies the artifact; it is empty when no supported reports were -# found. Test artifacts include coverage only with `coverage: github`. -# Codecov upload remains separate. Console-only lint output creates no artifact; -# configure a supported file report such as PHPStan Checkstyle for consolidation. -# -# Individual comments are disabled by default, keeping producer jobs read-only. -# When calling an action directly, set `comment: true` and grant -# `pull-requests: write` to opt in. Human and bot actors follow the same rules; -# fork PRs keep summaries, annotations and artifacts without commenting. -# -# For custom producer jobs named `lint` and `test`, leave individual comments -# disabled and add one final job using the common reporting workflow: -# -# ```yaml -# reports: -# needs: [lint, test] -# if: always() -# uses: hoverkraft-tech/ci-github-common/.github/workflows/ci-reports.yml@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 -# permissions: -# contents: read -# pull-requests: write -# with: -# job-results: ${{ toJSON(needs) }} -# ``` -# -# This updates one comment each for tests, coverage and lint, with details -# collapsed. Keep producer job IDs aligned with the shared reporter's contract; -# when wrapping producers in reusable workflows, use matching caller and inner -# job IDs. The full CI workflow uses inner `lint` and `test` jobs; use the -# individual actions when you need to compose them with this final reporter. -# Keep producer jobs as required checks: report publication does not replace them. -# -# Preparation belongs in the Composer script, with report arguments attached only -# to the test command: -# -# ```json -# { -# "scripts": { -# "test:ci": [ -# "@test:load-fixtures", -# "@test --log-junit=junit.xml --coverage-clover=clover.xml" -# ] -# } -# } -# ``` -# -# Pest and Codeception projects use the same contract; define their commands and -# report options in Composer. No test-runner selection is needed in the action. -# Use `command` for a script name other than `test:ci`. Group custom settings in one -# input, omitting fields that use defaults: -# -# ```yaml -# with: -# test: '{"coverage":"codecov","cache":".cache"}' -# ``` -# -# The test `cache` option can retain a directory of generated test fixtures or results. Do not -# cache `vendor`; Composer installation manages dependencies. -# -# Dependency review runs only on pull requests. PHP CodeQL analysis is not part of -# the workflow because PHP is not a supported CodeQL language. Run your PHP static -# analyzer through the lint script. +# The caller publishes those artifacts once with `publish-ci-reports.yml`. +# See the [common reporting guide](https://github.com/hoverkraft-tech/ci-github-common/blob/44d42ca06b9f722d8ab79af4f588f30ad1e16bc5/docs/usage/ci-reports.md#consumer-workflow). # # ### Generated application files and documentation # @@ -198,6 +111,7 @@ # # Package checks run on the primary PHP version. The source test matrix remains # responsible for compatibility across every supported PHP version. Release callers should depend on successful validation with `needs`. +# name: Continuous integration on: workflow_call: @@ -215,7 +129,7 @@ on: type: string default: . php-versions: - description: Optional JSON array overriding Composer-based PHP discovery. Empty discovers the newest stable compatible patch per minor. The last version runs lint/package checks and publishes coverage. An empty entry uses the setup action default. + description: Optional JSON array overriding Composer-based PHP discovery. Empty discovers the newest stable compatible patch per minor. The last version runs lint/package checks and contributes coverage. An empty entry uses the setup action default. type: string default: "" extensions: @@ -239,14 +153,8 @@ on: type: string default: "true" test: - description: | - Run the Composer `test:ci` script unchanged, or provide another script name. - Pass "false", "null" or an empty string to disable tests. - A JSON object groups test options: `command` (default `test:ci`), - `coverage` (`github`, `codecov` or empty), and `cache` (one directory relative to working-directory). - Configure report/coverage generation in the Composer script itself. - Coverage is published on the last PHP version only; the command controls collection on every version. Codecov requires id-token: write. - Example: `{"coverage":"codecov","cache":".cache"}`. + description: |- + true for defaults, a Composer script, or JSON options (command, coverage boolean, test-results paths, test-coverage paths, cache). false, null or empty disables tests. Only the primary runtime contributes coverage. type: string default: "true" package: @@ -268,6 +176,7 @@ jobs: configuration: runs-on: ${{ fromJSON(inputs.runs-on) }} permissions: + actions: read contents: read outputs: versions: ${{ steps.config.outputs.versions }} @@ -281,6 +190,7 @@ jobs: if: inputs.checks && inputs.php-versions == '' with: persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} - id: versions if: inputs.checks && inputs.php-versions == '' uses: $/actions/get-php-versions @@ -315,8 +225,10 @@ jobs: VERSIONS: ${{ inputs.php-versions || steps.versions.outputs.php-versions }} LINT: ${{ inputs.lint }} TEST: ${{ inputs.test }} + CHECKS: ${{ inputs.checks }} + DIRECTORY: ${{ inputs.working-directory }} with: - script: |- + script: | const versions = process.env.VERSIONS.trim() ? JSON.parse(process.env.VERSIONS) : ['']; if (!Array.isArray(versions) || !versions.length || versions.length > 20 || versions.some(version => typeof version !== 'string' || (version && !/^\d+\.\d+(?:\.\d+)?$/.test(version))) || new Set(versions).size !== versions.length) { throw new Error('php-versions must be a JSON array of unique numeric PHP versions.'); @@ -334,14 +246,13 @@ jobs: if (unknown.length) throw new Error('Unknown ' + name + ' options: ' + unknown.join(', ') + '.'); config = {...defaults, ...config}; for (const [key, option] of Object.entries(config)) { - if (typeof option !== 'string') throw new Error(name + '.' + key + ' must be a string.'); + if (Array.isArray(defaults[key]) ? !Array.isArray(option) : typeof option !== typeof defaults[key]) throw new Error(name + '.' + key + ' has the wrong type.'); } if (!config.command.trim() || config.command.startsWith('-') || /\s/.test(config.command)) throw new Error(name + '.command must name a Composer script.'); return config; } - const lint = options('lint', process.env.LINT, {command: 'lint:ci'}); - const test = options('test', process.env.TEST, {command: 'test:ci', coverage: 'github', cache: ''}); - if (test && !['', 'github', 'codecov'].includes(test.coverage)) throw new Error('test.coverage must be github, codecov or empty.'); + const lint = options('lint', process.env.LINT, {command: 'lint:ci', 'lint-results': '*-checkstyle.xml'}); + const test = options('test', process.env.TEST, {command: 'test:ci', coverage: true, cache: '', 'test-results': 'junit.xml', 'test-coverage': 'cobertura.xml'}); const cache = test?.cache; if (cache && (cache === '.' || cache.startsWith('/') || cache.includes('\\') || cache.split('/').includes('..') || /[\r\n*?]/.test(cache))) { throw new Error('test.cache must be one directory inside working-directory.'); @@ -349,27 +260,31 @@ jobs: core.setOutput('lint', JSON.stringify(lint)); core.setOutput('test', JSON.stringify(test)); core.setOutput('versions', versions); - core.setOutput('primary-version', versions.at(-1)); + core.setOutput('primary-version', [...versions].sort((a,b) => a.localeCompare(b, undefined, {numeric:true})).at(-1)); dependency-review: if: inputs.checks && github.event_name == 'pull_request' && inputs.dependency-review runs-on: ${{ fromJSON(inputs.runs-on) }} permissions: + actions: read contents: read steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - uses: actions/dependency-review-action@bbc44d14a204704ccc493733616cd1e93a0321ec + ref: ${{ github.event.pull_request.head.sha || github.sha }} + - uses: actions/dependency-review-action@bbc44d14a204704ccc493733616cd1e93a0321ec # v5.0.1 lint: if: inputs.checks && needs.configuration.outputs.lint != 'null' needs: configuration runs-on: ${{ fromJSON(inputs.runs-on) }} permissions: + actions: read contents: read steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} - uses: $/actions/setup-php with: working-directory: ${{ inputs.working-directory }} @@ -382,21 +297,23 @@ jobs: with: working-directory: ${{ inputs.working-directory }} command: ${{ fromJSON(needs.configuration.outputs.lint).command }} + lint-results: ${{ fromJSON(needs.configuration.outputs.lint).lint-results }} test: if: inputs.checks && needs.configuration.outputs.test != 'null' needs: configuration runs-on: ${{ fromJSON(inputs.runs-on) }} permissions: + actions: read contents: read - id-token: write strategy: fail-fast: false matrix: php-version: ${{ fromJSON(needs.configuration.outputs.versions) }} steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} - uses: $/actions/setup-php with: working-directory: ${{ inputs.working-directory }} @@ -415,17 +332,21 @@ jobs: with: working-directory: ${{ inputs.working-directory }} command: ${{ fromJSON(needs.configuration.outputs.test).command }} - coverage: ${{ matrix.php-version == needs.configuration.outputs.primary-version && fromJSON(needs.configuration.outputs.test).coverage || '' }} + test-results: ${{ fromJSON(needs.configuration.outputs.test).test-results }} + test-coverage: ${{ fromJSON(needs.configuration.outputs.test).test-coverage }} + coverage: ${{ matrix.php-version == needs.configuration.outputs.primary-version && fromJSON(needs.configuration.outputs.test).coverage && 'true' || 'false' }} package: if: inputs.checks && needs.configuration.outputs.package-enabled == 'true' needs: configuration runs-on: ${{ fromJSON(inputs.runs-on) }} permissions: + actions: read contents: read steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} - uses: $/actions/setup-php with: working-directory: ${{ inputs.working-directory }} diff --git a/.github/workflows/documentation.md b/.github/workflows/documentation.md index 3f7f3e1..2c124dc 100644 --- a/.github/workflows/documentation.md +++ b/.github/workflows/documentation.md @@ -3,7 +3,7 @@ # GitHub Reusable Workflow: Build PHP documentation
- Build PHP documentation + Build PHP documentation
--- diff --git a/.github/workflows/prepare-package-release.md b/.github/workflows/prepare-package-release.md index a51db65..2398aaf 100644 --- a/.github/workflows/prepare-package-release.md +++ b/.github/workflows/prepare-package-release.md @@ -3,7 +3,7 @@ # GitHub Reusable Workflow: Prepare Composer Package Release
- Prepare Composer Package Release + Prepare Composer Package Release
--- diff --git a/.github/workflows/release.md b/.github/workflows/release.md index 98e4013..d3e2171 100644 --- a/.github/workflows/release.md +++ b/.github/workflows/release.md @@ -3,7 +3,7 @@ # GitHub Reusable Workflow: Release Composer Package
- Release Composer Package + Release Composer Package
--- diff --git a/.gitignore b/.gitignore index b25e815..e046a4d 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ Thumbs.db # Workflow self-reference self-workflow/ + +# Local CI report staging +.cache/ diff --git a/Makefile b/Makefile index 233fab1..2bac405 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,8 @@ deps-audit: ## Audit action and fixture dependencies done test: ## Run fixture lint and Composer project tests - composer --working-dir=tests/php-project lint:ci + mkdir -p .cache/reports + CI_REPORTS_DIR="$(CURDIR)/.cache/reports" composer --working-dir=tests/php-project lint:ci @set -e; for directory in $(COMPOSER_DIRECTORIES); do \ if php -r 'exit(isset(json_decode(file_get_contents($$argv[1]), true)["scripts"]["test"]) ? 0 : 1);' "$$directory/composer.json"; then \ composer --working-dir="$$directory" test; \ diff --git a/actions/get-php-versions/README.md b/actions/get-php-versions/README.md index 41071ba..17e9d23 100644 --- a/actions/get-php-versions/README.md +++ b/actions/get-php-versions/README.md @@ -3,7 +3,7 @@ # ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItbGlzdCIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSI4IiB5MT0iNiIgeDI9IjIxIiB5Mj0iNiI+PC9saW5lPjxsaW5lIHgxPSI4IiB5MT0iMTIiIHgyPSIyMSIgeTI9IjEyIj48L2xpbmU+PGxpbmUgeDE9IjgiIHkxPSIxOCIgeDI9IjIxIiB5Mj0iMTgiPjwvbGluZT48bGluZSB4MT0iMyIgeTE9IjYiIHgyPSIzLjAxIiB5Mj0iNiI+PC9saW5lPjxsaW5lIHgxPSIzIiB5MT0iMTIiIHgyPSIzLjAxIiB5Mj0iMTIiPjwvbGluZT48bGluZSB4MT0iMyIgeTE9IjE4IiB4Mj0iMy4wMSIgeTI9IjE4Ij48L2xpbmU+PC9zdmc+) GitHub Action: Get PHP versions
- Get PHP versions + Get PHP versions
--- diff --git a/actions/get-php-versions/composer.json b/actions/get-php-versions/composer.json index 57962d1..18bb102 100644 --- a/actions/get-php-versions/composer.json +++ b/actions/get-php-versions/composer.json @@ -17,7 +17,7 @@ }, "scripts": { "test": "phpunit --bootstrap vendor/autoload.php src/PhpVersionsTest.php", - "test:ci": "@test --log-junit=junit.xml --coverage-cobertura=cobertura.xml --coverage-filter=src" + "test:ci": "if [ \"$CI_TEST_COVERAGE\" = true ]; then phpunit --bootstrap vendor/autoload.php src/PhpVersionsTest.php --coverage-filter=src --log-junit=\"$CI_REPORTS_DIR/junit.xml\" --coverage-cobertura=\"$CI_REPORTS_DIR/cobertura.xml\"; else phpunit --bootstrap vendor/autoload.php src/PhpVersionsTest.php --log-junit=\"$CI_REPORTS_DIR/junit.xml\" --no-coverage; fi" }, "config": { "sort-packages": true, diff --git a/actions/lint/README.md b/actions/lint/README.md index 045a93d..4424f48 100644 --- a/actions/lint/README.md +++ b/actions/lint/README.md @@ -1,9 +1,9 @@ -# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Lint PHP +# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItY2hlY2stc3F1YXJlIiBjb2xvcj0iYmx1ZSI+PHBvbHlsaW5lIHBvaW50cz0iOSAxMSAxMiAxNCAyMiA0Ij48L3BvbHlsaW5lPjxwYXRoIGQ9Ik0yMSAxMnY3YTIgMiAwIDAgMS0yIDJINWEyIDIgMCAwIDEtMi0yVjVhMiAyIDAgMCAxIDItMmgxMSI+PC9wYXRoPjwvc3ZnPg==) GitHub Action: Lint PHP
- Lint PHP + Lint PHP
--- @@ -13,12 +13,13 @@ ## Overview -Run a project-defined Composer lint script and report results. +Run PHP lint checks, fail on native errors and retain evidence for consolidated reporting. -Native lint reports are retained for seven days, including after command -failures. Only parsed report files are uploaded. Keep `comment: false` and -call the common `ci-reports` workflow after producer jobs for consolidated -comments with collapsed details. +Run the project's Composer script and retain validated native reports. +The script writes fresh reports under CI_REPORTS_DIR. Test scripts honor +CI_TEST_COVERAGE when selecting instrumentation. Run setup-php first. +Requires actions: read and contents: read. Call ci-reports once after all jobs; +the separate CI complete gate decides whether the whole pipeline succeeded. @@ -28,29 +29,17 @@ comments with collapsed details. ```yaml - uses: hoverkraft-tech/ci-github-php/actions/lint@9fc3d4e8925f8c6d87f1d46bd6b695ef75cb0f0a # 2.0.4 with: - # Composer project directory. Run setup-php first to install its dependencies. + # Composer project directory, with its dependencies installed. # Default: `.` working-directory: . - # Composer script to execute, normally `lint:ci` in composer.json. - # Define the tools and their configuration in that script. Examples: - # - # - PHPStan: `phpstan analyse --error-format=checkstyle > phpstan-checkstyle.xml` - # - Psalm: `psalm --output-format=checkstyle > psalm-checkstyle.xml` - # - PHP_CodeSniffer: `phpcs --report=checkstyle --report-file=phpcs-checkstyle.xml` - # - PHP CS Fixer: `php-cs-fixer check --format=checkstyle > php-cs-fixer-checkstyle.xml` - # - # Redirecting output preserves the tool's exit status. The action discovers - # Checkstyle reports for annotations and summaries. Use paths relative to the project; - # for separate tooling installations, prefix binaries with `tools/vendor/bin/`. - # See the [CI guide](../../.github/workflows/continuous-integration.md). - # + # Composer script to execute unchanged. Write native reports under CI_REPORTS_DIR. # Default: `lint:ci` command: lint:ci - # Publish an individual lint PR comment. Requires pull-requests write permission. Fork comments are disabled. Leave false for consolidated reporting; annotations, summaries and artifacts remain enabled. - # Default: `false` - comment: "false" + # Required native report paths relative to CI_REPORTS_DIR, one per line. + # Default: `*-checkstyle.xml` + lint-results: "*-checkstyle.xml" ``` @@ -58,22 +47,11 @@ comments with collapsed details. ## Inputs -| **Input** | **Description** | **Required** | **Default** | -| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------- | -| **`working-directory`** | Composer project directory. Run setup-php first to install its dependencies. | **false** | `.` | -| **`command`** | Composer script to execute, normally `lint:ci` in composer.json. | **false** | `lint:ci` | -| | Define the tools and their configuration in that script. Examples: | | | -| | | | | -| | - PHPStan: `phpstan analyse --error-format=checkstyle > phpstan-checkstyle.xml` | | | -| | - Psalm: `psalm --output-format=checkstyle > psalm-checkstyle.xml` | | | -| | - PHP_CodeSniffer: `phpcs --report=checkstyle --report-file=phpcs-checkstyle.xml` | | | -| | - PHP CS Fixer: `php-cs-fixer check --format=checkstyle > php-cs-fixer-checkstyle.xml` | | | -| | | | | -| | Redirecting output preserves the tool's exit status. The action discovers | | | -| | Checkstyle reports for annotations and summaries. Use paths relative to the project; | | | -| | for separate tooling installations, prefix binaries with `tools/vendor/bin/`. | | | -| | See the [CI guide](../../.github/workflows/continuous-integration.md). | | | -| **`comment`** | Publish an individual lint PR comment. Requires pull-requests write permission. Fork comments are disabled. Leave false for consolidated reporting; annotations, summaries and artifacts remain enabled. | **false** | `false` | +| **Input** | **Description** | **Required** | **Default** | +| ----------------------- | -------------------------------------------------------------------------------- | ------------ | ------------------- | +| **`working-directory`** | Composer project directory, with its dependencies installed. | **false** | `.` | +| **`command`** | Composer script to execute unchanged. Write native reports under CI_REPORTS_DIR. | **false** | `lint:ci` | +| **`lint-results`** | Required native report paths relative to CI_REPORTS_DIR, one per line. | **false** | `\*-checkstyle.xml` | @@ -82,44 +60,25 @@ comments with collapsed details. ## Outputs -| **Output** | **Description** | -| ------------------------ | ---------------------------------------------------------------------------- | -| **`report-artifact-id`** | Native lint report artifact ID, empty when no supported reports were parsed. | +| **Output** | **Description** | +| ------------------------ | ------------------------------------------------------------------ | +| **`report-artifact-id`** | Native result artifact ID, automatically discovered by ci-reports. | [![Marketplace](https://img.shields.io/badge/Marketplace-lint--php-blue?logo=github-actions)](https://github.com/marketplace/actions/lint-php) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-php)](https://github.com/hoverkraft-tech/ci-github-php/releases) -[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-php)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-php?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-php?style=social) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-php/blob/main/CONTRIBUTING.md) -![GitHub Verified Creator](https://img.shields.io/badge/GitHub-Verified%20Creator-4493F8?logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJyZ2IoNjgsIDE0NywgMjQ4KSI+CiAgPHBhdGggZD0ibTkuNTg1LjUyLjkyOS42OGMuMTUzLjExMi4zMzEuMTg2LjUxOC4yMTVsMS4xMzguMTc1YTIuNjc4IDIuNjc4IDAgMCAxIDIuMjQgMi4yNGwuMTc0IDEuMTM5Yy4wMjkuMTg3LjEwMy4zNjUuMjE1LjUxOGwuNjguOTI4YTIuNjc3IDIuNjc3IDAgMCAxIDAgMy4xN2wtLjY4LjkyOGExLjE3NCAxLjE3NCAwIDAgMC0uMjE1LjUxOGwtLjE3NSAxLjEzOGEyLjY3OCAyLjY3OCAwIDAgMS0yLjI0MSAyLjI0MWwtMS4xMzguMTc1YTEuMTcgMS4xNyAwIDAgMC0uNTE4LjIxNWwtLjkyOC42OGEyLjY3NyAyLjY3NyAwIDAgMS0zLjE3IDBsLS45MjgtLjY4YTEuMTc0IDEuMTc0IDAgMCAwLS41MTgtLjIxNUwzLjgzIDE0LjQxYTIuNjc4IDIuNjc4IDAgMCAxLTIuMjQtMi4yNGwtLjE3NS0xLjEzOGExLjE3IDEuMTcgMCAwIDAtLjIxNS0uNTE4bC0uNjgtLjkyOGEyLjY3NyAyLjY3NyAwIDAgMSAwLTMuMTdsLjY4LS45MjhjLjExMi0uMTUzLjE4Ni0uMzMxLjIxNS0uNTE4bC4xNzUtMS4xNGEyLjY3OCAyLjY3OCAwIDAgMSAyLjI0LTIuMjRsMS4xMzktLjE3NWMuMTg3LS4wMjkuMzY1LS4xMDMuNTE4LS4yMTVsLjkyOC0uNjhhMi42NzcgMi42NzcgMCAwIDEgMy4xNyAwWk03LjMwMyAxLjcyOGwtLjkyNy42OGEyLjY3IDIuNjcgMCAwIDEtMS4xOC40ODlsLTEuMTM3LjE3NGExLjE3OSAxLjE3OSAwIDAgMC0uOTg3Ljk4N2wtLjE3NCAxLjEzNmEyLjY3NyAyLjY3NyAwIDAgMS0uNDg5IDEuMThsLS42OC45MjhhMS4xOCAxLjE4IDAgMCAwIDAgMS4zOTRsLjY4LjkyN2MuMjU2LjM0OC40MjQuNzUzLjQ4OSAxLjE4bC4xNzQgMS4xMzdjLjA3OC41MDkuNDc4LjkwOS45ODcuOTg3bDEuMTM2LjE3NGEyLjY3IDIuNjcgMCAwIDEgMS4xOC40ODlsLjkyOC42OGMuNDE0LjMwNS45NzkuMzA1IDEuMzk0IDBsLjkyNy0uNjhhMi42NyAyLjY3IDAgMCAxIDEuMTgtLjQ4OWwxLjEzNy0uMTc0YTEuMTggMS4xOCAwIDAgMCAuOTg3LS45ODdsLjE3NC0xLjEzNmEyLjY3IDIuNjcgMCAwIDEgLjQ4OS0xLjE4bC42OC0uOTI4YTEuMTc2IDEuMTc2IDAgMCAwIDAtMS4zOTRsLS42OC0uOTI3YTIuNjg2IDIuNjg2IDAgMCAxLS40ODktMS4xOGwtLjE3NC0xLjEzN2ExLjE3OSAxLjE3OSAwIDAgMC0uOTg3LS45ODdsLTEuMTM2LS4xNzRhMi42NzcgMi42NzcgMCAwIDEtMS4xOC0uNDg5bC0uOTI4LS42OGExLjE3NiAxLjE3NiAwIDAgMC0xLjM5NCAwWk0xMS4yOCA2Ljc4bC0zLjc1IDMuNzVhLjc1Ljc1IDAgMCAxLTEuMDYgMEw0LjcyIDguNzhhLjc1MS43NTEgMCAwIDEgLjAxOC0xLjA0Mi43NTEuNzUxIDAgMCAxIDEuMDQyLS4wMThMNyA4Ljk0bDMuMjItMy4yMmEuNzUxLjc1MSAwIDAgMSAxLjA0Mi4wMTguNzUxLjc1MSAwIDAgMSAuMDE4IDEuMDQyWiI+PC9wYXRoPgo8L3N2Zz4K) - -## Contributing - -Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-php/blob/main/CONTRIBUTING.md) for more details. - - -## License - -This project is licensed under the MIT License. - -SPDX-License-Identifier: MIT - -Copyright © 2026 hoverkraft - -For more details, see the [license](http://choosealicense.com/licenses/mit/). - diff --git a/actions/lint/action.yml b/actions/lint/action.yml index 4157f1c..ec7b940 100644 --- a/actions/lint/action.yml +++ b/actions/lint/action.yml @@ -1,41 +1,31 @@ +# Run the project's Composer script and retain validated native reports. +# The script writes fresh reports under CI_REPORTS_DIR. Test scripts honor +# CI_TEST_COVERAGE when selecting instrumentation. Run setup-php first. +# Requires actions: read and contents: read. Call ci-reports once after all jobs; +# the separate CI complete gate decides whether the whole pipeline succeeded. name: Lint PHP -description: | - Run a project-defined Composer lint script and report results. - - Native lint reports are retained for seven days, including after command - failures. Only parsed report files are uploaded. Keep `comment: false` and - call the common `ci-reports` workflow after producer jobs for consolidated - comments with collapsed details. +description: Run PHP lint checks, fail on native errors and retain evidence for + consolidated reporting. author: hoverkraft branding: - icon: package + icon: check-square color: blue inputs: working-directory: - description: Composer project directory. Run setup-php first to install its dependencies. + description: Composer project directory, with its dependencies installed. default: . command: - description: | - Composer script to execute, normally `lint:ci` in composer.json. - Define the tools and their configuration in that script. Examples: - - - PHPStan: `phpstan analyse --error-format=checkstyle > phpstan-checkstyle.xml` - - Psalm: `psalm --output-format=checkstyle > psalm-checkstyle.xml` - - PHP_CodeSniffer: `phpcs --report=checkstyle --report-file=phpcs-checkstyle.xml` - - PHP CS Fixer: `php-cs-fixer check --format=checkstyle > php-cs-fixer-checkstyle.xml` - - Redirecting output preserves the tool's exit status. The action discovers - Checkstyle reports for annotations and summaries. Use paths relative to the project; - for separate tooling installations, prefix binaries with `tools/vendor/bin/`. - See the [CI guide](../../.github/workflows/continuous-integration.md). + description: + Composer script to execute unchanged. Write native reports under + CI_REPORTS_DIR. default: lint:ci - comment: - description: Publish an individual lint PR comment. Requires pull-requests write permission. Fork comments are disabled. Leave false for consolidated reporting; annotations, summaries and artifacts remain enabled. - default: "false" + lint-results: + description: Required native report paths relative to CI_REPORTS_DIR, one per line. + default: "*-checkstyle.xml" outputs: report-artifact-id: - description: Native lint report artifact ID, empty when no supported reports were parsed. - value: ${{ steps.upload-reports.outputs.artifact-id }} + description: Native result artifact ID, automatically discovered by ci-reports. + value: ${{ steps.reports.outputs.artifact-id }} runs: using: composite steps: @@ -43,50 +33,49 @@ runs: uses: hoverkraft-tech/ci-github-common/actions/working-directory@f165c0ca3e88604611481e1408ace1e0e3a5ee47 # 4.3.1 with: working-directory: ${{ inputs.working-directory }} - - id: run + - id: definition uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: - WORKING_DIRECTORY: ${{ steps.directory.outputs.absolute-path }} + PROJECT: ${{ steps.directory.outputs.workspace-relative-path || '.' }} COMMAND: ${{ inputs.command }} + RESULTS: ${{ inputs.lint-results }} with: - script: |- + script: | const command = process.env.COMMAND.trim(); - if (!command || command.startsWith('-')) throw new Error('command must name a Composer script.'); - await exec.exec('composer', ['--no-interaction', 'run-script', '--timeout=0', command], { - cwd: process.env.WORKING_DIRECTORY, - }); - - name: Report lint results - id: reports - if: ${{ !cancelled() && steps.directory.outcome == 'success' }} - uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@f165c0ca3e88604611481e1408ace1e0e3a5ee47 # 4.3.1 - with: - working-directory: ${{ steps.directory.outputs.absolute-path }} - report-paths: auto:lint - report-name: PHP lint - output-format: annotations,summary,markdown - - name: Publish individual report comment - if: ${{ !cancelled() && inputs.comment == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && steps.reports.outputs.lint-markdown != '' }} - uses: hoverkraft-tech/ci-github-common/actions/create-or-update-comment@f165c0ca3e88604611481e1408ace1e0e3a5ee47 # 4.3.1 + if (!command || command.startsWith('-') || /\s/.test(command)) throw new Error('command must name a Composer script.'); + const paths = value => { + const result = value.split(/\r?\n/).map(item => item.trim()).filter(Boolean); + if (!result.length) throw new Error('Required report paths must not be empty.'); + return result; + }; + const reports = paths(process.env.RESULTS).map(pattern => ({kind:'lint',pattern})); + const runtime = await exec.getExecOutput('php', ['-r', 'echo PHP_VERSION;'], {silent:true}); + core.setOutput('definition', {name:'PHP lint checks',project:process.env.PROJECT,variant:{runtime:runtime.stdout.trim()},reports}); + - id: prepare + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: - title: PHP lint results - body: ${{ steps.reports.outputs.lint-markdown }} - - name: Prepare native report artifact - id: report-artifact - if: ${{ !cancelled() && steps.reports.outputs.parsed-files != '' }} + script: | + const fs = require('node:fs'); + const path = require('node:path'); + core.setOutput('report-directory', fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, 'ci-reports-'))); + core.setOutput('definition', process.env.REPORT_DEFINITION); + env: + REPORT_DEFINITION: ${{ steps.definition.outputs.definition }} + - id: run uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: - REPORT_FILES: ${{ steps.reports.outputs.parsed-files }} + WORKING_DIRECTORY: ${{ steps.directory.outputs.absolute-path }} + COMMAND: ${{ inputs.command }} + CI_REPORTS_DIR: ${{ steps.prepare.outputs.report-directory }} + CI: "true" with: script: | - core.setOutput('files', JSON.parse(process.env.REPORT_FILES).join('\n')); - core.setOutput('id', require('node:crypto').randomUUID()); - - name: Upload native lint reports - id: upload-reports - if: ${{ !cancelled() && steps.report-artifact.outputs.files != '' }} - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + await exec.exec('composer', ['--no-interaction', 'run-script', '--timeout=0', process.env.COMMAND.trim()], {cwd:process.env.WORKING_DIRECTORY}); + - name: Prepare and retain reports + id: reports + if: ${{ !cancelled() && steps.prepare.outcome == 'success' }} + uses: hoverkraft-tech/ci-github-common/actions/quality/prepare-ci-reports@23aa1846c8c6d829f321984b6d0252ebc36b01ee # PR #683 (unreleased) with: - name: ci-reports-${{ github.run_attempt }}-${{ github.job }}-${{ steps.report-artifact.outputs.id }} - path: ${{ steps.report-artifact.outputs.files }} - include-hidden-files: true - if-no-files-found: error - retention-days: 7 + definition: ${{ steps.prepare.outputs.definition }} + directory: ${{ steps.prepare.outputs.report-directory }} + outcome: ${{ steps.run.outcome }} diff --git a/actions/package/test/README.md b/actions/package/test/README.md index a7eb1f2..e266196 100644 --- a/actions/package/test/README.md +++ b/actions/package/test/README.md @@ -3,7 +3,7 @@ # ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Test Composer package
- Test Composer package + Test Composer package
--- diff --git a/actions/setup-php/README.md b/actions/setup-php/README.md index 0cbcf9f..a992340 100644 --- a/actions/setup-php/README.md +++ b/actions/setup-php/README.md @@ -3,7 +3,7 @@ # ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Setup PHP
- Setup PHP + Setup PHP
--- diff --git a/actions/setup-php/action.yml b/actions/setup-php/action.yml index 54d7688..576125c 100644 --- a/actions/setup-php/action.yml +++ b/actions/setup-php/action.yml @@ -108,7 +108,7 @@ runs: core.setOutput('directories', resolved); core.setOutput('cache', cache.stdout.trim()); core.setOutput('php-version', php.stdout.trim()); - - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ${{ steps.configuration.outputs.cache }} key: composer-${{ runner.os }}-${{ steps.configuration.outputs.php-version }}-${{ hashFiles(format('{0}/**/composer.json', inputs.working-directory), format('{0}/**/composer.lock', inputs.working-directory)) }} diff --git a/actions/test/README.md b/actions/test/README.md index 4465956..efd1887 100644 --- a/actions/test/README.md +++ b/actions/test/README.md @@ -1,9 +1,9 @@ -# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Test PHP +# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItY2hlY2stc3F1YXJlIiBjb2xvcj0iYmx1ZSI+PHBvbHlsaW5lIHBvaW50cz0iOSAxMSAxMiAxNCAyMiA0Ij48L3BvbHlsaW5lPjxwYXRoIGQ9Ik0yMSAxMnY3YTIgMiAwIDAgMS0yIDJINWEyIDIgMCAwIDEtMi0yVjVhMiAyIDAgMCAxIDItMmgxMSI+PC9wYXRoPjwvc3ZnPg==) GitHub Action: Test PHP
- Test PHP + Test PHP
--- @@ -13,12 +13,13 @@ ## Overview -Run Composer tests and report results, optionally uploading coverage. +Run PHP tests, fail on native errors and retain evidence for consolidated reporting. -Native test reports and GitHub coverage reports are retained for seven days, -including after command failures. Only parsed report files are uploaded. -Keep `comment: false` and call the common `ci-reports` workflow after producer -jobs for consolidated comments with collapsed details. +Run the project's Composer script and retain validated native reports. +The script writes fresh reports under CI_REPORTS_DIR. Test scripts honor +CI_TEST_COVERAGE when selecting instrumentation. Run setup-php first. +Requires actions: read and contents: read. Call ci-reports once after all jobs; +the separate CI complete gate decides whether the whole pipeline succeeded. @@ -28,32 +29,25 @@ jobs for consolidated comments with collapsed details. ```yaml - uses: hoverkraft-tech/ci-github-php/actions/test@9fc3d4e8925f8c6d87f1d46bd6b695ef75cb0f0a # 2.0.4 with: - # Composer project directory. Run setup-php first to install its dependencies. + # Composer project directory, with its dependencies installed. # Default: `.` working-directory: . - # Composer script to execute unchanged, normally `test:ci` in composer.json. - # The project defines its test tool, preparation and report generation. Examples: - # - # - PHPUnit: `phpunit --configuration phpunit.xml --log-junit=junit.xml --coverage-cobertura=cobertura.xml` - # - Pest: `pest --ci --log-junit=junit.xml --coverage-cobertura=cobertura.xml` - # - Codeception: `codecept run --xml=junit.xml --coverage-xml=clover.xml`; - # enable coverage in codeception.yml and select `coverage: codecov` for its Clover XML. - # - # For Codecov, PHPUnit and Pest can use `--coverage-clover=clover.xml`. - # Omit coverage arguments when collection is not needed. The coverage input controls publication only. - # See the [CI guide](../../.github/workflows/continuous-integration.md). - # + # Composer script to execute unchanged. Write native reports under CI_REPORTS_DIR. # Default: `test:ci` command: test:ci - # Coverage destination: `github` for report parsing, `codecov` for OIDC upload, or empty to disable coverage publication. Coverage files must be produced by the test command. - # Default: `github` - coverage: github + # Required native report paths relative to CI_REPORTS_DIR, one per line. + # Default: `junit.xml` + test-results: junit.xml - # Publish an individual test and coverage PR comment. Requires pull-requests write permission. Fork comments are disabled. Leave false for consolidated reporting; annotations, summaries and artifacts remain enabled. - # Default: `false` - comment: "false" + # Require test coverage. The project command must honor CI_TEST_COVERAGE when selecting instrumentation. + # Default: `true` + coverage: "true" + + # Required native coverage paths relative to CI_REPORTS_DIR when coverage is enabled, one per line. + # Default: `cobertura.xml` + test-coverage: cobertura.xml ``` @@ -61,22 +55,13 @@ jobs for consolidated comments with collapsed details. ## Inputs -| **Input** | **Description** | **Required** | **Default** | -| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------- | -| **`working-directory`** | Composer project directory. Run setup-php first to install its dependencies. | **false** | `.` | -| **`command`** | Composer script to execute unchanged, normally `test:ci` in composer.json. | **false** | `test:ci` | -| | The project defines its test tool, preparation and report generation. Examples: | | | -| | | | | -| | - PHPUnit: `phpunit --configuration phpunit.xml --log-junit=junit.xml --coverage-cobertura=cobertura.xml` | | | -| | - Pest: `pest --ci --log-junit=junit.xml --coverage-cobertura=cobertura.xml` | | | -| | - Codeception: `codecept run --xml=junit.xml --coverage-xml=clover.xml`; | | | -| | enable coverage in codeception.yml and select `coverage: codecov` for its Clover XML. | | | -| | | | | -| | For Codecov, PHPUnit and Pest can use `--coverage-clover=clover.xml`. | | | -| | Omit coverage arguments when collection is not needed. The coverage input controls publication only. | | | -| | See the [CI guide](../../.github/workflows/continuous-integration.md). | | | -| **`coverage`** | Coverage destination: `github` for report parsing, `codecov` for OIDC upload, or empty to disable coverage publication. Coverage files must be produced by the test command. | **false** | `github` | -| **`comment`** | Publish an individual test and coverage PR comment. Requires pull-requests write permission. Fork comments are disabled. Leave false for consolidated reporting; annotations, summaries and artifacts remain enabled. | **false** | `false` | +| **Input** | **Description** | **Required** | **Default** | +| ----------------------- | ------------------------------------------------------------------------------------------------------ | ------------ | --------------- | +| **`working-directory`** | Composer project directory, with its dependencies installed. | **false** | `.` | +| **`command`** | Composer script to execute unchanged. Write native reports under CI_REPORTS_DIR. | **false** | `test:ci` | +| **`test-results`** | Required native report paths relative to CI_REPORTS_DIR, one per line. | **false** | `junit.xml` | +| **`coverage`** | Require test coverage. The project command must honor CI_TEST_COVERAGE when selecting instrumentation. | **false** | `true` | +| **`test-coverage`** | Required native coverage paths relative to CI_REPORTS_DIR when coverage is enabled, one per line. | **false** | `cobertura.xml` | @@ -85,44 +70,25 @@ jobs for consolidated comments with collapsed details. ## Outputs -| **Output** | **Description** | -| ------------------------ | ----------------------------------------------------------------------------------------------------------------- | -| **`report-artifact-id`** | Native report artifact ID, empty when no supported reports were parsed. Coverage is included only in GitHub mode. | +| **Output** | **Description** | +| ------------------------ | ------------------------------------------------------------------ | +| **`report-artifact-id`** | Native result artifact ID, automatically discovered by ci-reports. | [![Marketplace](https://img.shields.io/badge/Marketplace-test--php-blue?logo=github-actions)](https://github.com/marketplace/actions/test-php) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-php)](https://github.com/hoverkraft-tech/ci-github-php/releases) -[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-php)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-php?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-php?style=social) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-php/blob/main/CONTRIBUTING.md) -![GitHub Verified Creator](https://img.shields.io/badge/GitHub-Verified%20Creator-4493F8?logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJyZ2IoNjgsIDE0NywgMjQ4KSI+CiAgPHBhdGggZD0ibTkuNTg1LjUyLjkyOS42OGMuMTUzLjExMi4zMzEuMTg2LjUxOC4yMTVsMS4xMzguMTc1YTIuNjc4IDIuNjc4IDAgMCAxIDIuMjQgMi4yNGwuMTc0IDEuMTM5Yy4wMjkuMTg3LjEwMy4zNjUuMjE1LjUxOGwuNjguOTI4YTIuNjc3IDIuNjc3IDAgMCAxIDAgMy4xN2wtLjY4LjkyOGExLjE3NCAxLjE3NCAwIDAgMC0uMjE1LjUxOGwtLjE3NSAxLjEzOGEyLjY3OCAyLjY3OCAwIDAgMS0yLjI0MSAyLjI0MWwtMS4xMzguMTc1YTEuMTcgMS4xNyAwIDAgMC0uNTE4LjIxNWwtLjkyOC42OGEyLjY3NyAyLjY3NyAwIDAgMS0zLjE3IDBsLS45MjgtLjY4YTEuMTc0IDEuMTc0IDAgMCAwLS41MTgtLjIxNUwzLjgzIDE0LjQxYTIuNjc4IDIuNjc4IDAgMCAxLTIuMjQtMi4yNGwtLjE3NS0xLjEzOGExLjE3IDEuMTcgMCAwIDAtLjIxNS0uNTE4bC0uNjgtLjkyOGEyLjY3NyAyLjY3NyAwIDAgMSAwLTMuMTdsLjY4LS45MjhjLjExMi0uMTUzLjE4Ni0uMzMxLjIxNS0uNTE4bC4xNzUtMS4xNGEyLjY3OCAyLjY3OCAwIDAgMSAyLjI0LTIuMjRsMS4xMzktLjE3NWMuMTg3LS4wMjkuMzY1LS4xMDMuNTE4LS4yMTVsLjkyOC0uNjhhMi42NzcgMi42NzcgMCAwIDEgMy4xNyAwWk03LjMwMyAxLjcyOGwtLjkyNy42OGEyLjY3IDIuNjcgMCAwIDEtMS4xOC40ODlsLTEuMTM3LjE3NGExLjE3OSAxLjE3OSAwIDAgMC0uOTg3Ljk4N2wtLjE3NCAxLjEzNmEyLjY3NyAyLjY3NyAwIDAgMS0uNDg5IDEuMThsLS42OC45MjhhMS4xOCAxLjE4IDAgMCAwIDAgMS4zOTRsLjY4LjkyN2MuMjU2LjM0OC40MjQuNzUzLjQ4OSAxLjE4bC4xNzQgMS4xMzdjLjA3OC41MDkuNDc4LjkwOS45ODcuOTg3bDEuMTM2LjE3NGEyLjY3IDIuNjcgMCAwIDEgMS4xOC40ODlsLjkyOC42OGMuNDE0LjMwNS45NzkuMzA1IDEuMzk0IDBsLjkyNy0uNjhhMi42NyAyLjY3IDAgMCAxIDEuMTgtLjQ4OWwxLjEzNy0uMTc0YTEuMTggMS4xOCAwIDAgMCAuOTg3LS45ODdsLjE3NC0xLjEzNmEyLjY3IDIuNjcgMCAwIDEgLjQ4OS0xLjE4bC42OC0uOTI4YTEuMTc2IDEuMTc2IDAgMCAwIDAtMS4zOTRsLS42OC0uOTI3YTIuNjg2IDIuNjg2IDAgMCAxLS40ODktMS4xOGwtLjE3NC0xLjEzN2ExLjE3OSAxLjE3OSAwIDAgMC0uOTg3LS45ODdsLTEuMTM2LS4xNzRhMi42NzcgMi42NzcgMCAwIDEtMS4xOC0uNDg5bC0uOTI4LS42OGExLjE3NiAxLjE3NiAwIDAgMC0xLjM5NCAwWk0xMS4yOCA2Ljc4bC0zLjc1IDMuNzVhLjc1Ljc1IDAgMCAxLTEuMDYgMEw0LjcyIDguNzhhLjc1MS43NTEgMCAwIDEgLjAxOC0xLjA0Mi43NTEuNzUxIDAgMCAxIDEuMDQyLS4wMThMNyA4Ljk0bDMuMjItMy4yMmEuNzUxLjc1MSAwIDAgMSAxLjA0Mi4wMTguNzUxLjc1MSAwIDAgMSAuMDE4IDEuMDQyWiI+PC9wYXRoPgo8L3N2Zz4K) - -## Contributing - -Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-php/blob/main/CONTRIBUTING.md) for more details. - - -## License - -This project is licensed under the MIT License. - -SPDX-License-Identifier: MIT - -Copyright © 2026 hoverkraft - -For more details, see the [license](http://choosealicense.com/licenses/mit/). - diff --git a/actions/test/action.yml b/actions/test/action.yml index 28d2117..ac31554 100644 --- a/actions/test/action.yml +++ b/actions/test/action.yml @@ -1,43 +1,39 @@ +# Run the project's Composer script and retain validated native reports. +# The script writes fresh reports under CI_REPORTS_DIR. Test scripts honor +# CI_TEST_COVERAGE when selecting instrumentation. Run setup-php first. +# Requires actions: read and contents: read. Call ci-reports once after all jobs; +# the separate CI complete gate decides whether the whole pipeline succeeded. name: Test PHP -description: | - Run Composer tests and report results, optionally uploading coverage. - - Native test reports and GitHub coverage reports are retained for seven days, - including after command failures. Only parsed report files are uploaded. - Keep `comment: false` and call the common `ci-reports` workflow after producer - jobs for consolidated comments with collapsed details. +description: Run PHP tests, fail on native errors and retain evidence for + consolidated reporting. author: hoverkraft branding: - icon: package + icon: check-square color: blue inputs: working-directory: - description: Composer project directory. Run setup-php first to install its dependencies. + description: Composer project directory, with its dependencies installed. default: . command: - description: | - Composer script to execute unchanged, normally `test:ci` in composer.json. - The project defines its test tool, preparation and report generation. Examples: - - - PHPUnit: `phpunit --configuration phpunit.xml --log-junit=junit.xml --coverage-cobertura=cobertura.xml` - - Pest: `pest --ci --log-junit=junit.xml --coverage-cobertura=cobertura.xml` - - Codeception: `codecept run --xml=junit.xml --coverage-xml=clover.xml`; - enable coverage in codeception.yml and select `coverage: codecov` for its Clover XML. - - For Codecov, PHPUnit and Pest can use `--coverage-clover=clover.xml`. - Omit coverage arguments when collection is not needed. The coverage input controls publication only. - See the [CI guide](../../.github/workflows/continuous-integration.md). + description: + Composer script to execute unchanged. Write native reports under + CI_REPORTS_DIR. default: test:ci + test-results: + description: Required native report paths relative to CI_REPORTS_DIR, one per line. + default: junit.xml coverage: - description: "Coverage destination: `github` for report parsing, `codecov` for OIDC upload, or empty to disable coverage publication. Coverage files must be produced by the test command." - default: github - comment: - description: Publish an individual test and coverage PR comment. Requires pull-requests write permission. Fork comments are disabled. Leave false for consolidated reporting; annotations, summaries and artifacts remain enabled. - default: "false" + description: Require test coverage. The project command must honor + CI_TEST_COVERAGE when selecting instrumentation. + default: "true" + test-coverage: + description: Required native coverage paths relative to CI_REPORTS_DIR when + coverage is enabled, one per line. + default: cobertura.xml outputs: report-artifact-id: - description: Native report artifact ID, empty when no supported reports were parsed. Coverage is included only in GitHub mode. - value: ${{ steps.upload-reports.outputs.artifact-id }} + description: Native result artifact ID, automatically discovered by ci-reports. + value: ${{ steps.reports.outputs.artifact-id }} runs: using: composite steps: @@ -45,98 +41,54 @@ runs: uses: hoverkraft-tech/ci-github-common/actions/working-directory@f165c0ca3e88604611481e1408ace1e0e3a5ee47 # 4.3.1 with: working-directory: ${{ inputs.working-directory }} - - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 - env: - COVERAGE: ${{ inputs.coverage }} - with: - script: |- - if (!['', 'github', 'codecov'].includes(process.env.COVERAGE)) throw new Error('coverage must be github, codecov or empty.'); - - id: run + - id: definition uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: - WORKING_DIRECTORY: ${{ steps.directory.outputs.absolute-path }} + PROJECT: ${{ steps.directory.outputs.workspace-relative-path || '.' }} COMMAND: ${{ inputs.command }} + RESULTS: ${{ inputs.test-results }} + COVERAGE: ${{ inputs.coverage }} + COVERAGE_PATHS: ${{ inputs.test-coverage }} with: - script: |- + script: | const command = process.env.COMMAND.trim(); - if (!command || command.startsWith('-')) throw new Error('command must name a Composer script.'); - const args = ['--no-interaction', 'run-script', '--timeout=0', command]; - await exec.exec('composer', args, {cwd: process.env.WORKING_DIRECTORY, env: {...process.env, CI: 'true'}}); - - name: Report test results - id: reports - if: ${{ !cancelled() && steps.directory.outcome == 'success' }} - uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@f165c0ca3e88604611481e1408ace1e0e3a5ee47 # 4.3.1 - with: - working-directory: ${{ steps.directory.outputs.absolute-path }} - report-paths: ${{ inputs.coverage == 'github' && 'auto:test,auto:coverage' || 'auto:test' }} - report-name: PHP tests - output-format: annotations,summary,markdown - - name: Publish individual report comment - if: ${{ !cancelled() && inputs.comment == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && (steps.reports.outputs.test-markdown != '' || steps.reports.outputs.coverage-markdown != '') }} - uses: hoverkraft-tech/ci-github-common/actions/create-or-update-comment@f165c0ca3e88604611481e1408ace1e0e3a5ee47 # 4.3.1 - with: - title: PHP test results - body: | - ${{ steps.reports.outputs.test-markdown }} - ${{ steps.reports.outputs.coverage-markdown }} - - name: Prepare native report artifact - id: report-artifact - if: ${{ !cancelled() && steps.reports.outputs.parsed-files != '' }} + if (!command || command.startsWith('-') || /\s/.test(command)) throw new Error('command must name a Composer script.'); + const paths = value => { + const result = value.split(/\r?\n/).map(item => item.trim()).filter(Boolean); + if (!result.length) throw new Error('Required report paths must not be empty.'); + return result; + }; + const reports = paths(process.env.RESULTS).map(pattern => ({kind:'test',pattern})); + if (!['true','false'].includes(process.env.COVERAGE)) throw new Error('coverage must be true or false.'); + if (process.env.COVERAGE === 'true') reports.push(...paths(process.env.COVERAGE_PATHS).map(pattern => ({kind:'coverage',pattern,language:'PHP'}))); + const runtime = await exec.getExecOutput('php', ['-r', 'echo PHP_VERSION;'], {silent:true}); + core.setOutput('definition', {name:'PHP tests',project:process.env.PROJECT,variant:{runtime:runtime.stdout.trim()},reports}); + - id: prepare uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - env: - REPORT_FILES: ${{ steps.reports.outputs.parsed-files }} with: script: | - core.setOutput('files', JSON.parse(process.env.REPORT_FILES).join('\n')); - core.setOutput('id', require('node:crypto').randomUUID()); - - name: Upload native test and coverage reports - id: upload-reports - if: ${{ !cancelled() && steps.report-artifact.outputs.files != '' }} - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: ci-reports-${{ github.run_attempt }}-${{ github.job }}-${{ steps.report-artifact.outputs.id }} - path: ${{ steps.report-artifact.outputs.files }} - include-hidden-files: true - if-no-files-found: error - retention-days: 7 - - name: Find coverage reports - id: coverage-reports - if: "!cancelled() && steps.run.outcome != 'skipped' && inputs.coverage == 'codecov'" + const fs = require('node:fs'); + const path = require('node:path'); + core.setOutput('report-directory', fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, 'ci-reports-'))); + core.setOutput('definition', process.env.REPORT_DEFINITION); + env: + REPORT_DEFINITION: ${{ steps.definition.outputs.definition }} + - id: run uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: WORKING_DIRECTORY: ${{ steps.directory.outputs.absolute-path }} + COMMAND: ${{ inputs.command }} + CI_REPORTS_DIR: ${{ steps.prepare.outputs.report-directory }} + CI_TEST_COVERAGE: ${{ inputs.coverage }} + CI: "true" with: - script: |- - const fs = require('node:fs/promises'); - const directory = process.env.WORKING_DIRECTORY; - const reports = {clover: [], cobertura: []}; - const search = await glob.create([ - `${directory}/**/*.xml`, - `!${directory}/**/vendor/**`, - `!${directory}/**/node_modules/**`, - `!${directory}/**/.git/**`, - ].join('\n'), {followSymbolicLinks: false, matchDirectories: false}); - for await (const file of search.globGenerator()) { - const handle = await fs.open(file, 'r'); - let header; - try { - const {buffer, bytesRead} = await handle.read(Buffer.alloc(8192), 0, 8192, 0); - header = buffer.toString('utf8', 0, bytesRead); - } finally { - await handle.close(); - } - if (/]*>\s*]*\bline-rate=/.test(header)) reports.cobertura.push(file); - } - const files = reports.clover.length ? reports.clover : reports.cobertura; - if (!files.length) throw new Error('No Clover or Cobertura coverage reports found. Enable coverage in the Composer test script.'); - if (files.some(file => file.includes(','))) throw new Error('Coverage report paths must not contain commas.'); - core.info(`Uploading ${files.length} ${reports.clover.length ? 'Clover' : 'Cobertura'} coverage report(s).`); - core.setOutput('files', files.sort().join(',')); - - name: Upload coverage - if: "!cancelled() && steps.coverage-reports.outcome == 'success'" - uses: hoverkraft-tech/ci-github-common/actions/quality/codecov@f165c0ca3e88604611481e1408ace1e0e3a5ee47 # 4.3.1 + script: | + await exec.exec('composer', ['--no-interaction', 'run-script', '--timeout=0', process.env.COMMAND.trim()], {cwd:process.env.WORKING_DIRECTORY}); + - name: Prepare and retain reports + id: reports + if: ${{ !cancelled() && steps.prepare.outcome == 'success' }} + uses: hoverkraft-tech/ci-github-common/actions/quality/prepare-ci-reports@23aa1846c8c6d829f321984b6d0252ebc36b01ee # PR #683 (unreleased) with: - working-directory: ${{ steps.directory.outputs.absolute-path }} - files: ${{ steps.coverage-reports.outputs.files }} - fail-ci-if-error: "true" + definition: ${{ steps.prepare.outputs.definition }} + directory: ${{ steps.prepare.outputs.report-directory }} + outcome: ${{ steps.run.outcome }} diff --git a/docs/development/README.md b/docs/development/README.md index e89022f..5a71b73 100644 --- a/docs/development/README.md +++ b/docs/development/README.md @@ -14,16 +14,18 @@ workflow validates Composer metadata and tag identity before publication. `__shared-ci.yml` runs lint, dedicated workflows for each action, and an end-to-end call to the public CI and documentation workflows. The Composer fixture covers automatic and explicit tool installation, lockfile and lockfile-free setup, installation hooks, PHPUnit reports, and PHPStan. -Test-action cases cover Composer-owned report generation, coverage publication, +Test-action cases cover Composer-owned report generation, primary-runtime coverage, preparation, custom commands, and failure propagation. Dedicated lint and test -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 -details. Package integration tests create independent Git -repositories and exercise distribution omissions, consumer commands, archive -immutability, and cleanup. +workflows retrieve native result artifacts after successful or intentionally +failed commands finish. They verify filenames, native checksums, validation errors +and exclusion of private project files. Verified negative fixture evidence is +removed before consolidated reporting; this cleanup is confined to the test harness. + +The actions use common `prepare-ci-reports`; they neither publish comments nor +forward report plans. One outer `ci-reports` publishes evidence and a separate +`CI complete` job gates every required dependency. Package integration tests create +independent Git repositories and exercise distribution omissions, consumer commands, +archive immutability, and cleanup. Release guard checks live in `__test-workflow-release.yml`. They exercise the actual preparation and publication scripts: event restrictions, no-change status, diff --git a/tests/php-project/composer.json b/tests/php-project/composer.json index 8e064c6..7ef23d5 100644 --- a/tests/php-project/composer.json +++ b/tests/php-project/composer.json @@ -19,11 +19,11 @@ } }, "scripts": { - "lint:ci": "tools/vendor/bin/phpstan analyse src --level=max --no-progress --error-format=github", + "lint:ci": "tools/vendor/bin/phpstan analyse src --level=max --no-progress --error-format=checkstyle > \"$CI_REPORTS_DIR/phpstan-checkstyle.xml\"", "test": "phpunit", "post-install-cmd": "@php -r \"file_put_contents('install-hook.txt', 'hook executed');\"", "post-update-cmd": "@post-install-cmd", - "test:ci": "@test --log-junit=junit.xml --coverage-cobertura=cobertura.xml" + "test:ci": "if [ \"$CI_TEST_COVERAGE\" = true ]; then phpunit --log-junit=\"$CI_REPORTS_DIR/junit.xml\" --coverage-cobertura=\"$CI_REPORTS_DIR/cobertura.xml\"; else phpunit --log-junit=\"$CI_REPORTS_DIR/junit.xml\" --no-coverage; fi" }, "license": "MIT" }