diff --git a/.devcontainer/devcontainer-lock.json b/.devcontainer/devcontainer-lock.json new file mode 100644 index 0000000..9b9fff5 --- /dev/null +++ b/.devcontainer/devcontainer-lock.json @@ -0,0 +1,29 @@ +{ + "features": { + "ghcr.io/devcontainers-extra/features/uv:1": { + "version": "1.0.2", + "resolved": "ghcr.io/devcontainers-extra/features/uv@sha256:1ac5b9f17a9e9e745933d0ac2ecf758e06ed3da4423cd22c94cce4d482fd2dd8", + "integrity": "sha256:1ac5b9f17a9e9e745933d0ac2ecf758e06ed3da4423cd22c94cce4d482fd2dd8" + }, + "ghcr.io/devcontainers/features/common-utils:2": { + "version": "2.7.2", + "resolved": "ghcr.io/devcontainers/features/common-utils@sha256:08e5a6ad4b672301c2010944217aeea4f428a87f4349d9bbf8bc97211238674b", + "integrity": "sha256:08e5a6ad4b672301c2010944217aeea4f428a87f4349d9bbf8bc97211238674b" + }, + "ghcr.io/devcontainers/features/docker-in-docker:4": { + "version": "4.1.3", + "resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:fae40f3c8be5a7c3b0db344c1d30341bc2c91ba38d1d5b14cd2ad72e6d65d084", + "integrity": "sha256:fae40f3c8be5a7c3b0db344c1d30341bc2c91ba38d1d5b14cd2ad72e6d65d084" + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "version": "1.1.3", + "resolved": "ghcr.io/devcontainers/features/github-cli@sha256:bd7ab48a832228f633239277552c30b353867fef2e5b037e064b4e64f0b843f2", + "integrity": "sha256:bd7ab48a832228f633239277552c30b353867fef2e5b037e064b4e64f0b843f2" + }, + "ghcr.io/devcontainers/features/node:2": { + "version": "2.1.2", + "resolved": "ghcr.io/devcontainers/features/node@sha256:20ac718cc67e7999a9d3fbb8387f1a3a5d53ecbd41fe7c075ebadb8e9b431b17", + "integrity": "sha256:20ac718cc67e7999a9d3fbb8387f1a3a5d53ecbd41fe7c075ebadb8e9b431b17" + } + } +} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..86026a9 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,48 @@ +{ + "name": "hoverkraft-tech/ci-github-python", + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true + }, + "ghcr.io/devcontainers/features/node:2": { + "pnpmVersion": "none" + }, + "ghcr.io/devcontainers/features/docker-in-docker:4": { + "moby": false + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "extensions": "nektos/gh-act" + }, + "ghcr.io/devcontainers-extra/features/uv:1": {} + }, + "remoteUser": "vscode", + "init": true, + "postCreateCommand": "make setup", + "waitFor": "postCreateCommand", + "customizations": { + "vscode": { + "extensions": [ + "eamodio.gitlens", + "github.vscode-github-actions", + "github.copilot", + "github.copilot-chat", + "ms-vscode.makefile-tools", + "biomejs.biome", + "ms-python.python", + "ms-python.vscode-pylance", + "ms-python.black-formatter", + "charliermarsh.ruff" + ], + "settings": { + "python.defaultInterpreterPath": "${containerWorkspaceFolder}/tests/python-project/.venv/bin/python", + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + } + } + } + }, + "containerEnv": { + "UV_LINK_MODE": "copy" + } +} diff --git a/.github/actions/parse-ci-reports/README.md b/.github/actions/parse-ci-reports/README.md new file mode 100644 index 0000000..353c082 --- /dev/null +++ b/.github/actions/parse-ci-reports/README.md @@ -0,0 +1,132 @@ + + +# GitHub Action: Parse CI reports + +
+ Parse CI reports +
+ +--- + + + + + + + + +[![Marketplace](https://img.shields.io/badge/Marketplace-parse--ci--reports-blue?logo=github-actions)](https://github.com/marketplace/actions/parse-ci-reports) +[![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-python)](https://github.com/hoverkraft-tech/ci-github-python/releases) +[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-python)](http://choosealicense.com/licenses/mit/) +[![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-python/blob/main/CONTRIBUTING.md) + + + + + + + +## Overview + +Parse native reports, publish summaries and retain selected files in one artifact. Internal helper for lint and test. + + + + + + + + +## Usage + +```yaml +- uses: hoverkraft-tech/ci-github-python/.github/actions/parse-ci-reports@f9227d0f443be4edbb7aacfc0701caaf25523f77 # fix/enforce-lint-checks + with: + # Validated absolute project directory. + # This input is required. + directory: "" + + # Report paths or auto selectors passed to the common parser. + # Default: `auto:test` + report-paths: auto:test + + # Calling job ID used to group reports. + # This input is required. + group: "" + + # Title of the GitHub report summary. + # Default: `CI reports` + report-name: CI reports +``` + + + + + +## Inputs + +| **Input** | **Description** | **Required** | **Default** | +| ------------------ | ----------------------------------------------------------- | ------------ | ------------ | +| **`directory`** | Validated absolute project directory. | **true** | - | +| **`report-paths`** | Report paths or auto selectors passed to the common parser. | **false** | `auto:test` | +| **`group`** | Calling job ID used to group reports. | **true** | - | +| **`report-name`** | Title of the GitHub report summary. | **false** | `CI reports` | + + + + + + + + +## Outputs + +| **Output** | **Description** | +| ----------------- | ---------------------------------------------------------- | +| **`artifact-id`** | Uploaded artifact ID, or empty when no report files exist. | + + + + + + + + + + + + + +## Contributing + +Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-python/blob/main/CONTRIBUTING.md) for more details. + + + + + + + + +## License + +This project is licensed under the MIT License. + +SPDX-License-Identifier: MIT + +Copyright © 2026 hoverkraft-tech + +For more details, see the [license](http://choosealicense.com/licenses/mit/). + + + + + +--- + +This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor). + + + + diff --git a/.github/actions/parse-ci-reports/action.test.cjs b/.github/actions/parse-ci-reports/action.test.cjs new file mode 100644 index 0000000..6be51d8 --- /dev/null +++ b/.github/actions/parse-ci-reports/action.test.cjs @@ -0,0 +1,52 @@ +const assert = require("node:assert/strict"); +const fs = require("node:fs"); +const path = require("node:path"); +const test = require("node:test"); +const { + createWorkspace, + loadActionStep, +} = require("../../../tests/action-test-helpers.cjs"); + +const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor; + +test("report artifacts contain only parsed reports and use unique names", async (t) => { + const directory = createWorkspace(t); + const report = path.join(directory, "junit.xml"); + fs.writeFileSync(report, ""); + fs.writeFileSync( + path.join(directory, "unrelated-secret.txt"), + "not a report", + ); + const prepare = new AsyncFunction( + "core", + "process", + "require", + loadActionStep(path.join(__dirname, "action.yml"), "prepare").with.script, + ); + async function outputs(files, group = "outer-job") { + const result = {}; + await prepare( + { + setOutput: (key, value) => { + result[key] = value; + }, + }, + { + env: { + DIRECTORY: directory, + REPORT_FILES: JSON.stringify(files), + REPORT_GROUP: group, + GITHUB_RUN_ATTEMPT: "2", + }, + }, + require, + ); + return result; + } + assert.deepEqual(await outputs([]), {}); + const first = await outputs([report]); + assert.equal(first.files, report); + assert.match(first.name, /^ci-reports-2-outer-job-/); + assert.notEqual(first.name, (await outputs([report])).name); + await assert.rejects(() => outputs([report], "../bad-group"), /report-group/); +}); diff --git a/.github/actions/parse-ci-reports/action.yml b/.github/actions/parse-ci-reports/action.yml new file mode 100644 index 0000000..0baa08c --- /dev/null +++ b/.github/actions/parse-ci-reports/action.yml @@ -0,0 +1,62 @@ +--- +name: Parse CI reports +description: + Parse native reports, publish summaries and retain selected files in one artifact. Internal helper for lint and + test. +inputs: + directory: + description: Validated absolute project directory. + required: true + report-paths: + description: Report paths or auto selectors passed to the common parser. + default: auto:test + group: + description: Calling job ID used to group reports. + required: true + report-name: + description: Title of the GitHub report summary. + default: CI reports +outputs: + artifact-id: + description: Uploaded artifact ID, or empty when no report files exist. + value: ${{ steps.upload.outputs.artifact-id }} +runs: + using: composite + steps: + - id: parse + if: ${{ !cancelled() }} + uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@66882b24f9f13e45a6541896a5a7c638cb91c94c + with: + working-directory: ${{ inputs.directory }} + report-paths: | + ${{ inputs.report-paths }} + !**/.venv/** + !**/.git/** + !**/.cache/** + !**/vendor/** + report-name: ${{ inputs.report-name }} + output-format: annotations,summary,markdown + - id: prepare + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + env: + DIRECTORY: ${{ inputs.directory }} + REPORT_FILES: ${{ steps.parse.outputs.parsed-files }} + REPORT_GROUP: ${{ inputs.group }} + with: + script: | + const files = JSON.parse(process.env.REPORT_FILES || '[]'); + if (!files.length) return; + const group = process.env.REPORT_GROUP; + if (!/^[\w-]+$/.test(group)) throw new Error('report-group must be a job ID.'); + core.setOutput('files', files.join('\n')); + core.setOutput('name', `ci-reports-${process.env.GITHUB_RUN_ATTEMPT}-${group}-${require('node:crypto').randomUUID()}`); + if: ${{ !cancelled() }} + - id: upload + if: ${{ !cancelled() && steps.prepare.outputs.files != '' }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: ${{ steps.prepare.outputs.name }} + path: ${{ steps.prepare.outputs.files }} + include-hidden-files: true + if-no-files-found: error + retention-days: 7 diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e7a6b45..8974c47 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,3 +1,4 @@ +--- version: 2 updates: - package-ecosystem: github-actions @@ -65,3 +66,18 @@ updates: uv-dependencies: patterns: - "*" + - package-ecosystem: devcontainers + directory: / + schedule: + interval: weekly + day: friday + commit-message: + prefix: build + include: scope + cooldown: + default-days: 7 + open-pull-requests-limit: 10 + groups: + devcontainers-dependencies: + patterns: + - "*" diff --git a/.github/linters/.checkov.yaml b/.github/linters/.checkov.yaml index 6fc65d3..84875ce 100644 --- a/.github/linters/.checkov.yaml +++ b/.github/linters/.checkov.yaml @@ -1,3 +1,4 @@ +--- quiet: true skip-path: - (^|/)node_modules/ diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index c17146d..33c7766 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -1,10 +1,3 @@ { - "threshold": 5, - "ignore": [ - "**/vendor/**", - "**/actions/**/README.md", - "**/.github/workflows/*.md", - "**/.github/logo.svg", - "**/.github/social-preview.svg" - ] + "threshold": 5 } diff --git a/.github/logo.svg b/.github/logo.svg index 99874f8..8630c8a 100644 --- a/.github/logo.svg +++ b/.github/logo.svg @@ -1,57 +1,12 @@ - - - CI GitHub Python - CI GitHub Python by Hoverkraft. Hoverkraft project badge with the Python language identifier. - - - - - + + CI GitHub Python + Hoverkraft project badge with the Python language mark. + + + + + - - - Python language mark - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.github/social-preview.png b/.github/social-preview.png index 8ca7735..fc7a98c 100644 Binary files a/.github/social-preview.png and b/.github/social-preview.png differ diff --git a/.github/social-preview.svg b/.github/social-preview.svg index df0e37f..4819452 100644 --- a/.github/social-preview.svg +++ b/.github/social-preview.svg @@ -1,63 +1,53 @@ - - - CI GitHub Python by Hoverkraft - Opinionated GitHub Actions and reusable workflows for Python. - - - - - - - + + CI GitHub Python by Hoverkraft + Hoverkraft project badge and CI GitHub Python wordmark. + + - - - + + + + diff --git a/.github/workflows/__main-ci.yml b/.github/workflows/__main-ci.yml index 4878e61..aeef736 100644 --- a/.github/workflows/__main-ci.yml +++ b/.github/workflows/__main-ci.yml @@ -1,3 +1,4 @@ +--- name: Internal - Main - Continuous Integration permissions: {} concurrency: diff --git a/.github/workflows/__prepare-release.yml b/.github/workflows/__prepare-release.yml index f199c71..ad7b83b 100644 --- a/.github/workflows/__prepare-release.yml +++ b/.github/workflows/__prepare-release.yml @@ -1,3 +1,4 @@ +--- name: Internal - Prepare release on: diff --git a/.github/workflows/__pull-request-ci.yml b/.github/workflows/__pull-request-ci.yml index aa9a26c..7232af2 100644 --- a/.github/workflows/__pull-request-ci.yml +++ b/.github/workflows/__pull-request-ci.yml @@ -1,3 +1,4 @@ +--- name: Internal - Pull request - Continuous Integration permissions: {} concurrency: diff --git a/.github/workflows/__release.yml b/.github/workflows/__release.yml index 9891620..00c75ae 100644 --- a/.github/workflows/__release.yml +++ b/.github/workflows/__release.yml @@ -1,3 +1,4 @@ +--- name: Internal - Release permissions: {} concurrency: diff --git a/.github/workflows/__renovate.yml b/.github/workflows/__renovate.yml index d7d639d..6ff9e0b 100644 --- a/.github/workflows/__renovate.yml +++ b/.github/workflows/__renovate.yml @@ -1,3 +1,4 @@ +--- name: Internal - Renovate dependency updates permissions: {} concurrency: diff --git a/.github/workflows/__semantic-pull-request.yml b/.github/workflows/__semantic-pull-request.yml index 8bd4f95..2b1fe88 100644 --- a/.github/workflows/__semantic-pull-request.yml +++ b/.github/workflows/__semantic-pull-request.yml @@ -1,8 +1,8 @@ --- name: "Pull Request - Semantic Lint" -on: # zizmor: ignore[dangerous-triggers] shared workflow checks out only the trusted base revision - pull_request_target: +on: + pull_request: types: - opened - edited diff --git a/.github/workflows/__shared-ci.yml b/.github/workflows/__shared-ci.yml index 15fca23..719edb3 100644 --- a/.github/workflows/__shared-ci.yml +++ b/.github/workflows/__shared-ci.yml @@ -1,3 +1,4 @@ +--- name: Internal - Common Continuous Integration tasks "on": workflow_call: null @@ -15,13 +16,12 @@ jobs: security-events: write with: linter-env: | - VALIDATE_GO=false - VALIDATE_GO_MODULES=false - VALIDATE_PYTHON_BLACK=false - VALIDATE_PYTHON_RUFF=false - VALIDATE_PYTHON_MYPY=false - VALIDATE_PYTHON_PYLINT=false - VALIDATE_PYTHON_ISORT=false + LOG_LEVEL=INFO + VALIDATE_PYTHON_TOOLCHAIN=black + PYTHON_BLACK_CONFIG_FILE=../../tests/python-project/pyproject.toml + PYTHON_RUFF_CONFIG_FILE=../../tests/python-project/pyproject.toml + PYTHON_ISORT_CONFIG_FILE=../../tests/python-project/pyproject.toml + PYTHON_MYPY_CONFIG_FILE=../../tests/python-project/pyproject.toml test: uses: $/.github/workflows/__test-workflow-continuous-integration.yml permissions: @@ -47,3 +47,7 @@ jobs: uses: $/.github/workflows/__test-action-package-test.yml permissions: contents: read + test-action-parse-ci-reports: + uses: $/.github/workflows/__test-action-parse-ci-reports.yml + permissions: + contents: read diff --git a/.github/workflows/__test-action-audit.yml b/.github/workflows/__test-action-audit.yml index 1b3897a..cfab95d 100644 --- a/.github/workflows/__test-action-audit.yml +++ b/.github/workflows/__test-action-audit.yml @@ -1,3 +1,4 @@ +--- name: Internal - Test audit action "on": workflow_call: null diff --git a/.github/workflows/__test-action-lint.yml b/.github/workflows/__test-action-lint.yml index a8e8dbf..ac15e09 100644 --- a/.github/workflows/__test-action-lint.yml +++ b/.github/workflows/__test-action-lint.yml @@ -1,3 +1,4 @@ +--- name: Internal - Test lint action "on": workflow_call: null @@ -8,11 +9,20 @@ jobs: timeout-minutes: 20 permissions: contents: read + outputs: + artifact-id: ${{ steps.failed-lint.outputs.report-artifact-id }} steps: - name: Arrange - Check out the repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false + - name: Assert - Action contract tests pass + uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + with: + command: test:ci + arguments: '["actions/lint/action.test.cjs"]' + coverage: "" + comment: "false" - name: Arrange - Install the project runtime and dependencies uses: $/actions/setup-python with: @@ -38,10 +48,17 @@ jobs: env: OUTCOME: ${{ steps.failed-lint.outcome }} ARTIFACT: ${{ steps.failed-lint.outputs.report-artifact-id }} + verify: + needs: lint + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + steps: - name: Assert - Download retained lint reports uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 with: - artifact-ids: ${{ steps.failed-lint.outputs.report-artifact-id }} + artifact-ids: ${{ needs.lint.outputs.artifact-id }} path: ${{ runner.temp }}/lint-reports - name: Assert - Retained report contains the diagnostic shell: bash diff --git a/.github/workflows/__test-action-package-test.yml b/.github/workflows/__test-action-package-test.yml index 3000368..3abee56 100644 --- a/.github/workflows/__test-action-package-test.yml +++ b/.github/workflows/__test-action-package-test.yml @@ -1,3 +1,4 @@ +--- name: Internal - Test package/test action "on": workflow_call: null diff --git a/.github/workflows/__test-action-parse-ci-reports.yml b/.github/workflows/__test-action-parse-ci-reports.yml new file mode 100644 index 0000000..c70ba38 --- /dev/null +++ b/.github/workflows/__test-action-parse-ci-reports.yml @@ -0,0 +1,65 @@ +--- +name: Internal - Test parse-ci-reports action +"on": + workflow_call: null +permissions: {} +jobs: + reports: + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + outputs: + artifact-id: ${{ steps.report.outputs.artifact-id }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Assert - Action contract tests pass + uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + with: + command: test:ci + arguments: '[".github/actions/parse-ci-reports/action.test.cjs"]' + coverage: "" + comment: "false" + - name: Arrange - Empty report directory + run: mkdir -p "$RUNNER_TEMP/empty-reports" + - name: Act - Retain no reports + id: empty + uses: $/.github/actions/parse-ci-reports + with: + directory: ${{ runner.temp }}/empty-reports + group: reports + - name: Assert - No empty artifact is created + env: + ARTIFACT: ${{ steps.empty.outputs.artifact-id }} + run: test -z "$ARTIFACT" + - name: Arrange - One report and an unrelated private file + run: | + mkdir -p "$RUNNER_TEMP/report-fixture" + printf '%s\n' '' > "$RUNNER_TEMP/report-fixture/junit.xml" + printf '%s\n' 'not a report' > "$RUNNER_TEMP/report-fixture/private.txt" + - name: Act - Retain the selected report + id: report + uses: $/.github/actions/parse-ci-reports + with: + directory: ${{ runner.temp }}/report-fixture + group: reports + report-paths: junit.xml + verify: + needs: reports + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + steps: + - name: Assert - Artifact can be downloaded + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 + with: + artifact-ids: ${{ needs.reports.outputs.artifact-id }} + path: ${{ runner.temp }}/downloaded-reports + - name: Assert - Only the selected file was retained + run: | + test -f "$RUNNER_TEMP/downloaded-reports/junit.xml" + test ! -e "$RUNNER_TEMP/downloaded-reports/private.txt" + test "$(find "$RUNNER_TEMP/downloaded-reports" -type f | wc -l)" -eq 1 diff --git a/.github/workflows/__test-action-setup-python.yml b/.github/workflows/__test-action-setup-python.yml index 9b93f8c..dc3fc04 100644 --- a/.github/workflows/__test-action-setup-python.yml +++ b/.github/workflows/__test-action-setup-python.yml @@ -1,3 +1,4 @@ +--- name: Internal - Test setup-python action "on": workflow_call: null @@ -13,6 +14,13 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false + - name: Assert - Action contract tests pass + uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + with: + command: test:ci + arguments: '["actions/setup-python/action.test.cjs"]' + coverage: "" + comment: "false" - name: Act - Detect the runtime and install dependencies uses: $/actions/setup-python with: diff --git a/.github/workflows/__test-action-test.yml b/.github/workflows/__test-action-test.yml index 12df1e6..4eb0b69 100644 --- a/.github/workflows/__test-action-test.yml +++ b/.github/workflows/__test-action-test.yml @@ -1,3 +1,4 @@ +--- name: Internal - Test test action "on": workflow_call: null @@ -8,11 +9,20 @@ jobs: timeout-minutes: 20 permissions: contents: read + outputs: + artifact-id: ${{ steps.failed-test.outputs.report-artifact-id }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false name: Arrange - Check out the repository + - name: Assert - Action contract tests pass + uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 + with: + command: test:ci + arguments: '["actions/test/action.test.cjs"]' + coverage: "" + comment: "false" - uses: $/actions/setup-python with: working-directory: tests/python-project @@ -45,9 +55,16 @@ jobs: assert.ok(process.env.SUCCESS_ARTIFACT, 'Successful tests retain reports'); assert.ok(process.env.FAILURE_ARTIFACT, 'Failed tests retain reports'); assert.notEqual(process.env.SUCCESS_ARTIFACT, process.env.FAILURE_ARTIFACT); + verify: + needs: test + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + steps: - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 with: - artifact-ids: ${{ steps.failed-test.outputs.report-artifact-id }} + artifact-ids: ${{ needs.test.outputs.artifact-id }} path: ${{ runner.temp }}/failed-reports - name: Verify retained failure report shell: bash diff --git a/.github/workflows/__test-workflow-continuous-integration.yml b/.github/workflows/__test-workflow-continuous-integration.yml index d57864d..6d7b8d4 100644 --- a/.github/workflows/__test-workflow-continuous-integration.yml +++ b/.github/workflows/__test-workflow-continuous-integration.yml @@ -1,3 +1,4 @@ +--- name: Internal - Test continuous integration workflow "on": workflow_call: null @@ -11,12 +12,13 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 + - name: Assert - Workflow configuration tests pass + uses: hoverkraft-tech/ci-github-nodejs/actions/test@98d91b1cc347efc64cd5fb20bc0ebc076acad114 # 3.1.0 with: - node-version-file: .node-version - cache: npm - - run: npm ci --ignore-scripts - - run: npm test + command: test:ci + arguments: '["tests/config.test.cjs"]' + coverage: "" + comment: "false" fixture: uses: $/.github/workflows/continuous-integration.yml permissions: diff --git a/.github/workflows/continuous-integration.md b/.github/workflows/continuous-integration.md index 58dfef3..4091009 100644 --- a/.github/workflows/continuous-integration.md +++ b/.github/workflows/continuous-integration.md @@ -2,13 +2,28 @@ # GitHub Reusable Workflow: Python Continuous Integration +
+ Python Continuous Integration +
+ +--- + + + + + [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-python)](https://github.com/hoverkraft-tech/ci-github-python/releases) +[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-python)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-python/blob/main/CONTRIBUTING.md) + + + ## Overview @@ -117,6 +132,10 @@ for standalone action usage. Pin the workflow to a reviewed commit SHA in produc - **`id-token`**: `write` + + + + ## Usage @@ -130,7 +149,7 @@ on: permissions: {} jobs: continuous-integration: - uses: hoverkraft-tech/ci-github-python/.github/workflows/continuous-integration.yml@0efcccef629a5715a6dff199a1b45add8eb5b397 # main + uses: hoverkraft-tech/ci-github-python/.github/workflows/continuous-integration.yml@f9227d0f443be4edbb7aacfc0701caaf25523f77 # fix/enforce-lint-checks permissions: contents: read id-token: write @@ -176,6 +195,7 @@ jobs: ``` + ## Inputs @@ -196,18 +216,46 @@ jobs: | **`uv-version`** | Pinned uv release. | **false** | **string** | `0.13.9` | + + + + + + + + + + +## Contributing + +Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-python/blob/main/CONTRIBUTING.md) for more details. + + + + +## License + +This project is licensed under the MIT License. + +SPDX-License-Identifier: MIT + +Copyright © 2026 hoverkraft-tech + +For more details, see the [license](http://choosealicense.com/licenses/mit/). + + --- @@ -215,3 +263,5 @@ jobs: This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor). + + diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b16a78e..2b485f0 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -96,6 +96,7 @@ # [test](../../actions/test/README.md) and [audit](../../actions/audit/README.md) # for standalone action usage. Pin the workflow to a reviewed commit SHA in production. +--- name: Python Continuous Integration "on": workflow_call: @@ -207,7 +208,8 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - &checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - uses: actions/dependency-review-action@bbc44d14a204704ccc493733616cd1e93a0321ec @@ -219,10 +221,9 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - with: - persist-credentials: false - - uses: $/actions/setup-python + - *checkout + - &setup-primary + uses: $/actions/setup-python with: working-directory: ${{ inputs.working-directory }} python-version: ${{ needs.configuration.outputs.primary-version }} @@ -240,9 +241,7 @@ jobs: contents: read id-token: write steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - with: - persist-credentials: false + - *checkout - uses: $/actions/setup-python with: working-directory: ${{ inputs.working-directory }} @@ -265,14 +264,8 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - with: - persist-credentials: false - - uses: $/actions/setup-python - with: - working-directory: ${{ inputs.working-directory }} - python-version: ${{ needs.configuration.outputs.primary-version }} - uv-version: ${{ inputs.uv-version }} + - *checkout + - *setup-primary - uses: $/actions/audit with: working-directory: ${{ inputs.working-directory }} @@ -284,14 +277,8 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - with: - persist-credentials: false - - uses: $/actions/setup-python - with: - working-directory: ${{ inputs.working-directory }} - python-version: ${{ needs.configuration.outputs.primary-version }} - uv-version: ${{ inputs.uv-version }} + - *checkout + - *setup-primary - uses: $/actions/package/test with: working-directory: ${{ inputs.working-directory }} diff --git a/Dockerfile b/Dockerfile index b04adef..be36c4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,11 +5,9 @@ ARG UID=1000 ARG GID=1000 USER ${UID}:${GID} -# Language fixtures are checked with their declared runtimes and tools. -ENV VALIDATE_GO=false \ - VALIDATE_GO_MODULES=false \ - VALIDATE_PYTHON_BLACK=false \ - VALIDATE_PYTHON_RUFF=false \ - VALIDATE_PYTHON_MYPY=false \ - VALIDATE_PYTHON_PYLINT=false \ - VALIDATE_PYTHON_ISORT=false +ENV LOG_LEVEL=INFO \ + VALIDATE_PYTHON_TOOLCHAIN=black \ + PYTHON_BLACK_CONFIG_FILE=../../tests/python-project/pyproject.toml \ + PYTHON_RUFF_CONFIG_FILE=../../tests/python-project/pyproject.toml \ + PYTHON_ISORT_CONFIG_FILE=../../tests/python-project/pyproject.toml \ + PYTHON_MYPY_CONFIG_FILE=../../tests/python-project/pyproject.toml diff --git a/Makefile b/Makefile index 14bf5f3..839988a 100644 --- a/Makefile +++ b/Makefile @@ -25,11 +25,11 @@ lint-fix: ## Apply supported formatting fixes $(call run_linter,-e FIX_YAML_PRETTIER=true -e FIX_MARKDOWN=true -e FIX_MARKDOWN_PRETTIER=true -e FIX_BIOME_FORMAT=true -e FIX_BIOME_LINT=true) docs: ## Generate action and workflow references with CI Dokumentor - docker run --rm --user $(shell id -u):$(shell id -g) -v "$(CURDIR):/workspace" -w /workspace ghcr.io/hoverkraft-tech/ci-dokumentor/cli:0.6.0 generate --repository git --cicd github-actions --source 'actions/**/action.yml' '.github/workflows/[!_]*.yml' + docker run --rm --user $(shell id -u):$(shell id -g) -v "$(CURDIR):/workspace" -w /workspace -e GITHUB_TOKEN ghcr.io/hoverkraft-tech/ci-dokumentor/cli:0.6.0 generate --repository github --cicd github-actions --source 'actions/**/action.yml' '.github/actions/**/action.yml' '.github/workflows/[!_]*.yml' ci: setup test lint-fixture test-fixture lint ## Run checks without rewriting source define run_linter docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag $(LINTER_IMAGE) . - docker run --rm -v "$(CURDIR):$(CURDIR)" -e DEFAULT_WORKSPACE="$(CURDIR)" -e DEFAULT_BRANCH="$$(git branch --show-current)" -e USE_FIND_ALGORITHM=false -e IGNORE_GITIGNORED_FILES=true $(1) $(LINTER_IMAGE) + docker run --rm -v "$(CURDIR):$(CURDIR)" -e DEFAULT_WORKSPACE="$(CURDIR)" -e IGNORE_GITIGNORED_FILES=true $(1) $(LINTER_IMAGE) endef diff --git a/actions/audit/README.md b/actions/audit/README.md index 8957203..2689b24 100644 --- a/actions/audit/README.md +++ b/actions/audit/README.md @@ -2,14 +2,29 @@ # ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Audit Python +
+ Audit Python +
+ +--- + + + + + [![Marketplace](https://img.shields.io/badge/Marketplace-audit--python-blue?logo=github-actions)](https://github.com/marketplace/actions/audit-python) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-python)](https://github.com/hoverkraft-tech/ci-github-python/releases) +[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-python)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-python/blob/main/CONTRIBUTING.md) + + + ## Overview @@ -23,25 +38,26 @@ supported; direct VCS or editable dependencies may require a project-specific audit workflow. Vulnerability lookup requires network access and scanner failures fail the action. Dependency metadata is not rewritten. -Run [setup-python](../setup-python/README.md) first with the same `working-directory`. -This action reuses the installed environment. Use the same reviewed commit SHA -for both actions. Do not populate command inputs from untrusted pull request text. + + -```yaml -- uses: hoverkraft-tech/ci-github-python/actions/audit@main - with: - working-directory: . -``` +Run [setup-python](../setup-python/README.md) first with the same `working-directory`. See the [continuous integration workflow](../../.github/workflows/continuous-integration.md) for orchestration and version matrices. + + + + + + ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-python/actions/audit@0efcccef629a5715a6dff199a1b45add8eb5b397 # main +- uses: hoverkraft-tech/ci-github-python/actions/audit@f9227d0f443be4edbb7aacfc0701caaf25523f77 # fix/enforce-lint-checks with: # uv project directory. # Default: `.` @@ -49,6 +65,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ``` + ## Inputs @@ -58,18 +75,46 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int | **`working-directory`** | uv project directory. | **false** | `.` | + + + + + + + + + + +## Contributing + +Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-python/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/). + + --- @@ -77,3 +122,5 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor). + + diff --git a/actions/audit/action.yml b/actions/audit/action.yml index 33d4f0e..b3737fb 100644 --- a/actions/audit/action.yml +++ b/actions/audit/action.yml @@ -1,6 +1,5 @@ +--- name: Audit Python -# Usage is self-contained in every generated action readme. -# jscpd:ignore-start description: | Audit locked production dependencies with pip-audit. @@ -11,18 +10,14 @@ description: | audit workflow. Vulnerability lookup requires network access and scanner failures fail the action. Dependency metadata is not rewritten. - Run [setup-python](../setup-python/README.md) first with the same `working-directory`. - This action reuses the installed environment. Use the same reviewed commit SHA - for both actions. Do not populate command inputs from untrusted pull request text. + + - ```yaml - - uses: hoverkraft-tech/ci-github-python/actions/audit@main - with: - working-directory: . - ``` + Run [setup-python](../setup-python/README.md) first with the same `working-directory`. See the [continuous integration workflow](../../.github/workflows/continuous-integration.md) for orchestration and version matrices. -# jscpd:ignore-end + + author: hoverkraft branding: icon: package @@ -34,13 +29,10 @@ inputs: runs: using: composite steps: - # Shared working-directory validation, kept at each standalone entry point. - # jscpd:ignore-start - id: directory uses: hoverkraft-tech/ci-github-common/actions/working-directory@66882b24f9f13e45a6541896a5a7c638cb91c94c with: working-directory: ${{ inputs.working-directory }} - # jscpd:ignore-end - id: audit shell: bash working-directory: ${{ steps.directory.outputs.absolute-path }} diff --git a/actions/lint/README.md b/actions/lint/README.md index 209f085..86421a1 100644 --- a/actions/lint/README.md +++ b/actions/lint/README.md @@ -2,14 +2,29 @@ # ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Lint Python +
+ Lint Python +
+ +--- + + + + + [![Marketplace](https://img.shields.io/badge/Marketplace-lint--python-blue?logo=github-actions)](https://github.com/marketplace/actions/lint-python) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-python)](https://github.com/hoverkraft-tech/ci-github-python/releases) +[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-python)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-python/blob/main/CONTRIBUTING.md) + + + ## Overview @@ -21,34 +36,27 @@ Declare all three in the default uv dependency groups and configure them in All three execute even after one fails. A trusted Bash `command` replaces defaults; emit SARIF or Checkstyle to retain annotations from custom checks. + + + Run [setup-python](../setup-python/README.md) first with the same `working-directory`. -This action reuses the installed environment. Use the same reviewed commit SHA -for both actions. Do not populate command inputs from untrusted pull request text. -```yaml -- uses: hoverkraft-tech/ci-github-python/actions/lint@main - with: - working-directory: . -``` +Native reports survive command failures and are retained for seven days. +See the [continuous integration workflow](../../.github/workflows/continuous-integration.md#reports-and-permissions) for consolidated reporting and permissions. -### Reports + -Native reports are retained for seven days, including after command failures. -Only report files are uploaded, with unique names for parallel calls. When no -reports are produced, `report-artifact-id` is empty. GitHub summaries and -annotations need only `contents: read`; individual PR comments are not created. -Use the common [ci-reports workflow](https://github.com/hoverkraft-tech/ci-github-common/blob/main/.github/workflows/ci-reports.yml) -for consolidated comments and set `report-group` to the outer calling job ID. + -See the [continuous integration workflow](../../.github/workflows/continuous-integration.md) for orchestration and version matrices. + + - ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-python/actions/lint@0efcccef629a5715a6dff199a1b45add8eb5b397 # main +- uses: hoverkraft-tech/ci-github-python/actions/lint@f9227d0f443be4edbb7aacfc0701caaf25523f77 # fix/enforce-lint-checks with: # uv project directory. # Default: `.` @@ -62,6 +70,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ``` + ## Inputs @@ -73,8 +82,10 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int | **`report-group`** | Outer calling job ID for consolidated ci-reports. Defaults to the current job ID. No individual PR comments are posted. | **false** | - | + + ## Outputs @@ -84,14 +95,40 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int | **`report-artifact-id`** | Native report artifact ID. Empty when no reports were produced. | + + + + + + + + +## Contributing + +Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-python/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/). + + --- @@ -99,3 +136,5 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor). + + diff --git a/actions/lint/action.test.cjs b/actions/lint/action.test.cjs new file mode 100644 index 0000000..2e6226f --- /dev/null +++ b/actions/lint/action.test.cjs @@ -0,0 +1,26 @@ +const assert = require("node:assert/strict"); +const fs = require("node:fs"); +const path = require("node:path"); +const test = require("node:test"); +const { + createWorkspace, + runActionStep, +} = require("../../tests/action-test-helpers.cjs"); + +const actionFile = path.join(__dirname, "action.yml"); + +test("custom commands retain quoting and fail without continuing to default tools", (t) => { + const directory = createWorkspace(t); + const output = path.join(directory, "command output.txt"); + const result = runActionStep(actionFile, "run", directory, { + COMMAND: 'printf "%s" "$VALUE" > "$OUTPUT"\nexit 17', + OUTPUT: output, + VALUE: 'quotes " and $(not-executed)', + }); + assert.equal(result.status, 17, result.stderr); + assert.notEqual( + runActionStep(actionFile, "run", directory, { COMMAND: " " }).status, + 0, + ); + assert.equal(fs.readFileSync(output, "utf8"), 'quotes " and $(not-executed)'); +}); diff --git a/actions/lint/action.yml b/actions/lint/action.yml index 201e9ff..7efc4f4 100644 --- a/actions/lint/action.yml +++ b/actions/lint/action.yml @@ -1,6 +1,5 @@ +--- name: Lint Python -# Usage is self-contained in every generated action readme. -# jscpd:ignore-start description: | Run project-locked Ruff, Black and mypy. @@ -9,27 +8,15 @@ description: | All three execute even after one fails. A trusted Bash `command` replaces defaults; emit SARIF or Checkstyle to retain annotations from custom checks. - Run [setup-python](../setup-python/README.md) first with the same `working-directory`. - This action reuses the installed environment. Use the same reviewed commit SHA - for both actions. Do not populate command inputs from untrusted pull request text. - - ```yaml - - uses: hoverkraft-tech/ci-github-python/actions/lint@main - with: - working-directory: . - ``` + + - ### Reports + Run [setup-python](../setup-python/README.md) first with the same `working-directory`. - Native reports are retained for seven days, including after command failures. - Only report files are uploaded, with unique names for parallel calls. When no - reports are produced, `report-artifact-id` is empty. GitHub summaries and - annotations need only `contents: read`; individual PR comments are not created. - Use the common [ci-reports workflow](https://github.com/hoverkraft-tech/ci-github-common/blob/main/.github/workflows/ci-reports.yml) - for consolidated comments and set `report-group` to the outer calling job ID. + Native reports survive command failures and are retained for seven days. + See the [continuous integration workflow](../../.github/workflows/continuous-integration.md#reports-and-permissions) for consolidated reporting and permissions. - See the [continuous integration workflow](../../.github/workflows/continuous-integration.md) for orchestration and version matrices. -# jscpd:ignore-end + author: hoverkraft branding: icon: package @@ -47,17 +34,14 @@ inputs: outputs: report-artifact-id: description: Native report artifact ID. Empty when no reports were produced. - value: ${{ steps.upload-reports.outputs.artifact-id }} + value: ${{ steps.report-artifact.outputs.artifact-id }} runs: using: composite steps: - # Shared working-directory validation, kept at each standalone entry point. - # jscpd:ignore-start - id: directory uses: hoverkraft-tech/ci-github-common/actions/working-directory@66882b24f9f13e45a6541896a5a7c638cb91c94c with: working-directory: ${{ inputs.working-directory }} - # jscpd:ignore-end - id: run shell: bash working-directory: ${{ steps.directory.outputs.absolute-path }} @@ -79,51 +63,11 @@ runs: uv run --locked mypy . || status=1 exit "$status" - name: Report lint results - id: reports + id: report-artifact if: ${{ !cancelled() && steps.run.outcome != 'skipped' }} - uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@66882b24f9f13e45a6541896a5a7c638cb91c94c + uses: $/.github/actions/parse-ci-reports with: - working-directory: ${{ steps.directory.outputs.absolute-path }} - report-paths: |- - auto:lint - !**/.venv/** - !**/.git/** - !**/.cache/** - !**/vendor/** + directory: ${{ steps.directory.outputs.absolute-path }} + report-paths: auto:lint report-name: Python lint results - output-format: annotations,summary,markdown - # Shared native artifact contract, also used by the test action. - # jscpd:ignore-start - - id: report-artifact - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 - if: ${{ !cancelled() && steps.run.outcome != 'skipped' }} - env: - DIRECTORY: ${{ steps.directory.outputs.absolute-path }} - REPORT_FILES: ${{ steps.reports.outputs.parsed-files }} - REPORT_GROUP: ${{ inputs.report-group || github.job }} - NATIVE_COVERAGE: "false" - with: - script: | - const fs = require('node:fs'); - const path = require('node:path'); - const files = JSON.parse(process.env.REPORT_FILES || '[]'); - if (process.env.NATIVE_COVERAGE === 'true') { - const coverage = path.join(process.env.DIRECTORY, 'coverage.out'); - if (fs.existsSync(coverage)) files.push(coverage); - } - if (!files.length) return; - const group = process.env.REPORT_GROUP; - if (!/^[\w-]+$/.test(group)) throw new Error('report-group must be a job ID.'); - core.setOutput('files', files.join('\n')); - core.setOutput('name', `ci-reports-${process.env.GITHUB_RUN_ATTEMPT}-${group}-${require('node:crypto').randomUUID()}`); - - id: upload-reports - name: Retain native reports - if: ${{ !cancelled() && steps.report-artifact.outputs.files != '' }} - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 - with: - name: ${{ steps.report-artifact.outputs.name }} - path: ${{ steps.report-artifact.outputs.files }} - include-hidden-files: true - if-no-files-found: error - retention-days: 7 - # jscpd:ignore-end + group: ${{ inputs.report-group || github.job }} diff --git a/actions/package/test/README.md b/actions/package/test/README.md index cc21cae..27e73f3 100644 --- a/actions/package/test/README.md +++ b/actions/package/test/README.md @@ -2,14 +2,29 @@ # ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Test Python distribution +
+ Test Python distribution +
+ +--- + + + + + [![Marketplace](https://img.shields.io/badge/Marketplace-test--python--distribution-blue?logo=github-actions)](https://github.com/marketplace/actions/test-python-distribution) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-python)](https://github.com/hoverkraft-tech/ci-github-python/releases) +[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-python)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-python/blob/main/CONTRIBUTING.md) + + + ## Overview @@ -29,25 +44,26 @@ execute code; there is no general equivalent to npm's `ignore-scripts` switch. The action does not publish to PyPI. Enable it in the reusable workflow with `package: "true"` or a JSON object containing `tests`. -Run [setup-python](../../setup-python/README.md) first with the same `working-directory`. -This action reuses the installed environment. Use the same reviewed commit SHA -for both actions. Do not populate command inputs from untrusted pull request text. + + -```yaml -- uses: hoverkraft-tech/ci-github-python/actions/package/test@main - with: - working-directory: . -``` +Run [setup-python](../../setup-python/README.md) first with the same `working-directory`. See the [continuous integration workflow](../../../.github/workflows/continuous-integration.md) for orchestration and version matrices. + + + + + + ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-python/actions/package/test@0efcccef629a5715a6dff199a1b45add8eb5b397 # main +- uses: hoverkraft-tech/ci-github-python/actions/package/test@f9227d0f443be4edbb7aacfc0701caaf25523f77 # fix/enforce-lint-checks with: # uv package directory with a build-system. # Default: `.` @@ -58,6 +74,7 @@ See the [continuous integration workflow](../../../.github/workflows/continuous- ``` + ## Inputs @@ -68,18 +85,46 @@ See the [continuous integration workflow](../../../.github/workflows/continuous- | **`commands`** | Optional trusted Bash smoke tests run separately against the installed wheel and sdist. The consumer venv is on PATH; PACKAGE_NAME and PACKAGE_VERSION identify the distribution. Source checkout is not the working directory. | **false** | - | + + + + + + + + + + +## Contributing + +Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-python/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/). + + --- @@ -87,3 +132,5 @@ See the [continuous integration workflow](../../../.github/workflows/continuous- This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor). + + diff --git a/actions/package/test/action.yml b/actions/package/test/action.yml index 2cb68f9..ead4f39 100644 --- a/actions/package/test/action.yml +++ b/actions/package/test/action.yml @@ -1,6 +1,5 @@ +--- name: Test Python distribution -# Usage is self-contained in every generated action readme. -# jscpd:ignore-start description: | Build and test a wheel and source distribution in clean consumers. @@ -17,18 +16,14 @@ description: | The action does not publish to PyPI. Enable it in the reusable workflow with `package: "true"` or a JSON object containing `tests`. - Run [setup-python](../../setup-python/README.md) first with the same `working-directory`. - This action reuses the installed environment. Use the same reviewed commit SHA - for both actions. Do not populate command inputs from untrusted pull request text. + + - ```yaml - - uses: hoverkraft-tech/ci-github-python/actions/package/test@main - with: - working-directory: . - ``` + Run [setup-python](../../setup-python/README.md) first with the same `working-directory`. See the [continuous integration workflow](../../../.github/workflows/continuous-integration.md) for orchestration and version matrices. -# jscpd:ignore-end + + author: hoverkraft branding: icon: package @@ -43,13 +38,10 @@ inputs: runs: using: composite steps: - # Shared working-directory validation, kept at each standalone entry point. - # jscpd:ignore-start - id: directory uses: hoverkraft-tech/ci-github-common/actions/working-directory@66882b24f9f13e45a6541896a5a7c638cb91c94c with: working-directory: ${{ inputs.working-directory }} - # jscpd:ignore-end - id: package shell: bash working-directory: ${{ steps.directory.outputs.absolute-path }} diff --git a/actions/setup-python/README.md b/actions/setup-python/README.md index 5c0a07e..a758192 100644 --- a/actions/setup-python/README.md +++ b/actions/setup-python/README.md @@ -2,14 +2,29 @@ # ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Setup Python +
+ Setup Python +
+ +--- + + + + + [![Marketplace](https://img.shields.io/badge/Marketplace-setup--python-blue?logo=github-actions)](https://github.com/marketplace/actions/setup-python) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-python)](https://github.com/hoverkraft-tech/ci-github-python/releases) +[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-python)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-python/blob/main/CONTRIBUTING.md) + + + ## Overview @@ -48,15 +63,24 @@ steps: working-directory: . ``` + + + See the [continuous integration workflow](../../.github/workflows/continuous-integration.md) for orchestration and version matrices. + + + + + + ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-python/actions/setup-python@0efcccef629a5715a6dff199a1b45add8eb5b397 # main +- uses: hoverkraft-tech/ci-github-python/actions/setup-python@f9227d0f443be4edbb7aacfc0701caaf25523f77 # fix/enforce-lint-checks with: # uv project directory inside the checkout. # Default: `.` @@ -75,6 +99,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ``` + ## Inputs @@ -87,8 +112,10 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int | **`install-dependencies`** | Synchronize locked dependencies and the project. Disable for tooling-only jobs. | **false** | `true` | + + ## Outputs @@ -98,14 +125,40 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int | **`uv-version`** | Installed uv version. | + + + + + + + + +## Contributing + +Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-python/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/). + + --- @@ -113,3 +166,5 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor). + + diff --git a/actions/setup-python/action.test.cjs b/actions/setup-python/action.test.cjs new file mode 100644 index 0000000..f1410bc --- /dev/null +++ b/actions/setup-python/action.test.cjs @@ -0,0 +1,48 @@ +const assert = require("node:assert/strict"); +const fs = require("node:fs"); +const path = require("node:path"); +const test = require("node:test"); +const { + createWorkspace, + runActionStep, +} = require("../../tests/action-test-helpers.cjs"); + +const actionFile = path.join(__dirname, "action.yml"); + +test("setup rejects invalid booleans and missing project manifests", (t) => { + const directory = createWorkspace(t); + for (const value of ["false", "invalid"]) { + assert.notEqual( + runActionStep(actionFile, "validate", directory, { + INSTALL_DEPENDENCIES: value, + }).status, + 0, + ); + } + fs.writeFileSync(path.join(directory, "pyproject.toml"), ""); + assert.equal( + runActionStep(actionFile, "validate", directory, { + INSTALL_DEPENDENCIES: "false", + }).status, + 0, + ); + assert.notEqual( + runActionStep(actionFile, "validate", directory, { + INSTALL_DEPENDENCIES: "invalid", + }).status, + 0, + ); + assert.notEqual( + runActionStep(actionFile, "validate", directory, { + INSTALL_DEPENDENCIES: "true", + }).status, + 0, + ); + fs.writeFileSync(path.join(directory, "uv.lock"), ""); + assert.equal( + runActionStep(actionFile, "validate", directory, { + INSTALL_DEPENDENCIES: "true", + }).status, + 0, + ); +}); diff --git a/actions/setup-python/action.yml b/actions/setup-python/action.yml index 0057f29..ba426cc 100644 --- a/actions/setup-python/action.yml +++ b/actions/setup-python/action.yml @@ -1,6 +1,5 @@ +--- name: Setup Python -# Usage is self-contained in every generated action readme. -# jscpd:ignore-start description: | Install Python and uv, cache downloads and synchronize locked dependencies. @@ -36,8 +35,12 @@ description: | working-directory: . ``` + + + See the [continuous integration workflow](../../.github/workflows/continuous-integration.md) for orchestration and version matrices. -# jscpd:ignore-end + + author: hoverkraft branding: icon: package @@ -62,13 +65,10 @@ outputs: runs: using: composite steps: - # Shared working-directory validation, kept at each standalone entry point. - # jscpd:ignore-start - id: directory uses: hoverkraft-tech/ci-github-common/actions/working-directory@66882b24f9f13e45a6541896a5a7c638cb91c94c with: working-directory: ${{ inputs.working-directory }} - # jscpd:ignore-end - id: validate shell: bash working-directory: ${{ steps.directory.outputs.absolute-path }} diff --git a/actions/test/README.md b/actions/test/README.md index 00cf470..cd07641 100644 --- a/actions/test/README.md +++ b/actions/test/README.md @@ -2,14 +2,29 @@ # ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Test Python +
+ Test Python +
+ +--- + + + + + [![Marketplace](https://img.shields.io/badge/Marketplace-test--python-blue?logo=github-actions)](https://github.com/marketplace/actions/test-python) [![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-python)](https://github.com/hoverkraft-tech/ci-github-python/releases) +[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-python)](http://choosealicense.com/licenses/mit/) [![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-python?style=social) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-python/blob/main/CONTRIBUTING.md) + + + ## Overview @@ -21,39 +36,37 @@ coverage sources in `[tool.coverage.run]` to avoid measuring unrelated code. A trusted Bash `command` replaces the default and must produce JUnit for test reporting and `cobertura.xml` for coverage. The common parser handles both formats. -Run [setup-python](../setup-python/README.md) first with the same `working-directory`. -This action reuses the installed environment. Use the same reviewed commit SHA -for both actions. Do not populate command inputs from untrusted pull request text. + + -```yaml -- uses: hoverkraft-tech/ci-github-python/actions/test@main - with: - working-directory: . -``` - -### Reports +Run [setup-python](../setup-python/README.md) first with the same `working-directory`. -Native reports are retained for seven days, including after command failures. -Only report files are uploaded, with unique names for parallel calls. When no -reports are produced, `report-artifact-id` is empty. GitHub summaries and -annotations need only `contents: read`; individual PR comments are not created. -Use the common [ci-reports workflow](https://github.com/hoverkraft-tech/ci-github-common/blob/main/.github/workflows/ci-reports.yml) -for consolidated comments and set `report-group` to the outer calling job ID. + `coverage: "github"` is the default. Set `coverage: "codecov"` and grant the job `id-token: write` for OIDC upload of `cobertura.xml`. An empty coverage value disables publication while retaining JUnit; collection is controlled by the command. Custom commands must produce the applicable report files. -See the [continuous integration workflow](../../.github/workflows/continuous-integration.md) for orchestration and version matrices. + + + +Native reports survive command failures and are retained for seven days. +See the [continuous integration workflow](../../.github/workflows/continuous-integration.md#reports-and-permissions) for consolidated reporting and permissions. + + + + + + ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-python/actions/test@0efcccef629a5715a6dff199a1b45add8eb5b397 # main +- uses: hoverkraft-tech/ci-github-python/actions/test@f9227d0f443be4edbb7aacfc0701caaf25523f77 # fix/enforce-lint-checks with: # uv project directory. # Default: `.` @@ -73,6 +86,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ``` + ## Inputs @@ -85,8 +99,10 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int | **`report-group`** | Outer calling job ID for consolidated ci-reports. Defaults to the current job ID. No individual PR comments are posted. | **false** | - | + + ## Outputs @@ -96,14 +112,40 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int | **`report-artifact-id`** | Native report artifact ID. Empty when no reports were produced. | + + + + + + + + +## Contributing + +Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-python/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/). + + --- @@ -111,3 +153,5 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor). + + diff --git a/actions/test/action.test.cjs b/actions/test/action.test.cjs new file mode 100644 index 0000000..25ba88b --- /dev/null +++ b/actions/test/action.test.cjs @@ -0,0 +1,44 @@ +const assert = require("node:assert/strict"); +const fs = require("node:fs"); +const path = require("node:path"); +const test = require("node:test"); +const { + createWorkspace, + runActionStep, +} = require("../../tests/action-test-helpers.cjs"); + +const actionFile = path.join(__dirname, "action.yml"); + +test("custom commands retain quoting and fail without continuing to default tools", (t) => { + const directory = createWorkspace(t); + const output = path.join(directory, "command output.txt"); + const result = runActionStep(actionFile, "run", directory, { + COMMAND: 'printf "%s" "$VALUE" > "$OUTPUT"\nexit 17', + OUTPUT: output, + VALUE: 'quotes " and $(not-executed)', + }); + assert.equal(result.status, 17, result.stderr); + assert.notEqual( + runActionStep(actionFile, "run", directory, { COMMAND: " " }).status, + 0, + ); + assert.equal(fs.readFileSync(output, "utf8"), 'quotes " and $(not-executed)'); +}); + +test("test configuration rejects unsupported coverage destinations", (t) => { + const directory = createWorkspace(t); + assert.notEqual( + runActionStep(actionFile, "validate", directory, { + COVERAGE: "wrong", + RACE: "true", + }).status, + 0, + ); + assert.equal( + runActionStep(actionFile, "validate", directory, { + COVERAGE: "", + RACE: "true", + }).status, + 0, + ); +}); diff --git a/actions/test/action.yml b/actions/test/action.yml index 995ee99..0143251 100644 --- a/actions/test/action.yml +++ b/actions/test/action.yml @@ -1,6 +1,5 @@ +--- name: Test Python -# Usage is self-contained in every generated action readme. -# jscpd:ignore-start description: | Run project-locked pytest with JUnit and Cobertura coverage. @@ -9,32 +8,25 @@ description: | A trusted Bash `command` replaces the default and must produce JUnit for test reporting and `cobertura.xml` for coverage. The common parser handles both formats. - Run [setup-python](../setup-python/README.md) first with the same `working-directory`. - This action reuses the installed environment. Use the same reviewed commit SHA - for both actions. Do not populate command inputs from untrusted pull request text. - - ```yaml - - uses: hoverkraft-tech/ci-github-python/actions/test@main - with: - working-directory: . - ``` + + - ### Reports + Run [setup-python](../setup-python/README.md) first with the same `working-directory`. - Native reports are retained for seven days, including after command failures. - Only report files are uploaded, with unique names for parallel calls. When no - reports are produced, `report-artifact-id` is empty. GitHub summaries and - annotations need only `contents: read`; individual PR comments are not created. - Use the common [ci-reports workflow](https://github.com/hoverkraft-tech/ci-github-common/blob/main/.github/workflows/ci-reports.yml) - for consolidated comments and set `report-group` to the outer calling job ID. + `coverage: "github"` is the default. Set `coverage: "codecov"` and grant the job `id-token: write` for OIDC upload of `cobertura.xml`. An empty coverage value disables publication while retaining JUnit; collection is controlled by the command. Custom commands must produce the applicable report files. - See the [continuous integration workflow](../../.github/workflows/continuous-integration.md) for orchestration and version matrices. -# jscpd:ignore-end + + + + Native reports survive command failures and are retained for seven days. + See the [continuous integration workflow](../../.github/workflows/continuous-integration.md#reports-and-permissions) for consolidated reporting and permissions. + + author: hoverkraft branding: icon: package @@ -55,17 +47,14 @@ inputs: outputs: report-artifact-id: description: Native report artifact ID. Empty when no reports were produced. - value: ${{ steps.upload-reports.outputs.artifact-id }} + value: ${{ steps.report-artifact.outputs.artifact-id }} runs: using: composite steps: - # Shared working-directory validation, kept at each standalone entry point. - # jscpd:ignore-start - id: directory uses: hoverkraft-tech/ci-github-common/actions/working-directory@66882b24f9f13e45a6541896a5a7c638cb91c94c with: working-directory: ${{ inputs.working-directory }} - # jscpd:ignore-end - id: validate shell: bash env: @@ -86,51 +75,14 @@ runs: fi bash --noprofile --norc -e -u -o pipefail -c "$COMMAND" - name: Report test results - id: reports + id: report-artifact if: ${{ !cancelled() && steps.run.outcome != 'skipped' }} - uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@66882b24f9f13e45a6541896a5a7c638cb91c94c + uses: $/.github/actions/parse-ci-reports with: - working-directory: ${{ steps.directory.outputs.absolute-path }} - report-paths: |- - ${{ inputs.coverage == 'github' && 'auto:test,auto:coverage' || 'auto:test' }} - !**/.venv/** - !**/.git/** - !**/.cache/** - !**/vendor/** + directory: ${{ steps.directory.outputs.absolute-path }} + report-paths: ${{ inputs.coverage == 'github' && 'auto:test,auto:coverage' || 'auto:test' }} report-name: Python test results - output-format: annotations,summary,markdown - - id: report-artifact - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 - if: ${{ !cancelled() && steps.run.outcome != 'skipped' }} - env: - DIRECTORY: ${{ steps.directory.outputs.absolute-path }} - REPORT_FILES: ${{ steps.reports.outputs.parsed-files }} - REPORT_GROUP: ${{ inputs.report-group || github.job }} - NATIVE_COVERAGE: "false" - with: - script: | - const fs = require('node:fs'); - const path = require('node:path'); - const files = JSON.parse(process.env.REPORT_FILES || '[]'); - if (process.env.NATIVE_COVERAGE === 'true') { - const coverage = path.join(process.env.DIRECTORY, 'coverage.out'); - if (fs.existsSync(coverage)) files.push(coverage); - } - if (!files.length) return; - const group = process.env.REPORT_GROUP; - if (!/^[\w-]+$/.test(group)) throw new Error('report-group must be a job ID.'); - core.setOutput('files', files.join('\n')); - core.setOutput('name', `ci-reports-${process.env.GITHUB_RUN_ATTEMPT}-${group}-${require('node:crypto').randomUUID()}`); - - id: upload-reports - name: Retain native reports - if: ${{ !cancelled() && steps.report-artifact.outputs.files != '' }} - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 - with: - name: ${{ steps.report-artifact.outputs.name }} - path: ${{ steps.report-artifact.outputs.files }} - include-hidden-files: true - if-no-files-found: error - retention-days: 7 + group: ${{ inputs.report-group || github.job }} - name: Upload coverage to Codecov if: ${{ !cancelled() && steps.run.outcome != 'skipped' && inputs.coverage == 'codecov' }} uses: hoverkraft-tech/ci-github-common/actions/quality/codecov@66882b24f9f13e45a6541896a5a7c638cb91c94c diff --git a/biome.json b/biome.json index 825a8d6..a5f148a 100644 --- a/biome.json +++ b/biome.json @@ -4,9 +4,6 @@ "clientKind": "git", "useIgnoreFile": true }, - "files": { - "includes": ["**", "!!.devcontainer/devcontainer-lock.json"] - }, "formatter": { "indentStyle": "space" } diff --git a/docs/development/README.md b/docs/development/README.md index 7c81327..46fdd6f 100644 --- a/docs/development/README.md +++ b/docs/development/README.md @@ -2,7 +2,9 @@ Install Node.js from `.node-version`, npm, uv and a supported Python runtime, and Docker. Node.js and the development-only `yaml` dependency exercise the actual inline -Actions configuration scripts. No JavaScript build or runtime bundle is shipped. +Actions configuration scripts. Lint and test actions share the internal +[parse-ci-reports action](../../.github/actions/parse-ci-reports/README.md), which owns +file selection, unique artifact naming and uploads. ```sh make setup @@ -16,17 +18,46 @@ Use a private disk-backed temporary directory or the managed scratch wrapper for local tests. Keep caches under ignored `.cache/` and clean disposable files after use. `make ci` runs checks without automatically fixing source. +## Dev container + +Open the repository with Visual Studio Code's "Dev Containers: Reopen in Container" command +or create a GitHub Codespace. The [configuration](../../.devcontainer/devcontainer.json) +provides Node.js, uv and the Python runtime selected by the fixture, GitHub CLI with `gh act`, +and Docker-in-Docker for `make lint` and `make docs`. +Nested Docker requires a host that supports privileged containers. + +The container runs development commands as `vscode` and waits for `make setup` +to install dependencies before attaching. Run `make ci` in its terminal to execute +the repository checks. Setup uses the fixture's `.python-version` and `uv.lock`. +Visual Studio Code uses the resulting fixture virtual environment, with Black +and Ruff extensions. + +The container uses the Microsoft Debian base image directly and installs tools +through Dev Container features. Dependabot maintains the features and their +[lockfile](../../.devcontainer/devcontainer-lock.json). Feature defaults select +tool versions when rebuilding. Rebuild after changing the configuration or lockfile. + ## Coverage The Node tests execute workflow configuration directly to check matrix selection, -disable switches and invalid input. Action boundary tests execute real Bash -command wrappers to detect quoting and failure-propagation bugs, validate setup -preconditions and check artifact selection. They do not mock language tools. - -`__test-workflow-continuous-integration.yml` calls the public workflow with real -fixture versions and checks disabled behavior. Each action has a dedicated -`__test-action-*.yml` workflow, called by `__shared-ci.yml`. These cover standalone -setup, default commands, failure propagation and retrieval of retained reports. +disable switches and invalid input. +Action contract tests live beside each action as `action.test.cjs`, including +[setup](../../actions/setup-python/action.test.cjs), +[lint](../../actions/lint/action.test.cjs), [test](../../actions/test/action.test.cjs) +and [report parsing](../../.github/actions/parse-ci-reports/action.test.cjs). +They execute the actual Bash and JavaScript from adjacent action metadata to +check quoting, failure propagation, setup preconditions and artifact selection. +`make test` discovers these files and the workflow configuration tests. + +In CI, each action's `action.test.cjs` runs in its dedicated +`__test-action-*.yml` workflow, alongside checks for standalone setup, default +commands, failure propagation and retrieval of retained reports. +`__test-workflow-continuous-integration.yml` runs only the workflow configuration +Node tests and calls the public workflow with real fixture versions and checks +disabled behavior. `__shared-ci.yml` calls all these test workflows. +The [`ci-github-nodejs` test action](https://github.com/hoverkraft-tech/ci-github-nodejs/tree/main/actions/test) +handles Node setup and dependency caching, installs locked dependencies with +lifecycle scripts disabled, and runs `test:ci` with the suite path from `arguments`. These GitHub runner/artifact boundaries cannot be covered by local unit tests. The fixture is deliberately small; it validates action wiring rather than the language's arithmetic implementation. @@ -34,12 +65,16 @@ language's arithmetic implementation. ## Documentation Edit action metadata or workflow header comments, then run `make docs`. -This uses the same CI Dokumentor release as the shared `release-actions.yml` -workflow. Never edit generated action readmes or workflow reference files by hand. +The same CI Dokumentor release as the shared `release-actions.yml` workflow +updates the existing reference sections directly. Never edit generated action +readmes or workflow reference files by hand. Usage belongs directly in generated action and workflow readmes. Put source guidance in action descriptions and workflow header comments so `make docs` preserves it. Contributor procedures belong here. +Documentation generation reads GitHub metadata for repository logos and licensing. +Set `GITHUB_TOKEN` when authentication is required or anonymous API limits are reached. + ## Maintenance and releases External actions are pinned to immutable commits. Dependabot updates actions, @@ -59,13 +94,18 @@ the consumer repository using its registry and release policy. ## Branding -The SVG assets use the [Hoverkraft project badge](https://github.com/hoverkraft-tech/branding/tree/main/brand/identity) -and [Inter](https://github.com/rsms/inter). Text is outlined so rendering does -not depend on installed fonts. `.github/logo.svg` is the compact badge; -`.github/social-preview.svg` is the source for the 1280 x 640 PNG preview. -After changing the SVG, export the PNG at those dimensions and inspect both. -The Python mark comes from the [Python Software Foundation](https://www.python.org/community/logos/) -and retains its original colors and proportions. +The SVG assets derive from the supplied Hoverkraft project artwork. Outlined +wordmarks and language marks preserve the supplied shapes without requiring fonts. +`.github/logo.svg` contains the compact badge. `.github/social-preview.svg` places +the full badge and wordmark on a white 1280 x 640 canvas; export it at those exact +dimensions to regenerate `.github/social-preview.png` and inspect the result. + +Duplication checks include every repository source and reference file. Inline +markers cover repeated generated API sections and repository boilerplate in +the references. Action metadata marks only repeated setup and reporting +paragraphs; unique overview text and examples remain checked. The generator +preserves these markers, and all Markdown sections still receive formatting and +Markdown validation. -Duplication checks exclude generated references, self-contained usage descriptions -and the shared SVG artwork. Executable workflow steps remain checked. +Super-Linter reads the fixture's `pyproject.toml` for Black, Ruff, isort and mypy. +It uses the same first-party import classification as project-local checks. diff --git a/package.json b/package.json index 493cef3..6054c70 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "private": true, "description": "Development-only tests for GitHub Actions configuration", "scripts": { - "test": "node --test tests/*.test.cjs" + "test": "node --test tests/*.test.cjs actions/*/*.test.cjs .github/actions/*/*.test.cjs", + "test:ci": "node --test" }, "devDependencies": { "yaml": "2.9.1" diff --git a/tests/action-test-helpers.cjs b/tests/action-test-helpers.cjs new file mode 100644 index 0000000..ae8c8ca --- /dev/null +++ b/tests/action-test-helpers.cjs @@ -0,0 +1,40 @@ +const fs = require("node:fs"); +const os = require("node:os"); +const path = require("node:path"); +const { spawnSync } = require("node:child_process"); +const YAML = require("yaml"); + +function loadActionStep(actionFile, id) { + const action = YAML.parse(fs.readFileSync(actionFile, "utf8")); + return action.runs.steps.find((step) => step.id === id); +} + +function createWorkspace(t) { + const directory = fs.mkdtempSync(path.join(os.tmpdir(), "ci-actions-")); + t.after(() => fs.rmSync(directory, { recursive: true, force: true })); + return directory; +} + +function runActionStep(actionFile, id, directory, env) { + return spawnSync( + "bash", + [ + "--noprofile", + "--norc", + "-e", + "-u", + "-o", + "pipefail", + "-c", + loadActionStep(actionFile, id).run, + ], + { + cwd: directory, + env: { ...process.env, ...env }, + encoding: "utf8", + timeout: 10000, + }, + ); +} + +module.exports = { createWorkspace, loadActionStep, runActionStep }; diff --git a/tests/actions.test.cjs b/tests/actions.test.cjs deleted file mode 100644 index 63ef4a2..0000000 --- a/tests/actions.test.cjs +++ /dev/null @@ -1,147 +0,0 @@ -const assert = require("node:assert/strict"); -const fs = require("node:fs"); -const os = require("node:os"); -const path = require("node:path"); -const { spawnSync } = require("node:child_process"); -const test = require("node:test"); -const YAML = require("yaml"); - -const load = (name) => - YAML.parse(fs.readFileSync(`actions/${name}/action.yml`, "utf8")); -const step = (name, id) => load(name).runs.steps.find((item) => item.id === id); -const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor; - -function workspace(t) { - const directory = fs.mkdtempSync(path.join(os.tmpdir(), "ci-actions-")); - t.after(() => fs.rmSync(directory, { recursive: true, force: true })); - return directory; -} - -function run(name, id, directory, env) { - return spawnSync( - "bash", - [ - "--noprofile", - "--norc", - "-e", - "-u", - "-o", - "pipefail", - "-c", - step(name, id).run, - ], - { - cwd: directory, - env: { ...process.env, ...env }, - encoding: "utf8", - timeout: 10000, - }, - ); -} - -test("custom commands retain quoting and fail without continuing to default tools", (t) => { - const directory = workspace(t); - for (const action of ["lint", "test"]) { - const output = path.join(directory, `${action} output.txt`); - const result = run(action, "run", directory, { - COMMAND: 'printf "%s" "$VALUE" > "$OUTPUT"\nexit 17', - OUTPUT: output, - VALUE: 'quotes " and $(not-executed)', - }); - assert.equal(result.status, 17, result.stderr); - assert.notEqual( - run(action, "run", directory, { COMMAND: " " }).status, - 0, - ); - assert.equal( - fs.readFileSync(output, "utf8"), - 'quotes " and $(not-executed)', - ); - } -}); - -test("setup rejects invalid booleans and missing project manifests", (t) => { - const directory = workspace(t); - const setup = "setup-python"; - for (const value of ["false", "invalid"]) { - assert.notEqual( - run(setup, "validate", directory, { INSTALL_DEPENDENCIES: value }).status, - 0, - ); - } - fs.writeFileSync(path.join(directory, "pyproject.toml"), ""); - assert.equal( - run(setup, "validate", directory, { INSTALL_DEPENDENCIES: "false" }).status, - 0, - ); - assert.notEqual( - run(setup, "validate", directory, { INSTALL_DEPENDENCIES: "invalid" }) - .status, - 0, - ); - assert.notEqual( - run(setup, "validate", directory, { INSTALL_DEPENDENCIES: "true" }).status, - 0, - ); - fs.writeFileSync(path.join(directory, "uv.lock"), ""); - assert.equal( - run(setup, "validate", directory, { INSTALL_DEPENDENCIES: "true" }).status, - 0, - ); -}); - -test("test configuration rejects unsupported coverage destinations", (t) => { - const directory = workspace(t); - assert.notEqual( - run("test", "validate", directory, { COVERAGE: "wrong", RACE: "true" }) - .status, - 0, - ); - assert.equal( - run("test", "validate", directory, { COVERAGE: "", RACE: "true" }).status, - 0, - ); -}); - -test("report artifacts contain only parsed reports and use unique names", async (t) => { - const directory = workspace(t); - const report = path.join(directory, "junit.xml"); - fs.writeFileSync(report, ""); - fs.writeFileSync( - path.join(directory, "unrelated-secret.txt"), - "not a report", - ); - const prepare = new AsyncFunction( - "core", - "process", - "require", - step("test", "report-artifact").with.script, - ); - async function outputs(files, group = "outer-job") { - const result = {}; - await prepare( - { - setOutput: (key, value) => { - result[key] = value; - }, - }, - { - env: { - DIRECTORY: directory, - REPORT_FILES: JSON.stringify(files), - REPORT_GROUP: group, - NATIVE_COVERAGE: "false", - GITHUB_RUN_ATTEMPT: "2", - }, - }, - require, - ); - return result; - } - assert.deepEqual(await outputs([]), {}); - const first = await outputs([report]); - assert.equal(first.files, report); - assert.match(first.name, /^ci-reports-2-outer-job-/); - assert.notEqual(first.name, (await outputs([report])).name); - await assert.rejects(() => outputs([report], "../bad-group"), /report-group/); -}); diff --git a/tests/python-project/pyproject.toml b/tests/python-project/pyproject.toml index ee286f5..134cba5 100644 --- a/tests/python-project/pyproject.toml +++ b/tests/python-project/pyproject.toml @@ -30,8 +30,19 @@ source = ["ci_python_fixture"] branch = true relative_files = true +[tool.black] +target-version = ["py313"] + [tool.mypy] strict = true +mypy_path = "$MYPY_CONFIG_FILE_DIR/src" [tool.ruff.lint] select = ["E", "F", "I", "UP", "B"] + +[tool.ruff.lint.isort] +known-first-party = ["ci_python_fixture"] + +[tool.isort] +profile = "black" +known_first_party = ["ci_python_fixture"] diff --git a/tests/python-project/tests/test_sample.py b/tests/python-project/tests/test_sample.py index edd95a5..dbc57e6 100644 --- a/tests/python-project/tests/test_sample.py +++ b/tests/python-project/tests/test_sample.py @@ -1,10 +1,13 @@ """Exercise the installed fixture package.""" -import pytest - from ci_python_fixture import add -@pytest.mark.parametrize(("left", "right", "expected"), [(2, 3, 5), (-2, 1, -1)]) -def test_add(left: int, right: int, expected: int) -> None: - assert add(left, right) == expected +def test_add_positive_numbers() -> None: + """Add two positive numbers.""" + assert add(2, 3) == 5 + + +def test_add_negative_number() -> None: + """Add numbers with opposite signs.""" + assert add(-2, 1) == -1