diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 28fe933..066954c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -26,6 +26,7 @@ updates: prefix: build include: scope directories: + - "/actions/*" - "/actions/*/*" cooldown: default-days: 7 diff --git a/.github/linters/actionlint.yml b/.github/linters/actionlint.yml new file mode 100644 index 0000000..3e2774f --- /dev/null +++ b/.github/linters/actionlint.yml @@ -0,0 +1,15 @@ +# FIXME: Remove this scoped exception when Actionlint supports code-quality. +# 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/__greetings.yml b/.github/workflows/__greetings.yml index 32eac57..dd12b35 100644 --- a/.github/workflows/__greetings.yml +++ b/.github/workflows/__greetings.yml @@ -12,7 +12,7 @@ permissions: {} jobs: greetings: - uses: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 + uses: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 permissions: contents: read issues: write diff --git a/.github/workflows/__main-ci.yml b/.github/workflows/__main-ci.yml index 977a149..483d881 100644 --- a/.github/workflows/__main-ci.yml +++ b/.github/workflows/__main-ci.yml @@ -23,6 +23,8 @@ jobs: name: Continuous Integration uses: $/.github/workflows/__shared-ci.yml permissions: + id-token: write + code-quality: write actions: read contents: read issues: write diff --git a/.github/workflows/__need-fix-to-issue.yml b/.github/workflows/__need-fix-to-issue.yml index c5aa356..91d1331 100644 --- a/.github/workflows/__need-fix-to-issue.yml +++ b/.github/workflows/__need-fix-to-issue.yml @@ -21,7 +21,7 @@ permissions: {} jobs: main: - uses: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 + uses: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 permissions: contents: read issues: write diff --git a/.github/workflows/__pull-request-ci.yml b/.github/workflows/__pull-request-ci.yml index 649b13f..8e3986a 100644 --- a/.github/workflows/__pull-request-ci.yml +++ b/.github/workflows/__pull-request-ci.yml @@ -19,6 +19,8 @@ jobs: name: Continuous Integration uses: $/.github/workflows/__shared-ci.yml permissions: + id-token: write + code-quality: write actions: read contents: read issues: write diff --git a/.github/workflows/__release.yml b/.github/workflows/__release.yml index ffc1392..a9c64f4 100644 --- a/.github/workflows/__release.yml +++ b/.github/workflows/__release.yml @@ -24,6 +24,8 @@ jobs: if: github.ref_type == 'branch' && github.ref_name == github.event.repository.default_branch uses: $/.github/workflows/__shared-ci.yml permissions: + id-token: write + code-quality: write actions: read contents: read issues: write diff --git a/.github/workflows/__semantic-pull-request.yml b/.github/workflows/__semantic-pull-request.yml index 36b014f..2122f61 100644 --- a/.github/workflows/__semantic-pull-request.yml +++ b/.github/workflows/__semantic-pull-request.yml @@ -14,4 +14,4 @@ jobs: main: permissions: contents: read - uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 + uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 diff --git a/.github/workflows/__shared-ci.yml b/.github/workflows/__shared-ci.yml index 7ff91d5..6de20ba 100644 --- a/.github/workflows/__shared-ci.yml +++ b/.github/workflows/__shared-ci.yml @@ -8,7 +8,7 @@ permissions: {} jobs: linter: - uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 + uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 with: linter-env: | FILTER_REGEX_EXCLUDE=/(\.cache|\.reports)/ @@ -20,35 +20,81 @@ jobs: pull-requests: write security-events: write statuses: write - test-action-vm-create: + test-vm-create: permissions: + actions: read contents: read uses: $/.github/workflows/__test-actions-vm-create.yml - test-action-vm-test: + test-vm-test: permissions: actions: read contents: read - pull-requests: write uses: $/.github/workflows/__test-actions-vm-test.yml - test-action-vm-destroy: + test-vm-destroy: permissions: + actions: read contents: read uses: $/.github/workflows/__test-actions-vm-destroy.yml - test-action-ansible-test: + test-ansible: permissions: actions: read contents: read - pull-requests: write uses: $/.github/workflows/__test-actions-ansible-test.yml - test-action-ansible-test-molecule: + test-molecule: permissions: actions: read contents: read - pull-requests: write uses: $/.github/workflows/__test-actions-ansible-test-molecule.yml - test-action-opentofu-test: + test-opentofu: permissions: actions: read contents: read - pull-requests: write uses: $/.github/workflows/__test-actions-opentofu-test.yml + + test-retain-native-reports: + permissions: + actions: read + contents: read + uses: $/.github/workflows/__test-actions-retain-native-reports.yml + + reports: + if: always() + needs: + - linter + - test-vm-create + - test-vm-test + - test-vm-destroy + - test-ansible + - test-molecule + - test-opentofu + - test-retain-native-reports + uses: hoverkraft-tech/ci-github-common/.github/workflows/publish-ci-reports.yml@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + 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-vm-create, + test-vm-test, + test-vm-destroy, + test-ansible, + test-molecule, + test-opentofu, + test-retain-native-reports, + reports, + ] + uses: hoverkraft-tech/ci-github-common/.github/workflows/check-jobs.yml@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + permissions: {} + with: + job-results: ${{ toJSON(needs) }} diff --git a/.github/workflows/__stale.yml b/.github/workflows/__stale.yml index 3fc7a3e..75a300e 100644 --- a/.github/workflows/__stale.yml +++ b/.github/workflows/__stale.yml @@ -9,7 +9,7 @@ permissions: {} jobs: main: - uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 + uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 permissions: issues: write pull-requests: write diff --git a/.github/workflows/__test-actions-ansible-test-molecule.yml b/.github/workflows/__test-actions-ansible-test-molecule.yml index 6df9f72..f06bb5d 100644 --- a/.github/workflows/__test-actions-ansible-test-molecule.yml +++ b/.github/workflows/__test-actions-ansible-test-molecule.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 permissions: + actions: read contents: read steps: - name: Arrange - Checkout action sources @@ -18,18 +19,18 @@ jobs: persist-credentials: false # jscpd:ignore-end - name: Act - Run ansible/test-molecule unit tests - uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + uses: hoverkraft-tech/ci-github-nodejs/actions/test@133df96fa31a002107174959beafa09808597051 # PR #624 (unreleased) with: working-directory: actions/ansible/test-molecule - command: test:ci - coverage: "" + engine: node:test + coverage: "true" + arguments: '["--test-coverage-exclude=**/tests/**","--test-coverage-include=*.cjs"]' local: runs-on: ubuntu-latest timeout-minutes: 12 permissions: actions: read contents: read - pull-requests: write strategy: fail-fast: false matrix: @@ -52,25 +53,42 @@ jobs: molecule-scenario: tests/fixture/molecule/local ansible-requirements: tests/fixture/ansible/requirements.txt test-timeout-minutes: ${{ matrix.result == 'timeout' && '1' || '5' }} - report-name: Molecule local scenario - ${{ matrix.result }} + - name: Arrange - Download local native-artifacts-0 evidence + uses: hoverkraft-tech/ci-github-common/actions/download-artifact@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.scenario.outputs.report-artifact-id }} + path: ${{ runner.temp }}/native-artifacts-0 + if: ${{ !cancelled() }} - name: Assert - Require native reports and scenario cleanup + id: verify-ansible-test-molecule-local if: ${{ always() }} uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: + EVIDENCE_DIRECTORY: ${{ runner.temp }}/native-artifacts-0 MOLECULE_TEST_DIRECTORY: ${{ runner.temp }}/molecule-local SCENARIO_OUTCOME: ${{ steps.scenario.outcome }} + NEGATIVE_ARTIFACT_IDS: ${{ steps.scenario.outcome == 'failure' && + steps.scenario.outputs.report-artifact-id || '' }} with: script: | const fs = require('node:fs'); const assert = require('node:assert/strict'); const { PublishedReports } = require('./tests/helpers/published-reports.cjs'); - const published = new PublishedReports(github, context); + const published = new PublishedReports(context); const expected = process.env.MOLECULE_TEST_RESULT === 'success' ? 'success' : 'failure'; assert.equal(process.env.SCENARIO_OUTCOME, expected); assert.equal(fs.existsSync(process.env.MOLECULE_TEST_DIRECTORY), false); - const [report] = await published.read('molecule-reports-', 1); - assert.ok(report.files.some(file => file.endsWith('/scenario.xml'))); - assert.equal(/<(?:failure|error)\b/.test(report.text), expected === 'failure'); + const [report] = await published.read(1); + assert.ok(report.files.every(file => !file.endsWith('-scenario.xml'))); + assert.equal(report.result.outcome, expected); + core.setOutput('negative-fixtures', process.env.NEGATIVE_ARTIFACT_IDS); + - name: Cleanup - Discard ansible-test-molecule local negative results + if: steps.verify-ansible-test-molecule-local.outputs.negative-fixtures != '' + uses: hoverkraft-tech/ci-github-common/actions/quality/discard-report-fixtures@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ + steps.verify-ansible-test-molecule-local.outputs.negative-fixtures + }} vm: runs-on: ubuntu-latest timeout-minutes: 25 @@ -79,7 +97,6 @@ jobs: permissions: actions: read contents: read - pull-requests: write steps: - name: Arrange - Checkout fixture uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -118,20 +135,26 @@ jobs: with: molecule-scenario: tests/fixture/molecule/smoke ansible-requirements: tests/fixture/ansible/requirements.txt - report-name: Molecule - success + - name: Arrange - Download vm native-artifacts-1 evidence + uses: hoverkraft-tech/ci-github-common/actions/download-artifact@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.molecule-success.outputs.report-artifact-id }} + path: ${{ runner.temp }}/native-artifacts-1 + if: ${{ !cancelled() }} - name: Assert - Check successful Molecule execution if: ${{ !cancelled() && steps.vm.outcome == 'success' }} uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: + EVIDENCE_DIRECTORY: ${{ runner.temp }}/native-artifacts-1 SUCCESS: ${{ steps.molecule-success.outcome }} with: script: | const assert = require('node:assert/strict'); const { PublishedReports } = require('./tests/helpers/published-reports.cjs'); - const published = new PublishedReports(github, context); + const published = new PublishedReports(context); assert.equal(process.env.SUCCESS, 'success'); - await published.read('molecule-reports-', 1); + await published.read(1); - name: Act - Test Molecule assertion-failure id: molecule-assertion-failure @@ -144,20 +167,6 @@ jobs: with: molecule-scenario: tests/fixture/molecule/smoke ansible-requirements: tests/fixture/ansible/requirements.txt - report-name: Molecule - assertion-failure - - - name: Assert - Check Molecule assertion failure and reports - if: ${{ !cancelled() && steps.vm.outcome == 'success' }} - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - env: - ASSERTION_FAILURE: ${{ steps.molecule-assertion-failure.outcome }} - with: - script: | - const assert = require('node:assert/strict'); - const { PublishedReports } = require('./tests/helpers/published-reports.cjs'); - const published = new PublishedReports(github, context); - assert.equal(process.env.ASSERTION_FAILURE, 'failure'); - await published.read('molecule-reports-', 2); - name: Act - Test Molecule idempotence-failure id: molecule-idempotence-failure @@ -170,21 +179,42 @@ jobs: with: molecule-scenario: tests/fixture/molecule/smoke ansible-requirements: tests/fixture/ansible/requirements.txt - report-name: Molecule - idempotence-failure + - name: Arrange - Download vm native-artifacts-3 evidence + uses: hoverkraft-tech/ci-github-common/actions/download-artifact@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: + ${{ steps.molecule-success.outputs.report-artifact-id }},${{ + steps.molecule-assertion-failure.outputs.report-artifact-id }},${{ + steps.molecule-idempotence-failure.outputs.report-artifact-id }} + path: ${{ runner.temp }}/native-artifacts-3 + if: ${{ !cancelled() }} - name: Assert - Check Molecule idempotence failure and reports + id: verify-ansible-test-molecule-vm if: ${{ !cancelled() && steps.vm.outcome == 'success' }} uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: + EVIDENCE_DIRECTORY: ${{ runner.temp }}/native-artifacts-3 IDEMPOTENCE_FAILURE: ${{ steps.molecule-idempotence-failure.outcome }} + NEGATIVE_ARTIFACT_IDS: ${{ + steps.molecule-assertion-failure.outputs.report-artifact-id }},${{ + steps.molecule-idempotence-failure.outputs.report-artifact-id }} + ASSERTION_FAILURE: ${{ steps.molecule-assertion-failure.outcome }} with: script: | const assert = require('node:assert/strict'); const { PublishedReports } = require('./tests/helpers/published-reports.cjs'); - const published = new PublishedReports(github, context); + const published = new PublishedReports(context); + assert.equal(process.env.ASSERTION_FAILURE, 'failure'); assert.equal(process.env.IDEMPOTENCE_FAILURE, 'failure'); - await published.read('molecule-reports-', 3); - + await published.read(3); + core.setOutput('negative-fixtures', process.env.NEGATIVE_ARTIFACT_IDS); + - name: Cleanup - Discard ansible-test-molecule vm negative results + if: steps.verify-ansible-test-molecule-vm.outputs.negative-fixtures != '' + uses: hoverkraft-tech/ci-github-common/actions/quality/discard-report-fixtures@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ + steps.verify-ansible-test-molecule-vm.outputs.negative-fixtures }} # Fixture teardown is intentionally repeated; action assertions remain above. # jscpd:ignore-start - name: Cleanup - Destroy direct QEMU guest diff --git a/.github/workflows/__test-actions-ansible-test.yml b/.github/workflows/__test-actions-ansible-test.yml index 1e31692..378b808 100644 --- a/.github/workflows/__test-actions-ansible-test.yml +++ b/.github/workflows/__test-actions-ansible-test.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 permissions: + actions: read contents: read steps: - name: Arrange - Checkout action sources @@ -18,18 +19,18 @@ jobs: persist-credentials: false # jscpd:ignore-end - name: Act - Run ansible/test unit tests - uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + uses: hoverkraft-tech/ci-github-nodejs/actions/test@133df96fa31a002107174959beafa09808597051 # PR #624 (unreleased) with: working-directory: actions/ansible/test - command: test:ci - coverage: "" + engine: node:test + coverage: "true" + arguments: '["--test-coverage-exclude=**/tests/**","--test-coverage-include=*.cjs"]' scenarios: runs-on: ubuntu-latest timeout-minutes: 30 permissions: actions: read contents: read - pull-requests: write strategy: fail-fast: false matrix: @@ -64,25 +65,45 @@ jobs: FIXTURE_RESULT: ${{ matrix.result }} with: ansible-requirements: tests/fixture/ansible/requirements.txt - python-version-file: ${{ matrix.mode == 'playbook' && 'tests/fixture/ansible/.python-version' || '' }} - ansible-config: ${{ matrix.mode == 'playbook' && 'tests/fixture/ansible/ansible.cfg' || '' }} - test-playbook: ${{ matrix.mode == 'playbook' && 'tests/fixture/ansible/valid.yml' || '' }} - collection: ${{ matrix.mode == 'sanity' && 'tests/fixture/ansible/ansible_collections/example/smoke' || '' }} - target-python-version: ${{ matrix.mode == 'sanity' && steps.fixture.outputs.python-version || '' }} + python-version-file: ${{ matrix.mode == 'playbook' && + 'tests/fixture/ansible/.python-version' || '' }} + ansible-config: ${{ matrix.mode == 'playbook' && + 'tests/fixture/ansible/ansible.cfg' || '' }} + test-playbook: ${{ matrix.mode == 'playbook' && + 'tests/fixture/ansible/valid.yml' || '' }} + collection: ${{ matrix.mode == 'sanity' && + 'tests/fixture/ansible/ansible_collections/example/smoke' || '' }} + target-python-version: ${{ matrix.mode == 'sanity' && + steps.fixture.outputs.python-version || '' }} sanity-image: ${{ matrix.sanity-image || '' }} - report-name: Ansible tests - ${{ matrix.mode }} - ${{ matrix.result }} + - name: Arrange - Download scenarios native-artifacts-0 evidence + uses: hoverkraft-tech/ci-github-common/actions/download-artifact@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.test.outputs.report-artifact-id }} + path: ${{ runner.temp }}/native-artifacts-0 + if: ${{ !cancelled() }} - name: Assert - Verify check outcomes and native reports + id: verify-ansible-test-scenarios if: ${{ always() }} env: + EVIDENCE_DIRECTORY: ${{ runner.temp }}/native-artifacts-0 EXPECTED: ${{ matrix.result }} OUTCOME: ${{ steps.test.outcome }} + NEGATIVE_ARTIFACT_IDS: ${{ steps.test.outcome == 'failure' && + steps.test.outputs.report-artifact-id || '' }} uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | const assert = require('node:assert/strict'); const { PublishedReports } = require('./tests/helpers/published-reports.cjs'); - const published = new PublishedReports(github, context); + const published = new PublishedReports(context); assert.equal(process.env.OUTCOME, process.env.EXPECTED); - const [report] = await published.read('ansible-reports-', 1); + const [report] = await published.read(1); assert.ok(report.files.every(file => file.endsWith('.xml'))); assert.equal(/<(?:failure|error)\b/.test(report.text), process.env.EXPECTED === 'failure'); + core.setOutput('negative-fixtures', process.env.NEGATIVE_ARTIFACT_IDS); + - name: Cleanup - Discard ansible-test scenarios negative results + if: steps.verify-ansible-test-scenarios.outputs.negative-fixtures != '' + uses: hoverkraft-tech/ci-github-common/actions/quality/discard-report-fixtures@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.verify-ansible-test-scenarios.outputs.negative-fixtures }} diff --git a/.github/workflows/__test-actions-opentofu-test.yml b/.github/workflows/__test-actions-opentofu-test.yml index 386b357..0f9066d 100644 --- a/.github/workflows/__test-actions-opentofu-test.yml +++ b/.github/workflows/__test-actions-opentofu-test.yml @@ -8,6 +8,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 permissions: + actions: read contents: read steps: - name: Arrange - Checkout reporting adapter @@ -15,19 +16,18 @@ jobs: with: persist-credentials: false - name: Act - Test native report validation - uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + uses: hoverkraft-tech/ci-github-nodejs/actions/test@133df96fa31a002107174959beafa09808597051 # PR #624 (unreleased) with: working-directory: actions/opentofu/test - command: test:ci - coverage: "" - comment: "false" + engine: node:test + coverage: "true" + arguments: '["--test-coverage-exclude=**/tests/**","--test-coverage-include=*.cjs"]' scenarios: runs-on: ubuntu-latest timeout-minutes: 15 permissions: actions: read contents: read - pull-requests: write strategy: fail-fast: false matrix: @@ -51,31 +51,47 @@ jobs: if (process.env.SCENARIO === 'init-failure') fs.writeFileSync('tests/fixture/opentofu/main.tofu', 'invalid {'); - name: Act - Run native OpenTofu tests - id: test + id: opentofu-tests continue-on-error: true uses: $/actions/opentofu/test with: working-directory: tests/fixture/opentofu tofu-version-file: tests/fixture/opentofu/.opentofu-version - report-name: OpenTofu - ${{ matrix.result }} - comment: ${{ matrix.result == 'success' && 'true' || 'false' }} - - name: Assert - Verify outcomes and published safe reports + - name: Arrange - Download scenarios native-artifacts-0 evidence + uses: hoverkraft-tech/ci-github-common/actions/download-artifact@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.opentofu-tests.outputs.report-artifact-id }} + path: ${{ runner.temp }}/native-artifacts-0 + if: ${{ !cancelled() }} + - name: Assert - Verify outcomes and retained safe reports + id: verify-opentofu-test-scenarios if: ${{ always() }} uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: + EVIDENCE_DIRECTORY: ${{ runner.temp }}/native-artifacts-0 SCENARIO: ${{ matrix.result }} - OUTCOME: ${{ steps.test.outcome }} + OUTCOME: ${{ steps.opentofu-tests.outcome }} + NEGATIVE_ARTIFACT_IDS: + ${{ steps.opentofu-tests.outcome == 'failure' && + steps.opentofu-tests.outputs.report-artifact-id || '' }} with: script: | const assert = require('node:assert/strict'); const { PublishedReports } = require('./tests/helpers/published-reports.cjs'); const success = process.env.SCENARIO === 'success'; assert.equal(process.env.OUTCOME, success ? 'success' : 'failure'); - const [report] = await new PublishedReports(github, context).read('opentofu-test-', 1); - assert.deepEqual(report.files.map(file => require('node:path').basename(file)), ['opentofu.junit.xml']); - assert.equal(/<(?:failure|error)\b/.test(report.text), !success); + const published = new PublishedReports(context); + const [report] = await published.read(1); + assert.deepEqual(report.files.map(file => require('node:path').basename(file)), process.env.SCENARIO === 'init-failure' ? [] : ['1-opentofu.junit.xml']); + assert.equal(report.result.outcome, success ? 'success' : 'failure'); + assert.equal(/<(?:failure|error)\b/.test(report.text), process.env.SCENARIO === 'assertion-failure'); assert.ok(!report.text.includes('synthetic-native-test')); if (success) { assert.match(report.text, /apply_and_read/); - await new PublishedReports(github, context).comment('OpenTofu - success'); } + core.setOutput('negative-fixtures', process.env.NEGATIVE_ARTIFACT_IDS); + - name: Cleanup - Discard opentofu-test scenarios negative results + if: steps.verify-opentofu-test-scenarios.outputs.negative-fixtures != '' + uses: hoverkraft-tech/ci-github-common/actions/quality/discard-report-fixtures@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.verify-opentofu-test-scenarios.outputs.negative-fixtures }} diff --git a/.github/workflows/__test-actions-retain-native-reports.yml b/.github/workflows/__test-actions-retain-native-reports.yml new file mode 100644 index 0000000..e110173 --- /dev/null +++ b/.github/workflows/__test-actions-retain-native-reports.yml @@ -0,0 +1,84 @@ +--- +name: Internal - Test retain-native-reports +on: + workflow_call: +permissions: {} +jobs: + unit-tests: + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + steps: + - name: Arrange - Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} + - name: Act - Verify staging validation + uses: hoverkraft-tech/ci-github-nodejs/actions/test@133df96fa31a002107174959beafa09808597051 # PR #624 (unreleased) + with: + working-directory: actions/retain-native-reports + engine: node:test + coverage: "true" + arguments: '["--test-coverage-exclude=**/tests/**","--test-coverage-include=*.cjs"]' + retain: + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + actions: read + contents: read + steps: + - name: Arrange - Checkout report verification helpers + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ github.event.pull_request.head.sha || github.sha }} + - name: Arrange - Write a native test result + id: fixture + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + with: + script: | + const fs = require('node:fs'); + const path = require('node:path'); + const directory = fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, 'native-retention-fixture-')); + const file = path.join(directory, 'native.xml'); + fs.writeFileSync(file, ''); + core.setOutput('file', file); + core.setOutput('directory', directory); + - name: Act - Retain the selected native report + id: retain + uses: $/actions/retain-native-reports + with: + files: ${{ steps.fixture.outputs.file }} + definition: '{"name":"Native report retention + fixture","reports":[{"kind":"test","pattern":"native.xml"}]}' + outcome: success + - name: Arrange - Download retained evidence + uses: hoverkraft-tech/ci-github-common/actions/download-artifact@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.retain.outputs.artifact-id }} + path: ${{ runner.temp }}/native-retention-artifacts + - name: Assert - Verify native bytes and successful preparation + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + EVIDENCE_DIRECTORY: ${{ runner.temp }}/native-retention-artifacts + with: + script: | + const assert = require('node:assert/strict'); + const {PublishedReports} = require('./tests/helpers/published-reports.cjs'); + const [report] = await new PublishedReports(context).read(1); + assert.equal(report.result.outcome, 'success'); + assert.deepEqual(report.result.errors, []); + assert.deepEqual(report.files.map(file => require('node:path').basename(file)), ['1-native.xml']); + assert.match(report.text, /name="retained native result"/); + - name: Cleanup - Remove fixture and downloaded files + if: always() + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + DIRECTORY: ${{ steps.fixture.outputs.directory }} + with: + script: | + const path = require('node:path'); + if (process.env.DIRECTORY) await io.rmRF(process.env.DIRECTORY); + await io.rmRF(path.join(process.env.RUNNER_TEMP, 'native-retention-artifacts')); diff --git a/.github/workflows/__test-actions-vm-create.yml b/.github/workflows/__test-actions-vm-create.yml index dfb6bb2..679bd69 100644 --- a/.github/workflows/__test-actions-vm-create.yml +++ b/.github/workflows/__test-actions-vm-create.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 permissions: + actions: read contents: read steps: - name: Arrange - Checkout action sources @@ -18,15 +19,17 @@ jobs: persist-credentials: false # jscpd:ignore-end - name: Act - Run vm/create unit tests - uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + uses: hoverkraft-tech/ci-github-nodejs/actions/test@133df96fa31a002107174959beafa09808597051 # PR #624 (unreleased) with: working-directory: actions/vm/create - command: test:ci - coverage: "" + engine: node:test + coverage: "true" + arguments: '["--test-coverage-exclude=**/tests/**","--test-coverage-include=*.cjs","--test-coverage-include=../_internal/command.cjs","--test-coverage-include=../_internal/workspace.cjs"]' startup: runs-on: ubuntu-latest timeout-minutes: 20 permissions: + actions: read contents: read strategy: fail-fast: false diff --git a/.github/workflows/__test-actions-vm-destroy.yml b/.github/workflows/__test-actions-vm-destroy.yml index 7469c0c..cedbce7 100644 --- a/.github/workflows/__test-actions-vm-destroy.yml +++ b/.github/workflows/__test-actions-vm-destroy.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 permissions: + actions: read contents: read steps: - name: Arrange - Checkout action sources @@ -18,15 +19,17 @@ jobs: persist-credentials: false # jscpd:ignore-end - name: Act - Run vm/destroy unit tests - uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + uses: hoverkraft-tech/ci-github-nodejs/actions/test@133df96fa31a002107174959beafa09808597051 # PR #624 (unreleased) with: working-directory: actions/vm/destroy - command: test:ci - coverage: "" + engine: node:test + coverage: "true" + arguments: '["--test-coverage-exclude=**/tests/**","--test-coverage-include=../_internal/runtime.cjs"]' deletion: runs-on: ubuntu-latest timeout-minutes: 20 permissions: + actions: read contents: read strategy: fail-fast: false diff --git a/.github/workflows/__test-actions-vm-test.yml b/.github/workflows/__test-actions-vm-test.yml index e0a6ae6..bc00aad 100644 --- a/.github/workflows/__test-actions-vm-test.yml +++ b/.github/workflows/__test-actions-vm-test.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 permissions: + actions: read contents: read steps: - name: Arrange - Checkout action sources @@ -18,18 +19,18 @@ jobs: persist-credentials: false # jscpd:ignore-end - name: Act - Run vm/test unit tests - uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + uses: hoverkraft-tech/ci-github-nodejs/actions/test@133df96fa31a002107174959beafa09808597051 # PR #624 (unreleased) with: working-directory: actions/vm/test - command: test:ci - coverage: "" + engine: node:test + coverage: "true" + arguments: '["--test-coverage-exclude=**/tests/**","--test-coverage-include=*.cjs"]' guest: runs-on: ubuntu-latest timeout-minutes: 25 permissions: actions: read contents: read - pull-requests: write strategy: fail-fast: false matrix: @@ -65,17 +66,6 @@ jobs: sudo -n usermod -aG iac-goss "$(id -un)" ! id -nG | grep -qw iac-goss ' - - name: Arrange - Capture existing comments when publication is disabled - if: ${{ matrix.backend == 'lima' }} - id: comment-before - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - env: - REPORT_NAME: Goss - ${{ matrix.backend }} - valid - with: - script: | - const { PublishedReports } = require('./tests/helpers/published-reports.cjs'); - const published = new PublishedReports(github, context); - core.setOutput('comments', JSON.stringify(await published.readComments(process.env.REPORT_NAME))); - name: Act - Validate valid suite if: ${{ !cancelled() && steps.vm.outcome == 'success' }} id: valid @@ -83,36 +73,29 @@ jobs: uses: $/actions/vm/test with: vm: ${{ steps.vm.outputs.vm }} - comment: ${{ matrix.backend != 'lima' }} goss-file: tests/fixture/goss/valid.yaml goss-vars: tests/fixture/goss/vars.json test-timeout-minutes: 1 - report-name: Goss - ${{ matrix.backend }} - valid + - name: Arrange - Download guest native-artifacts-0 evidence + uses: hoverkraft-tech/ci-github-common/actions/download-artifact@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.valid.outputs.report-artifact-id }} + path: ${{ runner.temp }}/native-artifacts-0 + if: ${{ !cancelled() }} - name: Assert - Check valid results and retained reports if: ${{ !cancelled() && steps.vm.outcome == 'success' }} uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: + EVIDENCE_DIRECTORY: ${{ runner.temp }}/native-artifacts-0 OUTCOME: ${{ steps.valid.outcome }} - REPORT_NAME: Goss - ${{ matrix.backend }} - valid - EXPECT_COMMENT: ${{ matrix.backend != 'lima' }} - COMMENTS_BEFORE: ${{ steps.comment-before.outputs.comments }} with: script: | const assert = require('node:assert/strict'); const { PublishedReports } = require('./tests/helpers/published-reports.cjs'); - const published = new PublishedReports(github, context); + const published = new PublishedReports(context); assert.equal(process.env.OUTCOME, 'success'); - const reports = await published.read('vm-test-', 1); - assert.ok(reports.some(report => report.text.includes('goss-execution'))); - if (process.env.EXPECT_COMMENT === 'true') { - await published.comment(process.env.REPORT_NAME); - } else { - assert.deepEqual( - await published.readComments(process.env.REPORT_NAME), - JSON.parse(process.env.COMMENTS_BEFORE), - 'Disabled publication must leave existing comments unchanged', - ); - } + const reports = await published.read(1); + assert.ok(reports.some(report => report.files.some(file => file.endsWith('/1-goss.xml')))); - name: Act - Validate invalid suite if: ${{ !cancelled() && steps.vm.outcome == 'success' }} id: invalid @@ -123,7 +106,6 @@ jobs: goss-file: tests/fixture/goss/invalid.yaml goss-vars: tests/fixture/goss/vars.json test-timeout-minutes: 1 - report-name: Goss - ${{ matrix.backend }} - invalid - name: Act - Validate empty suite if: ${{ !cancelled() && steps.vm.outcome == 'success' }} id: empty @@ -134,7 +116,6 @@ jobs: goss-file: tests/fixture/goss/empty.yaml goss-vars: tests/fixture/goss/vars.json test-timeout-minutes: 1 - report-name: Goss - ${{ matrix.backend }} - empty - name: Act - Validate timeout suite if: ${{ !cancelled() && steps.vm.outcome == 'success' }} id: timeout @@ -145,27 +126,45 @@ jobs: goss-file: tests/fixture/goss/timeout.yaml goss-vars: tests/fixture/goss/vars.json test-timeout-minutes: 1 - report-name: Goss - ${{ matrix.backend }} - timeout - - name: Assert - Check failed suites, independent artifacts and comments + - name: Arrange - Download guest native-artifacts-1 evidence + uses: hoverkraft-tech/ci-github-common/actions/download-artifact@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.valid.outputs.report-artifact-id }},${{ + steps.invalid.outputs.report-artifact-id }},${{ + steps.empty.outputs.report-artifact-id }},${{ + steps.timeout.outputs.report-artifact-id }} + path: ${{ runner.temp }}/native-artifacts-1 + if: ${{ !cancelled() }} + - name: Assert - Check failed suites and independent native artifacts + id: verify-vm-test-guest if: ${{ !cancelled() && steps.vm.outcome == 'success' }} uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: + EVIDENCE_DIRECTORY: ${{ runner.temp }}/native-artifacts-1 INVALID: ${{ steps.invalid.outcome }} EMPTY: ${{ steps.empty.outcome }} TIMEOUT: ${{ steps.timeout.outcome }} BACKEND: ${{ matrix.backend }} + NEGATIVE_ARTIFACT_IDS: + ${{ steps.invalid.outputs.report-artifact-id }},${{ + steps.empty.outputs.report-artifact-id }},${{ + steps.timeout.outputs.report-artifact-id }} with: script: | const assert = require('node:assert/strict'); const { PublishedReports } = require('./tests/helpers/published-reports.cjs'); for (const outcome of [process.env.INVALID, process.env.EMPTY, process.env.TIMEOUT]) assert.equal(outcome, 'failure'); - const published = new PublishedReports(github, context); - const reports = await published.read('vm-test-', 4); - assert.equal(reports.filter(report => report.text.includes('failures="1"')).length, 3); + const published = new PublishedReports(context); + const reports = await published.read(4); + assert.equal(reports.filter(report => report.result.outcome === 'failure').length, 3); assert.ok(reports.some(report => report.text.includes('iac-missing-synthetic-file'))); - for (const name of ['invalid', 'empty', 'timeout']) - await published.comment(`Goss - ${process.env.BACKEND} - ${name}`); + core.setOutput('negative-fixtures', process.env.NEGATIVE_ARTIFACT_IDS); + - name: Cleanup - Discard vm-test guest negative results + if: steps.verify-vm-test-guest.outputs.negative-fixtures != '' + uses: hoverkraft-tech/ci-github-common/actions/quality/discard-report-fixtures@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + artifact-ids: ${{ steps.verify-vm-test-guest.outputs.negative-fixtures }} - name: Cleanup - Destroy VM if: ${{ always() && steps.vm.outputs.vm != '' }} uses: $/actions/vm/destroy diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 53467ea..f36c1a3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,7 +58,7 @@ checksum aligned with `tests/fixture/lima.yml`. The Lima version is maintained in `actions/vm/create/action.yml`. Keep the token scoped to this repository and the repository configuration in `.github/renovate.json`. Dependabot owns Actions, Dockerfile, Python and action -test-package updates. Its npm directory glob `/actions/*/*` matches the action +test-package updates. Its npm directory globs `/actions/*` and `/actions/*/*` match the action package layout used by `make test`; Renovate owns Lima, Goss, the documentation image and the action `.node-version` files, grouping Node.js runtime updates in one pull request. @@ -74,11 +74,12 @@ action-test workflows for actual VM behavior. PR CI verifies action outcomes across successful assertions, failed assertions and failed startup, without a consumer Makefile. It repeats tests on the same guest to verify independent reports, collects native Goss JUnit -after assertion failures, and verifies action-owned parsing, summaries and -artifact uploads. PR comments reuse stable titles; fork and Dependabot runs skip -comments. Tests inspect native report files and GitHub artifacts directly, and -check published summaries through PR comments when comments are enabled. -Consumer workflows grant comment permissions and always schedule cleanup. +after assertion failures, and verifies native byte preservation and the common +recording contract. The dedicated test workflows download result artifacts through +the shared action and check native content, checksums and private-data exclusion. +Verified negative fixture artifacts are deleted by the test harness before the +outer reporting job, so expected fixture failures do not become real CI findings. +Consumers always schedule infrastructure cleanup. Hosted scenarios are the primary checks for public action behavior. Unit tests call action modules directly where they add distinct coverage: input boundaries, process ownership, failed rollback or deletion, corrupted @@ -99,11 +100,13 @@ Each action owns a private `package.json`, lockfile, `.node-version` and `tests/ directory. Development dependencies supply the same Toolkit helpers injected by the pinned GitHub Script action; production scripts receive them from the caller. For example, run `npm --prefix actions/vm/create ci` followed by -`npm --prefix actions/vm/create test` for creation tests. Hosted unit jobs run -`npm run test:ci`: the `pretest:ci` hook creates the -coverage directory, then Node.js writes console results and `coverage/lcov.info`. -Generated coverage files are gitignored. `make test` discovers the action packages, -installs their locked test dependencies and runs each suite, stopping on failure. +`npm --prefix actions/vm/create test` for creation tests. Hosted unit jobs use +the Node test action's `node:test` preset, which configures native results and +coverage. Native arguments preserve each suite's coverage scope. +Generated coverage files are gitignored. `make setup` installs locked action +dependencies; `make test` runs each suite and stops on failure. `make build` runs +available build scripts. `make ci` installs, tests, checks generated distributions +when present and lints without applying fixes. Keep fixes in `make lint-fix`. Keep reusable test helpers in `tests/helpers/` and synthetic inputs in `tests/fixture/`. Keep single-use setup beside its tests; avoid adding test harnesses that parse action YAML or emulate the GitHub Script runtime. The public actions require no npm installation @@ -111,6 +114,9 @@ in consumer workflows. `__shared-ci.yml` runs the dedicated workflows: +`__test-actions-retain-native-reports.yml` verifies the shared retention action +through its entrypoint and checks the actual retained native artifact. + | Workflow in `.github/workflows/` | Action | Coverage | | ------------------------------------------ | ----------------------- | ----------------------------------------------------------------------------------- | | `__test-actions-ansible-test.yml` | `ansible/test` | Playbook and collection sanity success/failure, native reports | @@ -156,7 +162,8 @@ gh workflow run __release.yml --ref main ``` The release job authenticates with `CI_BOT_APP_CLIENT_ID` and -`CI_BOT_APP_PRIVATE_KEY`; `OPENAI_API_KEY` supplies release-summary generation. +`CI_BOT_APP_PRIVATE_KEY`; `CHANGELOG_SUMMARY` supplies the JSON provider +configuration for release-summary generation. These values can be provided through organization variables and secrets. The app needs repository contents write and pull request read permissions for publication. Its token allows the resulting tag push to trigger main CI. @@ -288,3 +295,28 @@ Reuse official setup and native execution, keeping only this reporting gap here. Renovate maintains the fixture's `.opentofu-version` and the adapter's Node version; Dependabot maintains the upstream setup Action. Generate its reference with `make docs`. + +## CI reporting ownership + +The VM, Ansible, Molecule and OpenTofu test actions register promised reports +before execution and finalize them through common `record-ci-reports`. Only +native outcomes are counted; execution and cleanup status stay on the producer. +No action posts its own CI comment or generic summary. Upstream Ansible sanity +keeps its own tool summary, while common owns the consolidated evidence view. + +One outer `ci-reports` publishes all evidence. A separate required `CI complete` +job uses common `check-jobs`, requiring every producer and reporting to succeed. +Native test failures can be reported successfully while the gate remains red. +No report-plan output or coverage inventory is forwarded between callers. + +The `actions/retain-native-reports` action owns `native-reports.cjs` and its +validation tests. It stages only regular +XML files into fresh recorder storage. It never retains environment directories, +VM state, secrets or raw command logs. Each action keeps resource cleanup in its +existing lifecycle, including after execution and reporting failures. + +Shared VM command and workspace helpers are measured by `vm/create`; runtime +ownership and cleanup are measured by `vm/destroy`. The native report staging +helper is measured by its owning `retain-native-reports` action. Other suites still test shared behavior without +submitting overlapping primary coverage for those same files. Explicit exclusions +keep maintained code in action directories named `test` measurable on Node 24. diff --git a/Makefile b/Makefile index fba35c7..af0eef6 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,17 @@ +GIT_COMMON_DIR := $(shell git rev-parse --path-format=absolute --git-common-dir) + SHELL := /bin/bash .DEFAULT_GOAL := help +.PHONY: help lint lint-fix docs setup test build check-distributions deps-audit ci + +ACTION_PACKAGES := $(sort $(patsubst %/package.json,%,$(shell find actions -name node_modules -prune -o -name dist -prune -o -name package.json -print))) HOST_UID := $(shell id -u) HOST_GID := $(shell id -g) -.PHONY: help lint-fix ci test lint docs help: ## Display help @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -test: ## Run unit tests - @set -eu; \ - for manifest in $(wildcard actions/*/*/package.json); do \ - npm --prefix "$${manifest%/package.json}" ci --ignore-scripts --no-audit --no-fund; \ - npm --prefix "$${manifest%/package.json}" test; \ - done - lint: ## Execute linting $(call run_linter,) @@ -30,10 +27,6 @@ lint-fix: ## Execute linting and fix -e FIX_SHELL_SHFMT=true \ ) -ci: ## Execute local CI tasks - $(MAKE) lint-fix - $(MAKE) test - docs: ## Generate action and public workflow documentation @set -eu; \ GITHUB_TOKEN="$$(gh auth token)"; \ @@ -48,6 +41,32 @@ docs: ## Generate action and public workflow documentation ############################# # Helpers ############################# +setup: ## Install locked action development dependencies + $(call run_npm_for_packages,ci --ignore-scripts --no-audit --no-fund) + +test: ## Run action source tests + $(call run_npm_for_packages,test) + +build: ## Rebuild action distributions where present + $(call run_npm_for_packages,run --if-present build) + +check-distributions: build ## Verify committed distributions match their source + @set -eu; changes="$$(git status --porcelain --untracked-files=all -- ':(glob)actions/**/dist/**')"; \ + if [ -n "$$changes" ]; then \ + printf '%s\n' "$$changes"; \ + echo 'Run make build and commit the generated distributions.' >&2; \ + exit 1; \ + fi + +deps-audit: ## Check action dependencies without changing lockfiles + $(call run_npm_for_packages,audit) + +ci: ## Install dependencies and run checks without applying fixes + $(MAKE) setup + $(MAKE) test + $(MAKE) check-distributions + $(MAKE) lint + define run_linter @set -eu; \ DEFAULT_WORKSPACE="$(CURDIR)"; \ @@ -58,10 +77,12 @@ define run_linter --build-arg UID=$(HOST_UID) --build-arg GID=$(HOST_GID) \ --tag "$$LINTER_IMAGE" .; \ docker run --platform=linux/amd64 \ + -v "$(GIT_COMMON_DIR):$(GIT_COMMON_DIR):ro" \ -v "$$VOLUME" --rm \ -e RUN_LOCAL=true \ -e DEFAULT_WORKSPACE="$$DEFAULT_WORKSPACE" \ -e DEFAULT_BRANCH="$$DEFAULT_BRANCH" \ + -e IGNORE_GITIGNORED_FILES=true \ -e USE_FIND_ALGORITHM=false \ -e FILTER_REGEX_INCLUDE="$(filter-out $@,$(MAKECMDGOALS))" \ -e 'FILTER_REGEX_EXCLUDE=/(\.cache|\.reports)/' \ @@ -76,3 +97,10 @@ ifneq ($(filter lint lint-fix,$(firstword $(MAKECMDGOALS))),) %: @: endif + +define run_npm_for_packages + @set -eu; \ + for directory in $(ACTION_PACKAGES); do \ + npm --prefix "$$directory" $(1); \ + done +endef diff --git a/README.md b/README.md index d677758..8574d64 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,12 @@ and publish GitHub summaries, annotations, PR comments and artifacts. Verify guest deletion before removing its private runtime and SSH keys. Failed cleanup remains visible and preserves the runtime for a retry. +### Reporting + +The [native report retention action](actions/retain-native-reports/README.md) +stages validated report files for the common reporting workflow. IaC test actions +invoke it as part of their normal execution. + ## Getting started For Ansible, check out your repository on a Linux runner. Pass its pinned diff --git a/actions/ansible/test-molecule/README.md b/actions/ansible/test-molecule/README.md index cf6813d..7d38cb6 100644 --- a/actions/ansible/test-molecule/README.md +++ b/actions/ansible/test-molecule/README.md @@ -13,16 +13,14 @@ [![Marketplace](https://img.shields.io/badge/Marketplace-ansible------test--molecule-blue?logo=github-actions)](https://github.com/marketplace/actions/ansible---test-molecule) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-iac)](https://github.com/hoverkraft-tech/ci-github-iac/releases) -[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-iac)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-iac/blob/main/CONTRIBUTING.md) ## Overview -Run native Molecule scenarios with native reports, PR comments and artifacts. +Run molecule tests and retain validated native evidence for consolidated CI reporting. Run a native Molecule scenario and publish its Ansible task reports. @@ -40,7 +38,6 @@ Use [ansible/test](../test/README.md) for test playbooks and collection sanity. molecule-scenario: tests/molecule/default ansible-requirements: requirements.txt python-version-file: .python-version - report-name: Ansible integration tests ``` Supply a directory containing `molecule.yml` with @@ -86,18 +83,12 @@ a scenario targeting an externally created VM must not destroy it itself. ### Publish results -Native task reports and a scenario status report are collected after failures. -Only JUnit files are published; inventory, runtime state and installed tools remain -private. Reports contain task results: use synthetic data and `no_log` for private values. - -Hoverkraft's report actions publish summaries, annotations and stable PR comments. -Grant `pull-requests: write` for comments; fork PR comments are skipped. -Never run untrusted tests through `pull_request_target`. Choose distinct report -names for separate scenarios. Reports are uploaded with a unique artifact name -and seven-day retention, including after parsing or commenting failures. -For consolidated comments, set `comment: false` and call the common `ci-reports` -workflow after all test jobs. Native report artifacts use the `ci-reports-` prefix -and the current run attempt, so earlier attempts cannot leak stale results. +Only native test outcomes are retained; no execution-status test is invented. +Runtime state, inventory, installed tools and raw logs stay private. Native +assertion details are public: use synthetic data and no_log for private values. +Call common publish-ci-reports once after all producers, then a separate CI complete +gate. Producers need contents: read and actions: read, without comment permissions. +Never execute untrusted tests via pull_request_target. @@ -115,7 +106,7 @@ and the current run attempt, so earlier attempts cannot leak stale results. # This input is required. ansible-requirements: "" - # Optional checkout-relative controller Python version file. Otherwise setup-python reads the root .python-version or uses the runner Python. For playbook or Molecule execution only; choose a version supported by the pinned tools. + # Controller Python version file for the pinned Molecule runtime. Empty uses the root .python-version, then the runner Python. python-version-file: "" # Optional checkout-relative ansible.cfg for scenario execution and collection search paths. @@ -124,14 +115,6 @@ and the current run attempt, so earlier attempts cannot leak stale results. # Native test sequence deadline, from 1 to 40 minutes. Interrupted runs allow two additional minutes for scenario cleanup. # Default: `20` test-timeout-minutes: "20" - - # Stable summary and PR comment title, distinct for each test step or matrix entry. - # Default: `Molecule test results` - report-name: Molecule test results - - # Publish an individual PR comment. Set false when using the shared ci-reports workflow; summaries, annotations and artifacts remain enabled. - # Default: `true` - comment: "true" ``` @@ -139,44 +122,33 @@ and the current run attempt, so earlier attempts cannot leak stale results. ## Inputs -| **Input** | **Description** | **Required** | **Default** | -| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------ | ----------------------- | -| **`molecule-scenario`** | Checkout-relative directory containing molecule.yml. The scenario defines its inventory, playbooks and test sequence. | **true** | - | -| **`ansible-requirements`** | Checkout-relative requirements file containing exactly one stable ansible-core==X.Y.Z pin. | **true** | - | -| **`python-version-file`** | Optional checkout-relative controller Python version file. Otherwise setup-python reads the root .python-version or uses the runner Python. For playbook or Molecule execution only; choose a version supported by the pinned tools. | **false** | - | -| **`ansible-config`** | Optional checkout-relative ansible.cfg for scenario execution and collection search paths. | **false** | - | -| **`test-timeout-minutes`** | Native test sequence deadline, from 1 to 40 minutes. Interrupted runs allow two additional minutes for scenario cleanup. | **false** | `20` | -| **`report-name`** | Stable summary and PR comment title, distinct for each test step or matrix entry. | **false** | `Molecule test results` | -| **`comment`** | Publish an individual PR comment. Set false when using the shared ci-reports workflow; summaries, annotations and artifacts remain enabled. | **false** | `true` | +| **Input** | **Description** | **Required** | **Default** | +| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------- | +| **`molecule-scenario`** | Checkout-relative directory containing molecule.yml. The scenario defines its inventory, playbooks and test sequence. | **true** | - | +| **`ansible-requirements`** | Checkout-relative requirements file containing exactly one stable ansible-core==X.Y.Z pin. | **true** | - | +| **`python-version-file`** | Controller Python version file for the pinned Molecule runtime. Empty uses the root .python-version, then the runner Python. | **false** | - | +| **`ansible-config`** | Optional checkout-relative ansible.cfg for scenario execution and collection search paths. | **false** | - | +| **`test-timeout-minutes`** | Native test sequence deadline, from 1 to 40 minutes. Interrupted runs allow two additional minutes for scenario cleanup. | **false** | `20` | + +## Outputs + +| **Output** | **Description** | +| ------------------------ | ------------------------------------------------------------------ | +| **`report-artifact-id`** | Native result artifact ID, discovered automatically by ci-reports. | + - -## Contributing - -Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-iac/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/ansible/test-molecule/action.yml b/actions/ansible/test-molecule/action.yml index e42e1a6..6d93e53 100644 --- a/actions/ansible/test-molecule/action.yml +++ b/actions/ansible/test-molecule/action.yml @@ -14,7 +14,6 @@ # molecule-scenario: tests/molecule/default # ansible-requirements: requirements.txt # python-version-file: .python-version -# report-name: Ansible integration tests # ``` # # Supply a directory containing `molecule.yml` with @@ -60,47 +59,49 @@ # # ### Publish results # -# Native task reports and a scenario status report are collected after failures. -# Only JUnit files are published; inventory, runtime state and installed tools remain -# private. Reports contain task results: use synthetic data and `no_log` for private values. -# -# Hoverkraft's report actions publish summaries, annotations and stable PR comments. -# Grant `pull-requests: write` for comments; fork PR comments are skipped. -# Never run untrusted tests through `pull_request_target`. Choose distinct report -# names for separate scenarios. Reports are uploaded with a unique artifact name -# and seven-day retention, including after parsing or commenting failures. -# For consolidated comments, set `comment: false` and call the common `ci-reports` -# workflow after all test jobs. Native report artifacts use the `ci-reports-` prefix -# and the current run attempt, so earlier attempts cannot leak stale results. +# Only native test outcomes are retained; no execution-status test is invented. +# Runtime state, inventory, installed tools and raw logs stay private. Native +# assertion details are public: use synthetic data and no_log for private values. +# Call common publish-ci-reports once after all producers, then a separate CI complete +# gate. Producers need contents: read and actions: read, without comment permissions. +# Never execute untrusted tests via pull_request_target. --- name: Ansible - Test Molecule -description: Run native Molecule scenarios with native reports, PR comments and artifacts. +description: Run molecule tests and retain validated native evidence for + consolidated CI reporting. author: Hoverkraft branding: icon: check-circle color: purple inputs: molecule-scenario: - description: Checkout-relative directory containing molecule.yml. The scenario defines its inventory, playbooks and test sequence. + description: + Checkout-relative directory containing molecule.yml. The scenario + defines its inventory, playbooks and test sequence. required: true ansible-requirements: - description: Checkout-relative requirements file containing exactly one stable ansible-core==X.Y.Z pin. + description: + Checkout-relative requirements file containing exactly one stable + ansible-core==X.Y.Z pin. required: true python-version-file: - description: Optional checkout-relative controller Python version file. Otherwise setup-python reads the root .python-version or uses the runner Python. For playbook or Molecule execution only; choose a version supported by the pinned tools. + description: Controller Python version file for the pinned Molecule runtime. + Empty uses the root .python-version, then the runner Python. default: "" ansible-config: - description: Optional checkout-relative ansible.cfg for scenario execution and collection search paths. + description: + Optional checkout-relative ansible.cfg for scenario execution and + collection search paths. default: "" test-timeout-minutes: - description: Native test sequence deadline, from 1 to 40 minutes. Interrupted runs allow two additional minutes for scenario cleanup. + description: + Native test sequence deadline, from 1 to 40 minutes. Interrupted + runs allow two additional minutes for scenario cleanup. default: "20" - report-name: - description: Stable summary and PR comment title, distinct for each test step or matrix entry. - default: Molecule test results - comment: - description: Publish an individual PR comment. Set false when using the shared ci-reports workflow; summaries, annotations and artifacts remain enabled. - default: "true" +outputs: + report-artifact-id: + description: Native result artifact ID, discovered automatically by ci-reports. + value: ${{ steps.reports.outputs.artifact-id }} runs: using: composite steps: @@ -174,31 +175,14 @@ runs: core.setFailed(error.message); } - - name: Parse scenario reports - if: ${{ always() && steps.scenario-reports.outputs.report-files != '' }} - id: parse-scenario-reports - uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 - with: - report-name: ${{ inputs.report-name }} - report-paths: ${{ steps.scenario-reports.outputs.report-files }} - path-mapping: ${{ github.workspace }}:. - output-format: summary,markdown,annotations - - - name: Add scenario PR comment - if: >- - ${{ always() && inputs.comment == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && steps.parse-scenario-reports.outputs.markdown != '' }} - uses: hoverkraft-tech/ci-github-common/actions/create-or-update-comment@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 - with: - title: ${{ inputs.report-name }} - body: ${{ steps.parse-scenario-reports.outputs.markdown }} - token: ${{ github.token }} - - - name: Upload scenario reports - if: ${{ always() && steps.scenario-reports.outputs.report-files != '' }} - id: upload-scenario-reports - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + - name: Retain Molecule native evidence + id: reports + if: ${{ !cancelled() && steps.scenario-inputs.outcome == 'success' }} + uses: $/actions/retain-native-reports with: - name: ci-reports-${{ github.run_attempt }}-${{ github.job }}-${{ steps.scenario-inputs.outputs.id }} - path: ${{ steps.scenario-reports.outputs.report-files }} - if-no-files-found: error - retention-days: 7 + outcome: ${{ steps.scenario-execution.outcome == 'success' && + steps.scenario-reports.outcome == 'success' && 'success' || 'failure' + }} + files: ${{ steps.scenario-reports.outputs.report-files }} + definition: '{"name":"Molecule + tests","reports":[{"kind":"test","pattern":"*.xml"}]}' diff --git a/actions/ansible/test-molecule/molecule.cjs b/actions/ansible/test-molecule/molecule.cjs index 8fdc1e9..4e289e4 100644 --- a/actions/ansible/test-molecule/molecule.cjs +++ b/actions/ansible/test-molecule/molecule.cjs @@ -89,9 +89,7 @@ class MoleculeScenario { ? await this.execute("destroy", "2m").catch(() => null) : 0; const cleanupFailed = cleanup !== 0; - const native = (await this.reportFiles()).filter( - (file) => path.basename(file) !== "scenario.xml", - ); + const native = await this.reportFiles(); const hasAssertions = native.some((file) => /]/.test(fs.readFileSync(file, "utf8")), ); @@ -99,11 +97,6 @@ class MoleculeScenario { const message = cleanupFailed ? "Molecule was interrupted and scenario cleanup failed" : "Molecule failed, timed out or produced no native assertions"; - fs.writeFileSync( - path.join(this.directory, "scenario.xml"), - `${failed ? `` : ""}\n`, - { flag: "wx" }, - ); if (failed) throw new Error(`${message}; inspect the scenario reports`); } } diff --git a/actions/ansible/test-molecule/package.json b/actions/ansible/test-molecule/package.json index c846950..5c89b8e 100644 --- a/actions/ansible/test-molecule/package.json +++ b/actions/ansible/test-molecule/package.json @@ -8,9 +8,7 @@ "node": ">=24.8.0" }, "scripts": { - "test": "node --test", - "pretest:ci": "node -e \"require('node:fs').mkdirSync('coverage', { recursive: true })\"", - "test:ci": "node --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test" + "test": "node --test" }, "devDependencies": { "@actions/exec": "3.0.0", diff --git a/actions/ansible/test-molecule/tests/molecule.test.mjs b/actions/ansible/test-molecule/tests/molecule.test.mjs index 602faab..15951cf 100644 --- a/actions/ansible/test-molecule/tests/molecule.test.mjs +++ b/actions/ansible/test-molecule/tests/molecule.test.mjs @@ -1,12 +1,12 @@ -import { suite, test } from "node:test"; -import { MoleculeInputs } from "../inputs.cjs"; -import { MoleculeScenario } from "../molecule.cjs"; -import fs from "node:fs"; -import path from "node:path"; import assert from "node:assert/strict"; +import fs from "node:fs"; import os from "node:os"; +import path from "node:path"; +import { suite, test } from "node:test"; import * as execToolkit from "@actions/exec"; import * as glob from "@actions/glob"; +import { MoleculeInputs } from "../inputs.cjs"; +import { MoleculeScenario } from "../molecule.cjs"; // Copy the ESM namespace so tests can mock the injected helper. const exec = { ...execToolkit }; @@ -192,10 +192,7 @@ suite("ansible/test-molecule", () => { "--scenario-name", "default", ]); - assert.match( - fs.readFileSync(path.join(directory, "scenario.xml"), "utf8"), - /failures="1"/, - ); + assert.equal(fs.existsSync(path.join(directory, "scenario.xml")), false); }); test("Molecule cannot succeed with empty or redirected native assertions", async (t) => { diff --git a/actions/ansible/test/README.md b/actions/ansible/test/README.md index 51ee9de..b94d350 100644 --- a/actions/ansible/test/README.md +++ b/actions/ansible/test/README.md @@ -13,16 +13,14 @@ [![Marketplace](https://img.shields.io/badge/Marketplace-ansible------test-blue?logo=github-actions)](https://github.com/marketplace/actions/ansible---test) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-iac)](https://github.com/hoverkraft-tech/ci-github-iac/releases) -[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-iac)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-iac/blob/main/CONTRIBUTING.md) ## Overview -Run Ansible test playbooks and collection sanity with native reports, PR comments and artifacts. +Run Ansible tests and retain validated native evidence for consolidated CI reporting. Run Ansible tests with maintained upstream actions and native JUnit reports. @@ -69,70 +67,48 @@ collection job so native `tests/output/junit` contains only that run's reports. ### Publish results -Hoverkraft's `parse-ci-reports` publishes native JUnit as summaries, annotations -and a stable PR comment. Test output and task results appear in these reports; -use synthetic data suitable for the repository's visibility. The collection -action also publishes its own summary. - -Report collection runs after upstream failures, including when the upstream -action does not export its report output. Reports are uploaded with a unique -artifact name and seven-day retention, including after parsing or commenting -errors. Missing reports fail the action. Failed tests remain failures. No custom -test runner or Docker lifecycle is maintained here. - -Grant `pull-requests: write` for comments. Fork PR comments are skipped. -Never run untrusted tests through `pull_request_target`. Use distinct report names -for matrix entries. -For consolidated comments, set `comment: false` and call the common `ci-reports` -workflow after all test jobs. Native report artifacts use the `ci-reports-` prefix -and the current run attempt, so earlier attempts cannot leak stale results. +Native JUnit is validated and retained through common prepare-ci-reports. +Use synthetic expectations: native reports may contain assertion details. +Call ci-reports once after every producer and add a separate CI complete gate. +Producers need contents: read and actions: read, without comment permissions. +Upstream collection sanity owns its diagnostic summary. It does not create +the consolidated report or comment. Never use pull_request_target for tests. ## Inputs -| **Input** | **Description** | **Required** | **Default** | -| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------ | ---------------------- | -| **`ansible-requirements`** | Checkout-relative requirements file containing exactly one stable ansible-core==X.Y.Z pin. | **true** | - | -| **`test-playbook`** | Checkout-relative playbook containing test assertions. This playbook is executed. Supply test-playbook or collection, exclusively. | **false** | - | -| **`collection`** | One checked-out collection directory containing galaxy.yml. Use a matrix for multiple collections. | **false** | - | -| **`target-python-version`** | Optional Python major.minor for collection sanity checks. Empty tests all versions supported by Ansible Core. | **false** | - | -| **`sanity-image`** | Optional pinned Docker image for collection sanity. Requires target-python-version; empty uses Ansible Core's default image and Python matrix. | **false** | - | -| **`python-version-file`** | Optional checkout-relative controller Python version file. Otherwise setup-python reads the root .python-version or uses the runner Python. For playbook or Molecule execution only; choose a version supported by the pinned tools. | **false** | - | -| **`ansible-config`** | Optional checkout-relative ansible.cfg file for test playbook execution. | **false** | - | -| **`galaxy-requirements`** | Optional checkout-relative Galaxy requirements file for third-party role and collection dependencies. | **false** | - | -| **`report-name`** | Stable summary and PR comment title, distinct for each test step or matrix entry. | **false** | `Ansible test results` | -| **`comment`** | Publish an individual PR comment. Set false when using the shared ci-reports workflow; summaries, annotations and artifacts remain enabled. | **false** | `true` | +| **Input** | **Description** | **Required** | **Default** | +| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------ | ----------- | +| **`ansible-requirements`** | Checkout-relative requirements file containing exactly one stable ansible-core==X.Y.Z pin. | **true** | - | +| **`test-playbook`** | Checkout-relative playbook containing test assertions. This playbook is executed. Supply test-playbook or collection, exclusively. | **false** | - | +| **`collection`** | One checked-out collection directory containing galaxy.yml. Use a matrix for multiple collections. | **false** | - | +| **`target-python-version`** | Optional Python major.minor for collection sanity checks. Empty tests all versions supported by Ansible Core. | **false** | - | +| **`sanity-image`** | Optional pinned Docker image for collection sanity. Requires target-python-version; empty uses Ansible Core's default image and Python matrix. | **false** | - | +| **`python-version-file`** | Optional checkout-relative controller Python version file. Otherwise setup-python reads the root .python-version or uses the runner Python. For playbook or Molecule execution only; choose a version supported by the pinned tools. | **false** | - | +| **`ansible-config`** | Optional checkout-relative ansible.cfg file for test playbook execution. | **false** | - | +| **`galaxy-requirements`** | Optional checkout-relative Galaxy requirements file for third-party role and collection dependencies. | **false** | - | + +## Outputs + +| **Output** | **Description** | +| ------------------------ | ------------------------------------------------------------------ | +| **`report-artifact-id`** | Native result artifact ID, discovered automatically by ci-reports. | + - -## Contributing - -Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-iac/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/). - @@ -172,14 +148,6 @@ This documentation was automatically generated by [CI Dokumentor](https://github # Optional checkout-relative Galaxy requirements file for third-party role and collection dependencies. galaxy-requirements: "" - - # Stable summary and PR comment title, distinct for each test step or matrix entry. - # Default: `Ansible test results` - report-name: Ansible test results - - # Publish an individual PR comment. Set false when using the shared ci-reports workflow; summaries, annotations and artifacts remain enabled. - # Default: `true` - comment: "true" ``` diff --git a/actions/ansible/test/action.yml b/actions/ansible/test/action.yml index c795686..3cfcf7a 100644 --- a/actions/ansible/test/action.yml +++ b/actions/ansible/test/action.yml @@ -43,61 +43,62 @@ # # ### Publish results # -# Hoverkraft's `parse-ci-reports` publishes native JUnit as summaries, annotations -# and a stable PR comment. Test output and task results appear in these reports; -# use synthetic data suitable for the repository's visibility. The collection -# action also publishes its own summary. -# -# Report collection runs after upstream failures, including when the upstream -# action does not export its report output. Reports are uploaded with a unique -# artifact name and seven-day retention, including after parsing or commenting -# errors. Missing reports fail the action. Failed tests remain failures. No custom -# test runner or Docker lifecycle is maintained here. -# -# Grant `pull-requests: write` for comments. Fork PR comments are skipped. -# Never run untrusted tests through `pull_request_target`. Use distinct report names -# for matrix entries. -# For consolidated comments, set `comment: false` and call the common `ci-reports` -# workflow after all test jobs. Native report artifacts use the `ci-reports-` prefix -# and the current run attempt, so earlier attempts cannot leak stale results. +# Native JUnit is validated and retained through common prepare-ci-reports. +# Use synthetic expectations: native reports may contain assertion details. +# Call ci-reports once after every producer and add a separate CI complete gate. +# Producers need contents: read and actions: read, without comment permissions. +# Upstream collection sanity owns its diagnostic summary. It does not create +# the consolidated report or comment. Never use pull_request_target for tests. --- name: Ansible - Test -description: Run Ansible test playbooks and collection sanity with native reports, PR comments and artifacts. +description: Run Ansible tests and retain validated native evidence for + consolidated CI reporting. author: Hoverkraft branding: icon: check-circle color: purple inputs: ansible-requirements: - description: Checkout-relative requirements file containing exactly one stable ansible-core==X.Y.Z pin. + description: + Checkout-relative requirements file containing exactly one stable + ansible-core==X.Y.Z pin. required: true test-playbook: - description: Checkout-relative playbook containing test assertions. This playbook is executed. Supply test-playbook or collection, exclusively. + description: Checkout-relative playbook containing test assertions. This + playbook is executed. Supply test-playbook or collection, exclusively. default: "" collection: - description: One checked-out collection directory containing galaxy.yml. Use a matrix for multiple collections. + description: + One checked-out collection directory containing galaxy.yml. Use a + matrix for multiple collections. default: "" target-python-version: - description: Optional Python major.minor for collection sanity checks. Empty tests all versions supported by Ansible Core. + description: Optional Python major.minor for collection sanity checks. Empty + tests all versions supported by Ansible Core. default: "" sanity-image: - description: Optional pinned Docker image for collection sanity. Requires target-python-version; empty uses Ansible Core's default image and Python matrix. + description: Optional pinned Docker image for collection sanity. Requires + target-python-version; empty uses Ansible Core's default image and Python + matrix. default: "" python-version-file: - description: Optional checkout-relative controller Python version file. Otherwise setup-python reads the root .python-version or uses the runner Python. For playbook or Molecule execution only; choose a version supported by the pinned tools. + description: Optional checkout-relative controller Python version file. + Otherwise setup-python reads the root .python-version or uses the runner + Python. For playbook or Molecule execution only; choose a version + supported by the pinned tools. default: "" ansible-config: description: Optional checkout-relative ansible.cfg file for test playbook execution. default: "" galaxy-requirements: - description: Optional checkout-relative Galaxy requirements file for third-party role and collection dependencies. + description: + Optional checkout-relative Galaxy requirements file for third-party + role and collection dependencies. default: "" - report-name: - description: Stable summary and PR comment title, distinct for each test step or matrix entry. - default: Ansible test results - comment: - description: Publish an individual PR comment. Set false when using the shared ci-reports workflow; summaries, annotations and artifacts remain enabled. - default: "true" +outputs: + report-artifact-id: + description: Native result artifact ID, discovered automatically by ci-reports. + value: ${{ steps.reports.outputs.artifact-id }} runs: using: composite steps: @@ -144,6 +145,7 @@ runs: core.addPath(path.join(runtime, 'bin')); - name: Execute Ansible test playbook + id: playbook if: steps.inputs.outputs.mode == 'playbook' uses: dawidd6/action-ansible-playbook@126642a1c6ce512da255ef2b41e8ee90f0077474 # v9 env: @@ -167,7 +169,8 @@ runs: collection-root: ${{ steps.inputs.outputs.collection-root }} target-python-version: ${{ steps.inputs.outputs.target-python-version }} docker-image: ${{ steps.inputs.outputs.sanity-image }} - test-deps: ${{ steps.inputs.outputs.galaxy != '' && format('-r {0}', steps.inputs.outputs.galaxy) || '' }} + test-deps: ${{ steps.inputs.outputs.galaxy != '' && format('-r {0}', + steps.inputs.outputs.galaxy) || '' }} coverage: never - name: Collect native Ansible reports @@ -177,7 +180,8 @@ runs: env: ACTION_PATH: ${{ github.action_path }} ANSIBLE_REPORT_DIRECTORY: ${{ steps.inputs.outputs.report-directory }} - ANSIBLE_COLLECTION_ROOT: ${{ steps.sanity.outputs.checkout-directory || steps.inputs.outputs.collection }} + ANSIBLE_COLLECTION_ROOT: ${{ steps.sanity.outputs.checkout-directory || + steps.inputs.outputs.collection }} with: script: | try { @@ -187,31 +191,16 @@ runs: core.setFailed(error.message); } - - name: Parse Ansible reports - if: ${{ always() && steps.collect.outputs.report-files != '' }} - id: parse - uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 - with: - report-name: ${{ inputs.report-name }} - report-paths: ${{ steps.collect.outputs.report-files }} - path-mapping: ${{ github.workspace }}:. - output-format: summary,markdown,annotations - - - name: Add Ansible PR comment - if: >- - ${{ always() && inputs.comment == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && steps.parse.outputs.markdown != '' }} - uses: hoverkraft-tech/ci-github-common/actions/create-or-update-comment@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 - with: - title: ${{ inputs.report-name }} - body: ${{ steps.parse.outputs.markdown }} - token: ${{ github.token }} - - - name: Upload Ansible reports - if: ${{ always() && steps.collect.outputs.report-files != '' }} - id: upload - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + - name: Retain Ansible native evidence + id: reports + if: ${{ !cancelled() && steps.inputs.outcome == 'success' }} + uses: $/actions/retain-native-reports with: - name: ci-reports-${{ github.run_attempt }}-${{ github.job }}-${{ steps.inputs.outputs.id }} - path: ${{ steps.collect.outputs.report-files }} - if-no-files-found: error - retention-days: 7 + outcome: + ${{ (steps.inputs.outputs.mode == 'playbook' && steps.playbook.outcome + == 'success' || steps.inputs.outputs.mode == 'sanity' && + steps.sanity.outcome == 'success') && steps.collect.outcome == + 'success' && 'success' || 'failure' }} + files: ${{ steps.collect.outputs.report-files }} + definition: '{"name":"Ansible + tests","reports":[{"kind":"test","pattern":"*.xml"}]}' diff --git a/actions/ansible/test/package.json b/actions/ansible/test/package.json index 6cbba8e..1db4f78 100644 --- a/actions/ansible/test/package.json +++ b/actions/ansible/test/package.json @@ -8,9 +8,7 @@ "node": ">=24.8.0" }, "scripts": { - "test": "node --test", - "pretest:ci": "node -e \"require('node:fs').mkdirSync('coverage', { recursive: true })\"", - "test:ci": "node --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test" + "test": "node --test" }, "devDependencies": { "@actions/glob": "0.7.0" diff --git a/actions/opentofu/test/README.md b/actions/opentofu/test/README.md index bcab524..42cc878 100644 --- a/actions/opentofu/test/README.md +++ b/actions/opentofu/test/README.md @@ -13,16 +13,14 @@ [![Marketplace](https://img.shields.io/badge/Marketplace-opentofu------test-blue?logo=github-actions)](https://github.com/marketplace/actions/opentofu---test) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-iac)](https://github.com/hoverkraft-tech/ci-github-iac/releases) -[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-iac)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-iac/blob/main/CONTRIBUTING.md) ## Overview -Run native OpenTofu tests with the official runtime, summaries, JUnit artifacts and optional PR comments. +Run opentofu tests and retain validated native evidence for consolidated CI reporting. Run native OpenTofu tests and publish their results through Hoverkraft reporting. @@ -45,10 +43,12 @@ variable values and raw event streams are never uploaded. Failures, empty suites incomplete reports and cleanup errors remain failures. Use synthetic fixtures; test names and filenames are public report metadata. -Reports are parsed as summaries and annotations and retained for seven days, -including after test failures. Set `comment: false` with the common `ci-reports` -workflow to consolidate results. Individual comments require `pull-requests: write` -and are skipped for fork PRs. Never execute untrusted tests via pull_request_target. +Only native test outcomes are retained; no execution-status test is invented. +Runtime state, inventory, installed tools and raw logs stay private. Native +assertion details are public: use synthetic data and no_log for private values. +Call common publish-ci-reports once after all producers, then a separate CI complete +gate. Producers need contents: read and actions: read, without comment permissions. +Never execute untrusted tests via pull_request_target. @@ -65,14 +65,6 @@ and are skipped for fork PRs. Never execute untrusted tests via pull_request_tar # Checkout-relative file containing an exact stable OpenTofu version maintained by the consumer. # This input is required. tofu-version-file: "" - - # Stable report title, distinct for each test step or matrix entry. - # Default: `OpenTofu test results` - report-name: OpenTofu test results - - # Publish an individual PR comment. Set false when using the shared ci-reports workflow. - # Default: `true` - comment: "true" ``` @@ -80,41 +72,30 @@ and are skipped for fork PRs. Never execute untrusted tests via pull_request_tar ## Inputs -| **Input** | **Description** | **Required** | **Default** | -| ----------------------- | ---------------------------------------------------------------------------------------------- | ------------ | ----------------------- | -| **`working-directory`** | Checkout-relative module directory containing native OpenTofu tests. | **true** | - | -| **`tofu-version-file`** | Checkout-relative file containing an exact stable OpenTofu version maintained by the consumer. | **true** | - | -| **`report-name`** | Stable report title, distinct for each test step or matrix entry. | **false** | `OpenTofu test results` | -| **`comment`** | Publish an individual PR comment. Set false when using the shared ci-reports workflow. | **false** | `true` | +| **Input** | **Description** | **Required** | **Default** | +| ----------------------- | ---------------------------------------------------------------------------------------------- | ------------ | ----------- | +| **`working-directory`** | Checkout-relative module directory containing native OpenTofu tests. | **true** | - | +| **`tofu-version-file`** | Checkout-relative file containing an exact stable OpenTofu version maintained by the consumer. | **true** | - | + +## Outputs + +| **Output** | **Description** | +| ------------------------ | ------------------------------------------------------------------ | +| **`report-artifact-id`** | Native result artifact ID, discovered automatically by ci-reports. | + - -## Contributing - -Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-iac/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/opentofu/test/action.yml b/actions/opentofu/test/action.yml index f2bec38..564e263 100644 --- a/actions/opentofu/test/action.yml +++ b/actions/opentofu/test/action.yml @@ -19,13 +19,16 @@ # incomplete reports and cleanup errors remain failures. Use synthetic fixtures; # test names and filenames are public report metadata. # -# Reports are parsed as summaries and annotations and retained for seven days, -# including after test failures. Set `comment: false` with the common `ci-reports` -# workflow to consolidate results. Individual comments require `pull-requests: write` -# and are skipped for fork PRs. Never execute untrusted tests via pull_request_target. +# Only native test outcomes are retained; no execution-status test is invented. +# Runtime state, inventory, installed tools and raw logs stay private. Native +# assertion details are public: use synthetic data and no_log for private values. +# Call common publish-ci-reports once after all producers, then a separate CI complete +# gate. Producers need contents: read and actions: read, without comment permissions. +# Never execute untrusted tests via pull_request_target. --- name: OpenTofu - Test -description: Run native OpenTofu tests with the official runtime, summaries, JUnit artifacts and optional PR comments. +description: Run opentofu tests and retain validated native evidence for + consolidated CI reporting. author: Hoverkraft branding: icon: check-circle @@ -35,14 +38,14 @@ inputs: description: Checkout-relative module directory containing native OpenTofu tests. required: true tofu-version-file: - description: Checkout-relative file containing an exact stable OpenTofu version maintained by the consumer. + description: + Checkout-relative file containing an exact stable OpenTofu version + maintained by the consumer. required: true - report-name: - description: Stable report title, distinct for each test step or matrix entry. - default: OpenTofu test results - comment: - description: Publish an individual PR comment. Set false when using the shared ci-reports workflow. - default: "true" +outputs: + report-artifact-id: + description: Native result artifact ID, discovered automatically by ci-reports. + value: ${{ steps.reports.outputs.artifact-id }} runs: using: composite steps: @@ -70,6 +73,7 @@ runs: if (!directory && !/^\d+\.\d+\.\d+$/.test(fs.readFileSync(resolved, 'utf8').trim())) throw new Error('Pin one stable OpenTofu release in tofu-version-file'); core.setOutput(name, resolved); + if (directory) core.setOutput('project', path.relative(root, resolved) || '.'); } const reports = fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, 'opentofu-test-')); core.setOutput('directory', reports); @@ -82,7 +86,7 @@ runs: tofu_wrapper: false - name: Run native OpenTofu tests - id: test + id: opentofu-tests uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: ACTION_PATH: ${{ github.action_path }} @@ -95,32 +99,15 @@ runs: const { OpenTofuTests } = require(`${process.env.ACTION_PATH}/opentofu.cjs`); await new OpenTofuTests(core, exec).run(process.env.MODULE_PATH, process.env.REPORT_DIRECTORY); - - name: Parse OpenTofu reports - id: parse - if: ${{ !cancelled() && steps.test.outputs.report != '' }} - uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 + - name: Retain OpenTofu native evidence + id: reports + if: ${{ !cancelled() && steps.inputs.outcome == 'success' }} + uses: $/actions/retain-native-reports with: - report-name: ${{ inputs.report-name }} - report-paths: ${{ steps.test.outputs.report }} - output-format: summary,markdown,annotations - - # Standard standalone-action comment publication shared by test actions. - # jscpd:ignore-start - - name: Add OpenTofu PR comment - if: >- - ${{ !cancelled() && inputs.comment == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && steps.parse.outputs.markdown != '' }} - uses: hoverkraft-tech/ci-github-common/actions/create-or-update-comment@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 - with: - title: ${{ inputs.report-name }} - body: ${{ steps.parse.outputs.markdown }} - token: ${{ github.token }} - # jscpd:ignore-end - - - name: Upload OpenTofu reports - if: ${{ !cancelled() && steps.test.outputs.report != '' }} - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: ci-reports-${{ github.run_attempt }}-${{ github.job }}-${{ steps.inputs.outputs.id }} - path: ${{ steps.test.outputs.report }} - if-no-files-found: error - retention-days: 7 + outcome: + ${{ steps.opentofu-tests.outcome == 'success' && 'success' || 'failure' + }} + files: ${{ steps.opentofu-tests.outputs.report }} + definition: ${{ format('{{"name":"OpenTofu + tests","project":{0},"reports":[{{"kind":"test","pattern":"*.xml"}}]}}', + toJSON(steps.inputs.outputs.project)) }} diff --git a/actions/opentofu/test/opentofu.cjs b/actions/opentofu/test/opentofu.cjs index 2b4ed24..fbc573c 100644 --- a/actions/opentofu/test/opentofu.cjs +++ b/actions/opentofu/test/opentofu.cjs @@ -44,15 +44,6 @@ class OpenTofuReport { summary.passed > 0 && summary.failed === 0 && summary.errored === 0; - if ( - !passed && - !cases.some((item) => ["fail", "error"].includes(item.status)) - ) - cases.push({ - file: "OpenTofu", - name: "execution-and-cleanup", - status: "error", - }); return new OpenTofuReport(cases, passed); } @@ -135,10 +126,12 @@ class OpenTofuTests { code, ); } catch { - result = new OpenTofuReport([ - { file: "OpenTofu", name: "execution-and-reporting", status: "error" }, - ]); + this.core.setFailed( + "OpenTofu initialization or native report collection failed.", + ); + return; } + const report = path.join(reports, "opentofu.junit.xml"); fs.writeFileSync(report, result.xml, { mode: 0o600, flag: "wx" }); this.core.setOutput("report", report); diff --git a/actions/opentofu/test/package.json b/actions/opentofu/test/package.json index 8f52e97..b4ea243 100644 --- a/actions/opentofu/test/package.json +++ b/actions/opentofu/test/package.json @@ -8,8 +8,6 @@ "node": ">=24.8.0" }, "scripts": { - "test": "node --test", - "pretest:ci": "node -e \"require('node:fs').mkdirSync('coverage', { recursive: true })\"", - "test:ci": "node --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test" + "test": "node --test" } } diff --git a/actions/opentofu/test/tests/reports.test.cjs b/actions/opentofu/test/tests/reports.test.cjs index 05bcb78..1605669 100644 --- a/actions/opentofu/test/tests/reports.test.cjs +++ b/actions/opentofu/test/tests/reports.test.cjs @@ -57,8 +57,8 @@ suite("Native OpenTofu reporting boundaries", () => { const result = OpenTofuReport.parse(events, 1); // Assert assert.equal(result.passed, false); - assert.match(result.xml, /execution-and-cleanup/); - assert.match(result.xml, /errors="1"/); + assert.doesNotMatch(result.xml, /execution-and-cleanup/); + assert.match(result.xml, /errors="0"/); }); for (const [name, events] of [ diff --git a/actions/retain-native-reports/.node-version b/actions/retain-native-reports/.node-version new file mode 100644 index 0000000..a45fd52 --- /dev/null +++ b/actions/retain-native-reports/.node-version @@ -0,0 +1 @@ +24 diff --git a/actions/retain-native-reports/README.md b/actions/retain-native-reports/README.md new file mode 100644 index 0000000..e29d6aa --- /dev/null +++ b/actions/retain-native-reports/README.md @@ -0,0 +1,80 @@ + + +# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItZmlsZS10ZXh0IiBjb2xvcj0iYmx1ZSI+PHBhdGggZD0iTTE0IDJINmEyIDIgMCAwIDAtMiAydjE2YTIgMiAwIDAgMCAyIDJoMTJhMiAyIDAgMCAwIDItMlY4eiI+PC9wYXRoPjxwb2x5bGluZSBwb2ludHM9IjE0IDIgMTQgOCAyMCA4Ij48L3BvbHlsaW5lPjxsaW5lIHgxPSIxNiIgeTE9IjEzIiB4Mj0iOCIgeTI9IjEzIj48L2xpbmU+PGxpbmUgeDE9IjE2IiB5MT0iMTciIHgyPSI4IiB5Mj0iMTciPjwvbGluZT48cG9seWxpbmUgcG9pbnRzPSIxMCA5IDkgOSA4IDkiPjwvcG9seWxpbmU+PC9zdmc+) GitHub Action: Retain native IaC reports + + + + +[![Marketplace](https://img.shields.io/badge/Marketplace-retain--native--iac--reports-blue?logo=github-actions)](https://github.com/marketplace/actions/retain-native-iac-reports) +[![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-iac)](https://github.com/hoverkraft-tech/ci-github-iac/releases) +[![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social) + + + + +## Overview + +Stage only bounded native XML files and finalize the common report contract. + +IaC producers use this action to stage native XML in fresh report storage. +The common reporting workflow owns consolidated publication. + + + + +## Usage + +```yaml +- uses: hoverkraft-tech/ci-github-iac/actions/retain-native-reports@4f5767a550308912c4b0d717eefefaae95bc85e9 # refactor/unified-ci-reporting + with: + # Newline-separated native report paths selected by the producer. + # This input is required. + files: "" + + # Producer execution outcome. + # This input is required. + outcome: "" + + # JSON report definition provided by the producer. + # This input is required. + definition: "" +``` + + + + +## Inputs + +| **Input** | **Description** | **Required** | **Default** | +| ---------------- | --------------------------------------------------------------- | ------------ | ----------- | +| **`files`** | Newline-separated native report paths selected by the producer. | **true** | - | +| **`outcome`** | Producer execution outcome. | **true** | - | +| **`definition`** | JSON report definition provided by the producer. | **true** | - | + + + + + + +## Outputs + +| **Output** | **Description** | +| ----------------- | -------------------------------- | +| **`artifact-id`** | Retained native result artifact. | + + + + + + + + + + + + +--- + +This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor). + + diff --git a/actions/retain-native-reports/action.yml b/actions/retain-native-reports/action.yml new file mode 100644 index 0000000..50e3732 --- /dev/null +++ b/actions/retain-native-reports/action.yml @@ -0,0 +1,54 @@ +# IaC producers use this action to stage native XML in fresh report storage. +# The common reporting workflow owns consolidated publication. +name: Retain native IaC reports +description: Stage only bounded native XML files and finalize the common report contract. +author: Hoverkraft +branding: + icon: file-text + color: blue +inputs: + files: + description: Newline-separated native report paths selected by the producer. + required: true + outcome: + description: Producer execution outcome. + required: true + definition: + description: JSON report definition provided by the producer. + required: true +outputs: + artifact-id: + description: Retained native result artifact. + value: ${{ steps.reports.outputs.artifact-id }} +runs: + using: composite + steps: + - id: stage + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + ACTION_PATH: ${{ github.action_path }} + NATIVE_REPORTS: ${{ inputs.files }} + with: + script: | + const fs = require('node:fs'); + const path = require('node:path'); + const { stageNativeReports } = require(path.resolve(process.env.ACTION_PATH, 'native-reports.cjs')); + const directory = fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, 'iac-reports-')); + core.setOutput('directory', directory); + stageNativeReports(process.env.NATIVE_REPORTS.split(/\r?\n/).filter(Boolean), directory); + - id: reports + if: ${{ !cancelled() }} + uses: hoverkraft-tech/ci-github-common/actions/quality/prepare-ci-reports@26f3d6878844ec53849eec6ac75af8d14ea402e9 # 5.0.0 + with: + definition: ${{ inputs.definition }} + directory: ${{ steps.stage.outputs.directory }} + outcome: + ${{ inputs.outcome == 'success' && steps.stage.outcome == 'success' && + 'success' || 'failure' }} + - name: Clean retained report staging + if: ${{ always() && steps.stage.outputs.directory != '' }} + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + REPORT_DIRECTORY: ${{ steps.stage.outputs.directory }} + with: + script: await io.rmRF(process.env.REPORT_DIRECTORY); diff --git a/actions/retain-native-reports/native-reports.cjs b/actions/retain-native-reports/native-reports.cjs new file mode 100644 index 0000000..0782ee1 --- /dev/null +++ b/actions/retain-native-reports/native-reports.cjs @@ -0,0 +1,28 @@ +const fs = require("node:fs"); +const path = require("node:path"); + +// Copy only verified native files into the recorder's fresh private directory. +// Runtime environments, VM state and raw command logs are never staged. +function stageNativeReports(files, destination) { + const root = fs.realpathSync(destination); + if (!fs.statSync(root).isDirectory() || fs.readdirSync(root).length) + throw new Error("Native report destination must be an empty directory."); + for (const source of [...new Set(files)]) { + const info = fs.lstatSync(source); + if ( + !info.isFile() || + fs.realpathSync(source) !== source || + !source.endsWith(".xml") || + info.size > 20 * 1024 * 1024 + ) + throw new Error( + "Only regular native XML reports up to 20 MiB may be retained.", + ); + fs.copyFileSync( + source, + path.join(root, path.basename(source)), + fs.constants.COPYFILE_EXCL, + ); + } +} +module.exports = { stageNativeReports }; diff --git a/actions/retain-native-reports/package-lock.json b/actions/retain-native-reports/package-lock.json new file mode 100644 index 0000000..8d94dd0 --- /dev/null +++ b/actions/retain-native-reports/package-lock.json @@ -0,0 +1,16 @@ +{ + "name": "retain-native-reports-tests", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "retain-native-reports-tests", + "version": "0.0.0", + "license": "MIT", + "engines": { + "node": ">=24.8.0" + } + } + } +} diff --git a/actions/retain-native-reports/package.json b/actions/retain-native-reports/package.json new file mode 100644 index 0000000..8b5329b --- /dev/null +++ b/actions/retain-native-reports/package.json @@ -0,0 +1,13 @@ +{ + "name": "retain-native-reports-tests", + "version": "0.0.0", + "private": true, + "description": "Native report preservation and staging validation", + "license": "MIT", + "engines": { + "node": ">=24.8.0" + }, + "scripts": { + "test": "node --test" + } +} diff --git a/actions/retain-native-reports/tests/native-reports.test.cjs b/actions/retain-native-reports/tests/native-reports.test.cjs new file mode 100644 index 0000000..181d639 --- /dev/null +++ b/actions/retain-native-reports/tests/native-reports.test.cjs @@ -0,0 +1,35 @@ +const assert = require("node:assert/strict"); +const fs = require("node:fs"); +const os = require("node:os"); +const path = require("node:path"); +const { suite, test } = require("node:test"); +const { stageNativeReports } = require("../native-reports.cjs"); + +suite("native report staging", () => { + test("preserves bytes and rejects private files, symlinks and reused destinations", (t) => { + // Arrange + const root = fs.mkdtempSync(path.join(os.tmpdir(), "native-staging-")); + t.after(() => fs.rmSync(root, { recursive: true, force: true })); + const output = path.join(root, "output"); + fs.mkdirSync(output); + const source = path.join(root, "result.xml"); + fs.writeFileSync(source, ""); + const privateFile = path.join(root, "state.json"); + fs.writeFileSync(privateFile, "private"); + const link = path.join(root, "linked.xml"); + fs.symlinkSync(source, link); + // Act + const stage = (files) => () => stageNativeReports(files, output); + // Assert + assert.throws(stage([privateFile]), /Only regular native XML/); + assert.throws(stage([link]), /Only regular native XML/); + // Act + stage([source])(); + // Assert + assert.deepEqual( + fs.readFileSync(path.join(output, "result.xml")), + fs.readFileSync(source), + ); + assert.throws(stage([source]), /empty directory/); + }); +}); diff --git a/actions/vm/create/README.md b/actions/vm/create/README.md index 51b7521..bbe68b6 100644 --- a/actions/vm/create/README.md +++ b/actions/vm/create/README.md @@ -47,7 +47,6 @@ After checkout, supply your VM configuration and a with: vm: ${{ steps.vm.outputs.vm }} goss-file: tests/goss.yaml - report-name: Infrastructure VM tests - name: Destroy VM if: ${{ always() && steps.vm.outputs.vm != '' }} uses: hoverkraft-tech/ci-github-iac/actions/vm/destroy@ @@ -61,9 +60,9 @@ check deployment, idempotence and reboot against the same VM. Reference the creation step's `name` and `ssh-config` outputs in that scenario's inventory; Molecule's target and sequence are configured by the scenario. -Default GitHub reporting needs `pull-requests: write` for PR comments. Other -reporting modes and permissions are documented by `vm/test`. The maintained -[VM test workflow](../../../.github/workflows/__test-actions-vm-test.yml) also +Call common `ci-reports` once after all producers to publish the consolidated +report, then use a separate `CI complete` gate. Producers need `actions: read`. +The maintained [VM test workflow](../../../.github/workflows/__test-actions-vm-test.yml) also covers failures and repeated tests. No consumer Makefile is required. ### Runner and configuration diff --git a/actions/vm/create/action.yml b/actions/vm/create/action.yml index 534b8c9..c390e64 100644 --- a/actions/vm/create/action.yml +++ b/actions/vm/create/action.yml @@ -21,7 +21,6 @@ # with: # vm: ${{ steps.vm.outputs.vm }} # goss-file: tests/goss.yaml -# report-name: Infrastructure VM tests # - name: Destroy VM # if: ${{ always() && steps.vm.outputs.vm != '' }} # uses: hoverkraft-tech/ci-github-iac/actions/vm/destroy@ @@ -35,9 +34,9 @@ # Reference the creation step's `name` and `ssh-config` outputs in that scenario's # inventory; Molecule's target and sequence are configured by the scenario. # -# Default GitHub reporting needs `pull-requests: write` for PR comments. Other -# reporting modes and permissions are documented by `vm/test`. The maintained -# [VM test workflow](../../../.github/workflows/__test-actions-vm-test.yml) also +# Call common `ci-reports` once after all producers to publish the consolidated +# report, then use a separate `CI complete` gate. Producers need `actions: read`. +# The maintained [VM test workflow](../../../.github/workflows/__test-actions-vm-test.yml) also # covers failures and repeated tests. No consumer Makefile is required. # # ### Runner and configuration diff --git a/actions/vm/create/package.json b/actions/vm/create/package.json index 5b58fec..5a3b9b3 100644 --- a/actions/vm/create/package.json +++ b/actions/vm/create/package.json @@ -8,9 +8,7 @@ "node": ">=24.8.0" }, "scripts": { - "test": "node --test", - "pretest:ci": "node -e \"require('node:fs').mkdirSync('coverage', { recursive: true })\"", - "test:ci": "node --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test" + "test": "node --test" }, "devDependencies": { "@actions/exec": "3.0.0", diff --git a/actions/vm/destroy/package.json b/actions/vm/destroy/package.json index 316aa38..b108727 100644 --- a/actions/vm/destroy/package.json +++ b/actions/vm/destroy/package.json @@ -8,9 +8,7 @@ "node": ">=24.8.0" }, "scripts": { - "test": "node --test", - "pretest:ci": "node -e \"require('node:fs').mkdirSync('coverage', { recursive: true })\"", - "test:ci": "node --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test" + "test": "node --test" }, "devDependencies": { "@actions/exec": "3.0.0", diff --git a/actions/vm/test/README.md b/actions/vm/test/README.md index d5c67ab..06318fb 100644 --- a/actions/vm/test/README.md +++ b/actions/vm/test/README.md @@ -13,16 +13,14 @@ [![Marketplace](https://img.shields.io/badge/Marketplace-vm------test-blue?logo=github-actions)](https://github.com/marketplace/actions/vm---test) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-iac)](https://github.com/hoverkraft-tech/ci-github-iac/releases) -[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-iac)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-iac?style=social) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-iac/blob/main/CONTRIBUTING.md) ## Overview -Validate VM state with Goss, publish summaries and PR comments, and upload JUnit results. +Run vm tests and retain validated native evidence for consolidated CI reporting. Validate a disposable Linux VM with Goss and publish JUnit results. @@ -52,25 +50,17 @@ report, a nonempty regular file up to 20 MiB. Missing, empty and fully skipped suites fail. Reports are collected after failed assertions; private guest test files are then removed. Incomplete transfers are never published. -### Publish results +### Retain results -Each invocation publishes native JUnit plus a sanitized execution-status report -through Hoverkraft's report parser: job summary, annotations and, on eligible -pull requests, an updated comment. Use a distinct stable `report-name` for each -step and matrix scenario. Comments use `github.token` and require -`pull-requests: write`; fork PRs still receive summaries and artifacts. -Do not use `pull_request_target` to execute untrusted suites. - -Completed reports are retained as a unique GitHub artifact for seven days, even -after parser or comment failure. Raw command output and exceptions are excluded -from the execution-status report. Native Goss reports retain assertion details: -use synthetic expectations and never match or print credentials. Infrastructure -assertions produce test results, not application code coverage. - -See the [lifecycle example](../create/README.md#compose-the-vm-actions). -For consolidated comments, set `comment: false` and call the common `ci-reports` -workflow after all test jobs. Native report artifacts use the `ci-reports-` prefix -and the current run attempt, so earlier attempts cannot leak stale results. +Each invocation registers its expected native Goss JUnit report before testing, +then validates and retains it even after assertion failures. No synthetic test +case is added for execution status. VM cleanup stays with the caller. +Native assertion details are public: never match or print credentials. +Infrastructure assertions produce test results, not application code coverage. +Call common publish-ci-reports once after all test jobs. Producers need contents: read +and actions: read; comments and summaries belong to the reporting workflow. +Use a separate CI complete gate for all required jobs and reporting. +Never use pull_request_target to execute untrusted suites. @@ -94,14 +84,6 @@ and the current run attempt, so earlier attempts cannot leak stale results. # Combined Goss setup and execution timeout, from 1 to 40 minutes. # Default: `10` test-timeout-minutes: "10" - - # Summary and PR comment title. Use a distinct stable name for each test step and matrix scenario. - # Default: `VM test results` - report-name: VM test results - - # Publish an individual PR comment. Set false when using the shared ci-reports workflow; summaries, annotations and artifacts remain enabled. - # Default: `true` - comment: "true" ``` @@ -109,43 +91,32 @@ and the current run attempt, so earlier attempts cannot leak stale results. ## Inputs -| **Input** | **Description** | **Required** | **Default** | -| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------------- | -| **`vm`** | VM reference returned by vm/create in the same job; works with either backend. | **true** | - | -| **`goss-file`** | Required checkout-relative Goss suite, including any referenced Goss files. | **true** | - | -| **`goss-vars`** | Optional checkout-relative JSON or YAML variables file. Use values suitable for public reports. | **false** | - | -| **`test-timeout-minutes`** | Combined Goss setup and execution timeout, from 1 to 40 minutes. | **false** | `10` | -| **`report-name`** | Summary and PR comment title. Use a distinct stable name for each test step and matrix scenario. | **false** | `VM test results` | -| **`comment`** | Publish an individual PR comment. Set false when using the shared ci-reports workflow; summaries, annotations and artifacts remain enabled. | **false** | `true` | +| **Input** | **Description** | **Required** | **Default** | +| -------------------------- | ----------------------------------------------------------------------------------------------- | ------------ | ----------- | +| **`vm`** | VM reference returned by vm/create in the same job; works with either backend. | **true** | - | +| **`goss-file`** | Required checkout-relative Goss suite, including any referenced Goss files. | **true** | - | +| **`goss-vars`** | Optional checkout-relative JSON or YAML variables file. Use values suitable for public reports. | **false** | - | +| **`test-timeout-minutes`** | Combined Goss setup and execution timeout, from 1 to 40 minutes. | **false** | `10` | + +## Outputs + +| **Output** | **Description** | +| ------------------------ | ------------------------------------------------------------------ | +| **`report-artifact-id`** | Native result artifact ID, discovered automatically by ci-reports. | + - -## Contributing - -Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-iac/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/vm/test/action.yml b/actions/vm/test/action.yml index 58d693f..f6700f4 100644 --- a/actions/vm/test/action.yml +++ b/actions/vm/test/action.yml @@ -26,51 +26,45 @@ # suites fail. Reports are collected after failed assertions; private guest test # files are then removed. Incomplete transfers are never published. # -# ### Publish results +# ### Retain results # -# Each invocation publishes native JUnit plus a sanitized execution-status report -# through Hoverkraft's report parser: job summary, annotations and, on eligible -# pull requests, an updated comment. Use a distinct stable `report-name` for each -# step and matrix scenario. Comments use `github.token` and require -# `pull-requests: write`; fork PRs still receive summaries and artifacts. -# Do not use `pull_request_target` to execute untrusted suites. -# -# Completed reports are retained as a unique GitHub artifact for seven days, even -# after parser or comment failure. Raw command output and exceptions are excluded -# from the execution-status report. Native Goss reports retain assertion details: -# use synthetic expectations and never match or print credentials. Infrastructure -# assertions produce test results, not application code coverage. -# -# See the [lifecycle example](../create/README.md#compose-the-vm-actions). -# For consolidated comments, set `comment: false` and call the common `ci-reports` -# workflow after all test jobs. Native report artifacts use the `ci-reports-` prefix -# and the current run attempt, so earlier attempts cannot leak stale results. +# Each invocation registers its expected native Goss JUnit report before testing, +# then validates and retains it even after assertion failures. No synthetic test +# case is added for execution status. VM cleanup stays with the caller. +# Native assertion details are public: never match or print credentials. +# Infrastructure assertions produce test results, not application code coverage. +# Call common publish-ci-reports once after all test jobs. Producers need contents: read +# and actions: read; comments and summaries belong to the reporting workflow. +# Use a separate CI complete gate for all required jobs and reporting. +# Never use pull_request_target to execute untrusted suites. --- name: VM - Test -description: Validate VM state with Goss, publish summaries and PR comments, and upload JUnit results. +description: Run vm tests and retain validated native evidence for consolidated + CI reporting. author: Hoverkraft branding: icon: check-circle color: purple inputs: vm: - description: VM reference returned by vm/create in the same job; works with either backend. + description: VM reference returned by vm/create in the same job; works with + either backend. required: true goss-file: description: Required checkout-relative Goss suite, including any referenced Goss files. required: true goss-vars: - description: Optional checkout-relative JSON or YAML variables file. Use values suitable for public reports. + description: + Optional checkout-relative JSON or YAML variables file. Use values + suitable for public reports. default: "" test-timeout-minutes: description: Combined Goss setup and execution timeout, from 1 to 40 minutes. default: "10" - report-name: - description: Summary and PR comment title. Use a distinct stable name for each test step and matrix scenario. - default: VM test results - comment: - description: Publish an individual PR comment. Set false when using the shared ci-reports workflow; summaries, annotations and artifacts remain enabled. - default: "true" +outputs: + report-artifact-id: + description: Native result artifact ID, discovered automatically by ci-reports. + value: ${{ steps.reports.outputs.artifact-id }} runs: using: composite steps: @@ -96,9 +90,8 @@ runs: try { await assertions.run(new Guest(process.env.VM_DIRECTORY, { exec }), { exec, io }); } finally { - if (assertions.report || assertions.reportFiles?.length) + if (assertions.reportFiles?.length) core.setOutput("id", assertions.id); - if (assertions.report) core.setOutput("report", assertions.report); if (assertions.reportFiles?.length) core.setOutput("report-files", assertions.reportFiles.join("\n")); } @@ -106,34 +99,11 @@ runs: core.setFailed("Goss assertions or report collection failed. Inspect the available reports."); } - - name: Parse test reports - if: ${{ always() && (steps.test.outputs.report-files != '' || steps.test.outputs.report != '') }} - id: parse-test-reports - uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 - with: - report-name: ${{ inputs.report-name }} - report-paths: | - ${{ steps.test.outputs.report }} - ${{ steps.test.outputs.report-files }} - output-format: summary,markdown,annotations - - - name: Add test PR comment - if: >- - ${{ always() && inputs.comment == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && steps.parse-test-reports.outputs.markdown != '' }} - uses: hoverkraft-tech/ci-github-common/actions/create-or-update-comment@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4 - with: - title: ${{ inputs.report-name }} - body: ${{ steps.parse-test-reports.outputs.markdown }} - token: ${{ github.token }} - - - name: Upload test reports - if: ${{ always() && (steps.test.outputs.report-files != '' || steps.test.outputs.report != '') }} - id: upload - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + - name: Retain VM native evidence + id: reports + if: ${{ !cancelled() }} + uses: $/actions/retain-native-reports with: - name: ci-reports-${{ github.run_attempt }}-${{ github.job }}-${{ steps.test.outputs.id }} - path: | - ${{ steps.test.outputs.report }} - ${{ steps.test.outputs.report-files }} - if-no-files-found: error - retention-days: 7 + outcome: ${{ steps.test.outcome == 'success' && 'success' || 'failure' }} + files: ${{ steps.test.outputs.report-files }} + definition: '{"name":"VM tests","reports":[{"kind":"test","pattern":"*.xml"}]}' diff --git a/actions/vm/test/assertions.cjs b/actions/vm/test/assertions.cjs index d624f25..592bc62 100644 --- a/actions/vm/test/assertions.cjs +++ b/actions/vm/test/assertions.cjs @@ -25,12 +25,10 @@ class GuestAssertions { } async run(vm, { exec, io }) { - this.report = undefined; this.reportFiles = []; await io.mkdirP(this.directory); const directory = fs.mkdtempSync(path.join(this.directory, "vm-test-")); this.id = path.basename(directory); - const report = path.join(directory, "e2e.junit.xml"); const started = performance.now(); let failed = false; try { @@ -71,7 +69,7 @@ class GuestAssertions { try { this.goss.validateReports(this.reportFiles); } catch (error) { - // Empty native suites cannot replace the failed execution summary. + // Empty native suites cannot satisfy the promised test report. this.reportFiles = []; throw error; } @@ -84,25 +82,6 @@ class GuestAssertions { failed = true; } } - const duration = ((performance.now() - started) / 1000).toFixed(3); - // All XML text is fixed; no paths, guest output or error details are serialized. - const failure = failed - ? '' - : ""; - try { - fs.writeFileSync( - report, - '\n' + - `` + - `${failure}\n`, - { flag: "wx" }, - ); - } catch (error) { - await io.rmRF(report); - if (!this.reportFiles.length) await io.rmRF(directory); - throw error; - } - this.report = report; if (failed) throw new Error("Goss assertions failed"); } } diff --git a/actions/vm/test/package.json b/actions/vm/test/package.json index f6487c1..cef9c0e 100644 --- a/actions/vm/test/package.json +++ b/actions/vm/test/package.json @@ -8,9 +8,7 @@ "node": ">=24.8.0" }, "scripts": { - "test": "node --test", - "pretest:ci": "node -e \"require('node:fs').mkdirSync('coverage', { recursive: true })\"", - "test:ci": "node --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test" + "test": "node --test" }, "devDependencies": { "@actions/exec": "3.0.0", diff --git a/actions/vm/test/tests/reports.test.mjs b/actions/vm/test/tests/reports.test.mjs index 67f3368..823239e 100644 --- a/actions/vm/test/tests/reports.test.mjs +++ b/actions/vm/test/tests/reports.test.mjs @@ -2,10 +2,10 @@ import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; import { suite, test } from "node:test"; -import { GuestReports } from "../reports.cjs"; -import { GuestAssertions } from "../assertions.cjs"; import * as exec from "@actions/exec"; import * as io from "@actions/io"; +import { GuestAssertions } from "../assertions.cjs"; +import { GuestReports } from "../reports.cjs"; async function fixture(t) { const directory = fs.mkdtempSync("/tmp/report-test-"); @@ -75,9 +75,7 @@ suite("vm/test - report safety", () => { assert.equal(fs.existsSync(guest), false); assert.equal(assertions.reportFiles.length, 1); assert.equal(fs.readFileSync(assertions.reportFiles[0], "utf8"), xml); - const status = fs.readFileSync(assertions.report, "utf8"); - assert.match(status, /failures="1"/); - assert.equal(status.includes("synthetic-private-output"), false); + assert.equal(xml.includes("synthetic-private-output"), false); assert.equal( fs.existsSync(path.join(directory, "guest/private.txt")), false, @@ -89,7 +87,6 @@ suite("vm/test - report safety", () => { "partial-transfer", "cleanup", "empty-suite", - "report-write", ]) { test(`${failure} fails without publishing incomplete results`, async (t) => { // Arrange @@ -115,31 +112,14 @@ suite("vm/test - report safety", () => { throw new Error("cleanup failed"); return execute(args); }); - if (failure === "report-write") { - const write = fs.writeFileSync; - t.mock.method(fs, "writeFileSync", (file, ...args) => { - if (file.endsWith("e2e.junit.xml")) { - write(file, "partial"); - throw new Error("write failed"); - } - return write(file, ...args); - }); - } // Act const run = () => assertions.run(vm, { exec, io }); // Assert await assert.rejects(run); assert.equal( assertions.reportFiles.length, - ["cleanup", "report-write"].includes(failure) ? 1 : 0, + failure === "cleanup" ? 1 : 0, ); - if (failure === "report-write") - assert.equal(assertions.report, undefined); - else - assert.match( - fs.readFileSync(assertions.report, "utf8"), - /failures="1"/, - ); assert.equal(fs.existsSync(guest), failure === "cleanup"); }); } diff --git a/docs/development/adr/0002-infrastructure-test-actions.md b/docs/development/adr/0002-infrastructure-test-actions.md index 4e09cc0..6561de0 100644 --- a/docs/development/adr/0002-infrastructure-test-actions.md +++ b/docs/development/adr/0002-infrastructure-test-actions.md @@ -8,6 +8,8 @@ Status: Accepted. Implementation is under review in Extends the backend and test execution contracts in [ADR 0001](0001-vm-actions.md) and supersedes its mandatory external entrypoints. +Reporting responsibilities are superseded by [ADR 0003](0003-consolidated-native-ci-reports.md). + ## Context The Proxmox installation consumer needs direct QEMU because installation inside diff --git a/docs/development/adr/0003-consolidated-native-ci-reports.md b/docs/development/adr/0003-consolidated-native-ci-reports.md new file mode 100644 index 0000000..93e822a --- /dev/null +++ b/docs/development/adr/0003-consolidated-native-ci-reports.md @@ -0,0 +1,38 @@ +# ADR 0003: Consolidated native CI reports + +Date: 2026-11-28. + +Status: Accepted. Supersedes the per-action publication and synthetic scenario +status reports in [ADR 0002](0002-infrastructure-test-actions.md). + +## Decision + +Test actions own execution, native result validation and safe retention. They +register expected evidence before executing tests and finalize it through common +`record-ci-reports`, including after failures. The shared staging helper retains +only bounded regular XML files; runtime state, environments and logs stay private. + +One outer common `ci-reports` workflow publishes annotations, summaries and the +consolidated comment. Its success means reporting succeeded. A separate +`CI complete` gate requires all producers and reporting to succeed, including VM +cleanup. Workflows continue to own VM lifetime and unconditional destruction. + +Remove `comment` and `report-name` inputs and export `report-artifact-id` for +inspection. Ordinary consumers need no artifact inventory. Stop inventing JUnit +test cases for command execution or cleanup; those failures remain action failures. +Native assertion counts now describe actual tests only. + +## Consequences + +This requires a breaking release. Consumers remove per-action reporting options +and add one outer reporting call and completion gate. Producers need read access +to Actions and contents; publication permissions belong to the reporting job. + +Hosted action tests inspect retained bytes and native outcomes. Only after their +assertions succeed may tests delete their own deliberately failing fixture results +and registrations, so those fixtures do not become real consolidated CI findings. + +The [common reporting contract](https://github.com/hoverkraft-tech/ci-github-common/blob/feat/native-github-coverage/docs/usage/ci-reports.md) +owns formats, discovery and publisher behavior. Common is released first, followed +by the language provider and this migration; candidate pins are replaced with +released SHAs before merging. diff --git a/tests/helpers/published-reports.cjs b/tests/helpers/published-reports.cjs index c333744..970d9d8 100644 --- a/tests/helpers/published-reports.cjs +++ b/tests/helpers/published-reports.cjs @@ -2,109 +2,39 @@ const assert = require("node:assert/strict"); const fs = require("node:fs"); const path = require("node:path"); -// Hosted assertions inspect report side effects without expanding the public API. +// Inspect the bytes downloaded by the public artifact action. class PublishedReports { - constructor(github, context) { - this.github = github; + constructor(context) { this.context = context; } - - async read(prefix, expectedCount) { - const directories = fs - .readdirSync(process.env.RUNNER_TEMP, { withFileTypes: true }) - .filter((entry) => entry.isDirectory() && entry.name.startsWith(prefix)) - .map((entry) => path.join(process.env.RUNNER_TEMP, entry.name)); - assert.equal(directories.length, expectedCount); - let artifacts = []; - // Upload completion can precede visibility in GitHub's artifact list. - const deadline = Date.now() + 60_000; - while (true) { - artifacts = await this.github.paginate( - this.github.rest.actions.listWorkflowRunArtifacts, - { ...this.context.repo, run_id: this.context.runId, per_page: 100 }, - ); - if ( - directories.every((directory) => - artifacts.some( - (item) => - item.name.startsWith( - `ci-reports-${process.env.GITHUB_RUN_ATTEMPT}-`, - ) && item.name.endsWith(`-${path.basename(directory)}`), - ), - ) || - Date.now() >= deadline - ) - break; - await new Promise((resolve) => setTimeout(resolve, 2_000)); - } - return directories.map((directory) => { - assert.equal(fs.statSync(directory).mode & 0o777, 0o700); - const artifact = artifacts.find( - (item) => - item.name.startsWith( - `ci-reports-${process.env.GITHUB_RUN_ATTEMPT}-`, - ) && item.name.endsWith(`-${path.basename(directory)}`), - ); - assert.ok( - artifact, - `Missing uploaded reports for ${path.basename(directory)}`, + async read(expectedCount) { + const directory = process.env.EVIDENCE_DIRECTORY; + const manifests = fs + .readdirSync(directory, { recursive: true }) + .filter((file) => path.basename(file) === "report.json"); + assert.equal(manifests.length, expectedCount); + return manifests.map((file) => { + const root = path.dirname(path.join(directory, file)); + const result = JSON.parse( + fs.readFileSync(path.join(root, "report.json"), "utf8"), ); - assert.ok(artifact.size_in_bytes > 0); - assert.equal(artifact.expired, false); - const files = fs - .readdirSync(directory) - .filter((name) => /\.(xml|info|json)$/.test(name)) - .map((name) => path.join(directory, name)); - for (const name of ["guest"]) { - const source = path.join(directory, name); - if (!fs.existsSync(source)) continue; - for (const relative of fs.readdirSync(source, { recursive: true })) { - const file = path.join(source, relative); - if (fs.lstatSync(file).isFile()) files.push(file); - } - } - assert.ok(files.length > 0); + assert.equal(result.version, 1); + assert.equal(result.run, String(this.context.runId)); + const files = fs.existsSync(path.join(root, "native")) + ? fs + .readdirSync(path.join(root, "native")) + .map((file) => path.join(root, "native", file)) + : []; const text = files .map((file) => fs.readFileSync(file, "utf8")) .join("\n"); assert.equal(text.includes("synthetic-private-output"), false); - return { directory, artifact, files, text }; + assert.ok( + files.length || result.errors.length, + "Missing native evidence must remain an error", + ); + return { directory: root, files, text, result }; }); } - - async readComments(title) { - const pullRequest = this.context.payload.pull_request; - if ( - this.context.eventName !== "pull_request" || - pullRequest.head.repo.full_name !== - `${this.context.repo.owner}/${this.context.repo.repo}` - ) - return null; - const comments = await this.github.paginate( - this.github.rest.issues.listComments, - { - ...this.context.repo, - issue_number: pullRequest.number, - per_page: 100, - }, - ); - return comments - .filter( - (item) => - item.user.login === "github-actions[bot]" && - item.body.startsWith(`${title}\n`), - ) - .map(({ id, body, updated_at }) => ({ id, body, updated_at })); - } - - async comment(title) { - const comments = await this.readComments(title); - if (comments === null) return null; - assert.ok(comments.length > 0, `Missing comment: ${title}`); - for (const comment of comments) - assert.equal(comment.body.includes("synthetic-private-output"), false); - return comments[0].body; - } } - module.exports = { PublishedReports };