Skip to content

Format the generated OpenAPI client in the Task pipeline, untrack the Task checksum, align spec-source docs - #40

Open
DzmitryHumianiuk wants to merge 4 commits into
masterfrom
chore/codegen-hygiene
Open

DzmitryHumianiuk wants to merge 4 commits into
masterfrom
chore/codegen-hygiene

Conversation

@DzmitryHumianiuk

@DzmitryHumianiuk DzmitryHumianiuk commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #39

task generate-openapi-client now formats its output with gofmt before it replaces pkg/openapi, and no longer asks the generator for .travis.yml, git_push.sh and README.md. The tracked Task checksum is removed from the index, and Taskfile.yml and AGENTS.md name the same spec source.

The generator was run with Docker (see the update comment): pkg/openapi is regenerated by the task in f014579. No .go file changed; the three dropped files are deleted and .openapi-generator/FILES / .openapi-generator-ignore are updated.

Changes

  • Taskfile.yml, generate-openapi-client:
    • new step gofmt -w "{{.GENERATED_DIR}}" after compat.go is copied and before the swap. A failed format keeps the committed client, like a failed generation does.
    • new step cp scripts/openapi-generator-ignore "{{.GENERATED_DIR}}/.openapi-generator-ignore" before the generator runs.
    • the spec-source comment names the demo URL (see below).
    • the generator container runs as the calling user (--user "$(id -u):$(id -g)", left out on Windows), so the output isn't owned by root on Linux.
    • --git-repo-id goRP/v5/pkg/openapi (was gorp/…).
  • .github/workflows/build.yml: new job openapi-drift runs the task and fails when pkg/openapi differs.
  • pkg/openapi: regenerated by the task (f014579).
  • scripts/openapi-generator-ignore (new): .travis.yml, git_push.sh, README.md.
  • .task/checksum/preprocess-schema: removed from the index (git rm --cached). .gitignore already has .task/.
  • AGENTS.md: spec source, the format step and the ignore list are described; scripts/ row mentions the new file.

Why plain gofmt

  • The committed client is plain gofmt output: gofmt -l pkg/openapi and gofmt -s -l pkg/openapi both print nothing.
  • golangci-lint formatters (gofumpt, gci, golines) skip generated files: .golangci.yml:30-31 has formatters.exclusions.generated: lax, and every file the generator writes has the Code generated … DO NOT EDIT header (373 of 374; the exception is compat.go, a hand-written template that gofmt -w leaves unchanged). So go fmt ./..., the first command of task fmt, is what formatted the committed tree.
  • gofmt -w <dir> needs no package loading and no Docker. It also formats compat.go, which is already gofmt-clean (pkg/openapi/compat.go equals the template byte for byte).

Generator leftovers: what is dropped and what is kept

File Decision Reason
.travis.yml drop Travis config for a standalone client repository. This client lives inside goRP, which uses GitHub Actions.
git_push.sh drop Script that pushes the directory to github.com/reportportal/gorp/v5/pkg/openapi. Not usable here.
README.md drop 797 lines; 682 links point to docs/*.md, which are not generated (modelDocs=false,apiDocs=false); the install snippet has the import path in the wrong case (gorp instead of goRP).
api/openapi.yaml keep The only committed copy of the preprocessed spec the client was generated from (openapi-modified.json is git-ignored). It makes the effect of a jq-filter change reviewable.
.gitignore, .openapi-generator/FILES, .openapi-generator/VERSION keep Harmless; FILES and VERSION record what was generated and by which generator version.

The ignore list lives in scripts/ and is copied in on every run, because the generator writes into a fresh build/openapi and pkg/openapi is replaced as a whole: the .openapi-generator-ignore that is committed in pkg/openapi is never read by this pipeline.

The three dropped files are deleted by the regeneration in f014579 (not by hand).

Spec source

  • The committed reportportal-api-docs.json was taken from https://beta.epmrpp.reportportal.io/api/api-docs. The only record of this is commit 3d526db, which replaced the spec and changed the Taskfile comment from demo to beta in one step. The host resolves to private addresses (10.x) and cannot be reached from outside, so this could not be checked against the host itself.
  • https://demo.reportportal.io/api/api-docs serves the same document: same size (731971 bytes), and identical after the example values are removed. The 15 differing values are random UUIDs and e-mail addresses; two downloads from demo a few seconds apart differ from each other in the same way. So the content shows the same service-api build (6.0.0), not which host it came from.
  • https://demo.reportportal.io/api/v1/api-docs (the URL in AGENTS.md) answers 401.
  • Both files now name https://demo.reportportal.io/api/api-docs as the canonical source (aedd18b); the internal host is no longer mentioned.

Not verified

  • The pipeline on a Linux host. All runs were on macOS with colima. The root-ownership problem and the --user fix were shown inside the Linux VM on a Docker volume, not by a full task generate-openapi-client on Linux. The first run of the openapi-drift job on this PR is that proof; the job has not run yet.
  • Podman / rootless Docker (possible regression, open question). AGENTS.md says Podman works through a docker symlink. In a rootless engine the container's root already is the host user, so the old command worked there. With --user uid:gid the process may become a subordinate id that cannot write the bind mount, and then generation fails. Not tried. If it fails, the flag has to be made conditional.
  • Windows. The --user flag is left out when Task reports OS = windows; this branch of the template was not executed.
  • gofmt across Go versions. The committed tree is formatted by gofmt 1.27.4. The CI job takes Go from go.mod. A later Go release that changes gofmt output would make the drift job fail until the client is regenerated.

Investigation log

Base: origin/master 517efe6. Go 1.27.4, darwin/arm64.

Format step:

  • gofmt -l pkg/openapi | wc -l → 0; gofmt -s -l pkg/openapi | wc -l → 0.
  • .golangci.yml:23-31: formatters gci, gofmt, gofumpt, goimports, golines, exclusions.generated: lax.
  • cmp scripts/openapi-compat/compat.go.tmpl pkg/openapi/compat.go → identical.
  • Proof on a copy outside the repository (codegen-work/proof.sh, codegen-work/perturb.py in the scratchpad):
    • step 0, cp -R pkg/openapi proof/build/openapi; diff -r → 0 lines.
    • step 1, gofmt -w "build/openapi" (the Taskfile command with the variable filled in); diff -r build/openapi <repo>/pkg/openapi → 0 lines.
    • step 2, whitespace-only damage: runs of spaces collapsed to one on lines without string literals or comments → 51 files differ, gofmt -l build/openapi lists 51.
    • step 3, gofmt -w "build/openapi" again → diff -r 0 lines, gofmt -l lists 0.
  • ruby -ryaml parses the edited Taskfile.yml; the generate-openapi-client commands are, in order: preprocess:schema, rm -rf, mkdir -p, cp …ignore, docker run … generate, cp compat.go.tmpl, gofmt -w, rm -rf, mv.

Checksum file:

  • git ls-files .task → .task/checksum/preprocess-schema; .gitignore:42 → .task/.
  • git log --diff-filter=A --format='%h %s' -- .task/checksum/preprocess-schema → 247d914 "CI: use govulncheck v1.9.0 and the latest Go 1.27 patch in lint and release".
  • After the commit: git ls-files -ci --exclude-standard prints nothing.

Spec source:

  • Taskfile.yml:16 (beta, /api/api-docs) against AGENTS.md:92 (demo, /api/v1/api-docs).
  • git log -S'beta.epmrpp' -- Taskfile.yml AGENTS.md README.md → 3d526db only; git show 3d526db -- Taskfile.yml shows the comment changing from demo to beta in the commit that replaced the spec.
  • jq '{openapi, info, servers}' reportportal-api-docs.json → OpenAPI 3.0.1, info.version 6.0.0, server /api, 251 paths, 322 schemas. The same for the demo snapshot consilium2/data/live-api-docs.json.
  • cmp of the two: differ; jq -S . | diff → 30 lines, all "example" (15 values).
  • curl https://demo.reportportal.io/api/api-docs twice → 200, 731971 bytes each, different SHA-256 (one equals the consilium snapshot).
  • jq -S 'walk(if type=="object" then del(.example) else . end)' | shasum -a 256 → f85036bd…8511e for the committed file and for both demo downloads.
  • curl https://demo.reportportal.io/api/v1/api-docs → 401 invalid_token.
  • curl https://demo.reportportal.io/api/info → service-api 6.0.0, branch rc/6.0.0-038258bf….
  • host beta.epmrpp.reportportal.io → 10.68.x.x; curl times out.

Generator leftovers:

  • git ls-files pkg/openapi | grep -v '\.go$' → .gitignore, .openapi-generator-ignore, .openapi-generator/FILES, .openapi-generator/VERSION, .travis.yml, README.md, api/openapi.yaml, git_push.sh.
  • pkg/openapi/.openapi-generator/FILES:3-5,53 lists .travis.yml, README.md, api/openapi.yaml, git_push.sh.
  • grep -c '](docs/' pkg/openapi/README.md → 682; pkg/openapi/docs does not exist; pkg/openapi/README.md:17 has the wrong-case import path.
  • Taskfile.yml:85-86 (rm -rf + mkdir -p of build/openapi) is why the committed .openapi-generator-ignore is never read.

Checks: go build ./..., go vet ./..., go test ./... pass (internal/commands, pkg/gorp ok). task lint not run (Docker); no Go file changed.

🤖 Generated with Claude Code

ghDmitry and others added 4 commits November 27, 2026 16:44
…ecksum

- generate-openapi-client: run gofmt on the generated code before it replaces pkg/openapi. The generator
  does not format its output and the committed client is gofmt-clean, so a regeneration shows
  formatting-only changes (372 files as reported in #33; not reproduced here, no Docker).
- generate-openapi-client: pass an ignore list (scripts/openapi-generator-ignore) so the generator stops
  writing .travis.yml, git_push.sh and README.md. The tracked copies go away with the next regeneration.
- Untrack .task/checksum/preprocess-schema: .task/ is git-ignored, the file was added in 247d914.
- Taskfile.yml and AGENTS.md now name the same spec source (/api/api-docs; beta is where the snapshot was
  taken, demo is the public equivalent). /api/v1/api-docs on demo answers 401.

Not run: the generator itself (needs Docker).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Output of `task generate-openapi-client` (openapi-generator v7.25.0, jq 1.8.1):
no .go file changes. The generator no longer writes .travis.yml, git_push.sh
and README.md, their entries leave .openapi-generator/FILES, and
.openapi-generator-ignore is now the copy of scripts/openapi-generator-ignore
(a pre-existing ignore file is not listed in FILES).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… demo as the spec source

- The generator container wrote its output as root on Linux, so the gofmt
  step and the next run's rm -rf would fail. It now runs with --user uid:gid.
- --git-repo-id uses the module path case (goRP). It only appears in
  README.md and git_push.sh, which are not generated any more.
- Taskfile.yml and AGENTS.md name https://demo.reportportal.io/api/api-docs
  as the canonical spec source.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@DzmitryHumianiuk

Copy link
Copy Markdown
Member Author

Update: the pipeline was run with Docker, the result is committed

task generate-openapi-client was run for real (Task v3.45.4, Docker 29.5.2 on colima, Go 1.27.4, darwin/arm64). Three commits were added on top of 9ac8742:

Commit What
f014579 Regenerated pkg/openapi (the output of the task, nothing edited by hand)
aedd18b Taskfile.yml: generator runs as the calling user, --git-repo-id case fixed, demo named as the spec source; AGENTS.md updated
03660d2 CI job openapi-drift in .github/workflows/build.yml

Regeneration result

  • No .go file changed: 374 .go files, 0 differ from the committed tree. api/openapi.yaml, .gitignore and .openapi-generator/VERSION (7.25.0) are unchanged too.
  • 5 files changed, 15 insertions, 886 deletions:
    • .travis.yml (8 lines), git_push.sh (54), README.md (797): deleted.
    • .openapi-generator/FILES: 4 lines removed. Three are the dropped files. The fourth is .openapi-generator-ignore: the generator lists that file only when it creates it, and now the Task puts it there first.
    • .openapi-generator-ignore: now the copy of scripts/openapi-generator-ignore.
  • The format step works on real generator output. The raw output is not gofmt-formatted (api_activities.go is 28807 bytes as generated and 28896 after the task; api_activity.go 35291 and 35682), and after gofmt -w 0 of 374 .go files differ from the committed tree.
  • The ignore list works when the file is placed in the output directory before the run. --ignore-file-override is not needed.
  • The result is reproducible: the task was run three times (as committed in 9ac8742, with the repo id changed, with --user added), and each run gave the same tree.

Changes made after the run

  1. File ownership (a real problem on Linux, fixed). The generator image runs as root. On macOS with colima the bind mount hides this (files show up as the host user), on a Linux filesystem the output is owned by root, and then gofmt -w and the next run's rm -rf fail. The generator container now runs with --user "$(id -u):$(id -g)" (skipped on Windows, which has no id and no such problem).
  2. --git-repo-id goRP/v5/pkg/openapi (was gorp/…). The value appears in two generated files only, and both are on the ignore list, so the committed output does not change. No import path or other code depends on it.
  3. Spec source. Taskfile.yml and AGENTS.md name https://demo.reportportal.io/api/api-docs as the canonical source. The internal host is no longer mentioned.
  4. CI drift job openapi-drift (ubuntu): task generate-openapi-client, then git add -A pkg/openapi and git diff --cached --stat --exit-code -- pkg/openapi. git add comes first so that a new untracked file also fails the job.

Verification

  • go build ./..., go vet ./..., go test -race ./...: pass (internal/commands, pkg/gorp ok).
  • golangci-lint v2.15.0 run ./...: 0 issues.
  • gofmt -l pkg/openapi: empty.
  • Taskfile.yml and .github/workflows/build.yml parse as YAML; the Taskfile was executed by Task itself.

Investigation log

  1. go run github.com/go-task/task/v3/cmd/task@v3.45.4 generate-openapi-client on 9ac8742 → exit 0. git status --short: M .openapi-generator-ignore, M .openapi-generator/FILES, D .travis.yml, D README.md, D git_push.sh, nothing else. git diff --stat: 5 files, +15 −886.
  2. Generator log: Ignored /generated/README.md (Ignored by rule in ignore file.), the same for git_push.sh and .travis.yml, and Skipped /generated/.openapi-generator-ignore (Skipped by supportingFiles options supplied by user.). The last line is why FILES lost a fourth entry.
  3. Repo id: generated twice by hand without the ignore list, once with gorp/v5/pkg/openapi and once with goRP/v5/pkg/openapi. diff -r of the two trees: README.md:18 (import openapi "github.com/reportportal/gorp/v5/pkg/openapi" → …/goRP/…) and git_push.sh:22 (git_repo_id="gorp/…" → "goRP/…"). No other file differs. With the ignore list the task output is identical for both values (run 2 = run 1).
  4. Ownership, default user: generated into a Docker named volume (a Linux filesystem inside the VM, not a macOS bind mount). id in the container → uid=0(root); every file and the api/ directory are 0 0.
  5. Ownership, effect: in a volume directory owned by uid 12345 with a root-owned a.go and api/openapi.yaml, as uid 12345: echo y >> a.go → Permission denied; rm -rf api → cannot remove 'api/openapi.yaml': Permission denied. These are the gofmt -w step and the rm -rf "build/openapi" step of the next run.
  6. Ownership, fix: the same generation with --user 12345:12345 → exit 0, 376 entries, everything owned by 12345 12345. On colima the task log shows docker run --rm --user 501:20 … and the output equals run 1.
  7. A bind mount from a path that is not shared with the colima VM (/private/tmp/…) gives exit 0 and an empty directory. Not a problem of this repository, but it explains an empty result if someone runs the task from such a path.

Scripts and logs (local scratch files, for re-running): <scratch>/regen.sh (runs the pinned Task; steps 1, 2, 6), <scratch>/regen40-probe.sh <worktree> <outdir under $HOME> (steps 3, 4, 6), logs <scratch>/regen40-run1.log, <scratch>/regen40-run2.log, <scratch>/regen40-run3.log. Step 5 was three one-off docker run commands on a named volume: chown 12345:12345 /generated as root, create a.go and api/openapi.yaml as root, then the two commands above with --user 12345:12345.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codegen hygiene: regeneration is not formatted, a Task checksum is tracked, docs name two spec sources

2 participants