diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index f8aeee56..9d09e193 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -361,3 +361,112 @@ jobs: run: | echo "✅ Integration test passed for ${{ matrix.repo }}" echo "The action successfully generated README from ${{ matrix.action_path }}" + + + pre-commit-hook: + name: Test published pre-commit hook + runs-on: ubuntu-latest + + steps: + - name: Checkout hook provider + uses: actions/checkout@v7.0.1 + with: + path: hook-source + persist-credentials: false + + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version: '3.13' + + - name: Setup Node.js for hook consumer + uses: actions/setup-node@v7.1.0 + with: + node-version: '24.19.0' + + - name: Install pre-commit + run: python -m pip install pre-commit==4.6.2 + + - name: Create consumer fixture + env: + HOOK_REPO: ${{ github.event.pull_request.head.repo.clone_url || format('https://github.com/{0}', github.repository) }} + HOOK_REF: ${{ github.event.pull_request.head.sha || github.sha }} + run: | + mkdir -p consumer/docs + cd consumer + git init + git config user.name "pre-commit smoke test" + git config user.email "pre-commit-smoke@example.invalid" + + cat > action.yml <<'YAML' + name: Consumer Action + description: Generated through the published pre-commit hook + runs: + using: composite + steps: [] + YAML + + cat > README.md <<'MARKDOWN' + # Default README + + + default README must stay stale + + MARKDOWN + + cat > docs/ACTION.md <<'MARKDOWN' + # Consumer + + + stale description + + MARKDOWN + + cat > .ghadocs.json <<'JSON' + { + "owner": "example", + "repo": "consumer-action", + "paths": { + "action": "action.yml", + "readme": "README.md" + }, + "sections": ["description"], + "prettier": false + } + JSON + + cat > .pre-commit-config.yaml </dev/null 2>&1 || ! command -v npx >/dev/null 2>&1; then + echo "github-action-readme-generator pre-commit hook requires Node.js and npm/npx." >&2 + exit 1 +fi + +script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +package_json="$script_dir/../package.json" +version=$(node -e 'const fs = require("node:fs"); const p = JSON.parse(fs.readFileSync(process.argv[1], "utf8")); process.stdout.write(p.version);' "$package_json") + +exec npx --yes "github-action-readme-generator@$version" "$@"