diff --git a/.gitea/workflows/review.yml b/.gitea/workflows/review.yml index 9eea230..1d93a2d 100644 --- a/.gitea/workflows/review.yml +++ b/.gitea/workflows/review.yml @@ -55,6 +55,9 @@ on: type: string required: false default: claude-sonnet-5-5 + # Gitea 28.3 does not tell a called workflow its own ref (github.workflow_ref and + # job_workflow_sha are empty, and GITHUB_WORKFLOW_SHA is the caller's commit), so + # the caller names the tool version twice. tool_ref: description: "Branch or tag of docs-review to run; keep it equal to the @ref in uses:" type: string @@ -102,19 +105,10 @@ jobs: # a pull request cannot replace the tool. steps: - name: Versions - env: - PROBE_WORKFLOW_REF: ${{ github.workflow_ref }} - PROBE_JOB_WORKFLOW_SHA: ${{ github.job_workflow_sha }} - PROBE_JOB_WORKFLOW_REF: ${{ github.job_workflow_ref }} run: | python3 --version git --version node --version - echo "probe workflow_ref=[$PROBE_WORKFLOW_REF]" - echo "probe job_workflow_sha=[$PROBE_JOB_WORKFLOW_SHA]" - echo "probe job_workflow_ref=[$PROBE_JOB_WORKFLOW_REF]" - echo "probe RUNNER_TEMP=[${RUNNER_TEMP:-}]" - env | grep -E '^GITHUB_' | grep -viE 'TOKEN' | sort | sed 's/^/probe /' - name: Fetch docs-review run: | @@ -150,19 +144,8 @@ jobs: GIT_CONFIG_VALUE_0="Authorization: token $DOCS_REVIEW_BOT_TOKEN" src="$(mktemp -d)" if ! git clone -q -- "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" "$src"; then - python3 -P -c 'import os, urllib.request, urllib.error - for path in ("/user", "/repos/" + os.environ["GITHUB_REPOSITORY"]): - req = urllib.request.Request(os.environ["GITHUB_SERVER_URL"] + "/api/v1" + path, headers={"Authorization": "token " + os.environ["DOCS_REVIEW_BOT_TOKEN"]}) - try: - r = urllib.request.urlopen(req, timeout=20); print("probe", path, r.status) - except urllib.error.HTTPError as e: - print("probe", path, e.code, e.read()[:300])' - url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" - GIT_CONFIG_VALUE_0="Authorization: Bearer $DOCS_REVIEW_BOT_TOKEN" git ls-remote -q "$url" >/dev/null 2>&1 && echo "probe bearer ok" || echo "probe bearer fail" - basic="$(printf 'docs-review-bot:%s' "$DOCS_REVIEW_BOT_TOKEN" | base64 -w0)" - GIT_CONFIG_VALUE_0="Authorization: Basic $basic" git ls-remote -q "$url" >/dev/null 2>&1 && echo "probe basic ok" || echo "probe basic fail" - GIT_CONFIG_COUNT=0 git ls-remote -q "$GITHUB_SERVER_URL/Civilytics/docs-review.git" >/dev/null 2>&1 && echo "probe anon public ok" || echo "probe anon public fail" - GIT_CONFIG_VALUE_0="Authorization: token $DOCS_REVIEW_BOT_TOKEN" git ls-remote -q "$GITHUB_SERVER_URL/Civilytics/docs-review.git" >/dev/null 2>&1 && echo "probe token public ok" || echo "probe token public fail" + echo "::error::the bot token could not clone $GITHUB_REPOSITORY; it needs the" \ + "write:repository scope and write access to the repository" exit 1 fi cd "$src" diff --git a/README.md b/README.md index d1be633..85ac7bf 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,6 @@ the documents the change makes stale. If the repository opts in, it also has Cla Code draft the edits. It is a Python package with no dependencies outside the standard library. -## Status - -The Python package and its tests are published here. The reusable Gitea Actions -workflow is not yet published, so the install snippet below is provisional and may -change. - ## What it does Stage 1 compares the pull request's changes with the documents you list. It uses no model @@ -55,27 +49,73 @@ committed, and everything posted to Gitea has credential values replaced with `* ## Install -Install instructions will be added with the reusable workflow. Until then, the package -can be run by hand: `python3 -m docs_review pr|closed|monthly --help`. +Add a workflow to the repository you want reviewed, at `.gitea/workflows/docs-review.yml`: + +```yaml +name: docs-review +on: + pull_request: + branches: [main] + types: [opened, synchronize, reopened, closed] + schedule: + - cron: "0 9 1 * *" # the monthly pass, on the first of the month + workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} +jobs: + docs: + uses: Civilytics/docs-review/.gitea/workflows/review.yml@v1 + with: + tool_ref: v1 + drafter: none + docs: | + README.md + docs/*.md + doc_guide: docs/README.md + secrets: inherit +``` + +- `closed` in the pull request types lets the workflow close a docs pull request whose + feature pull request merged or closed first. +- The `concurrency` block cancels a run when the pull request is pushed again. With + `drafter: claude` the workflow waits three minutes between stage 1 and drafting, so a + quick re-push cancels a run before it has spent anything. +- `tool_ref` must name the same version as the `@` in `uses:`. Gitea does not tell a + called workflow which ref it was called at, so the workflow fetches the tool's code at + `tool_ref`. +- A `workflow_dispatch` run is the monthly pass for the current month. + +The job runs in the `node:22` image. It clones the repository with the bot token, so +it needs no checkout action, and it installs Claude Code +(`@anthropic-ai/claude-code`, a pinned version) only when `drafter` is `claude` and a +Claude credential is set. With `drafter: claude` and no credential, it posts the stage 1 +comment with a note saying so and fails. The drafter's cost and turn count are printed +in the log and appended to `$GITHUB_STEP_SUMMARY`. + +The package can also be run by hand: `python3 -m docs_review pr|closed|monthly --help`. ## Inputs | Input | Default | Meaning | |---|---|---| -| `drafter` | `none` | `none` flags only. `claude` also drafts edits. `local` is accepted but not yet built. | +| `drafter` | `none` | `none` flags only. `claude` also drafts edits. `local` is accepted but not yet built. Any other value, including a misspelling, behaves as `none`. | | `docs` | required | Newline-separated patterns for the living documents. | | `generated` | none | Patterns for generated files. | | `top_level` | `README.md` | The subset of `docs` the monthly pass re-reads in full. | -| `source_dirs` | `R scripts` | Directories whose files count as source. | +| `source_dirs` | `R` and `scripts` | Newline-separated directories whose files count as source. | | `workstream` | `docs` | Scope in draft commit messages, as `docs(): ...`. | | `tracking_issue` | none | Issue number the monthly pass's commit messages cite. | | `doc_guide` | none | Path to the document that says who reads each listed document and what it is for. The drafter writes for that reader. | | `model` | `claude-sonnet-5-5` | Model used when `drafter` is `claude`. | +| `tool_ref` | `v1` | The docs-review branch or tag to run; the same as the `@` in `uses:`. | ## Secrets - `DOCS_REVIEW_BOT_TOKEN` is required. It is a token for a Gitea bot account with - repository write, issue write and user read permissions. + write access to the repository and the token scopes `write:repository`, + `write:issue` and `read:user`. An organization secret serves every repository in the + organization. - `CLAUDE_CODE_OAUTH_TOKEN` or `ANTHROPIC_API_KEY` is needed only for `drafter: claude`.