Skip to content

Add API docs preview workflow for pull requests - #21645

Open
NullVoxPopuli-ai-agent wants to merge 1 commit into
emberjs:mainfrom
NullVoxPopuli-ai-agent:nvp/api-docs-preview
Open

NullVoxPopuli-ai-agent wants to merge 1 commit into
emberjs:mainfrom
NullVoxPopuli-ai-agent:nvp/api-docs-preview

Conversation

@NullVoxPopuli-ai-agent

Copy link
Copy Markdown
Contributor

Add the api-docs-preview label to a PR. About 2 minutes later, a comment on the PR gives a link to the API docs site for that PR and the commands to view it.

Example comment, from a test PR in my fork: NullVoxPopuli-ai-agent#16 (comment)

Before the first use

  1. Create the api-docs-preview label. This repository does not have it.
  2. Merge this PR. GitHub starts the comment workflow only from main, so no comment can show on this PR itself.

What the preview is

The artifact is a build of ember-api-docs, the app of https://api.emberjs.com, with the docs of the PR. The data comes from the same steps as docs.yml: pnpm run docs, then ember-jsonapi-docs, then fix:files. The zip file is about 5 MB.

To view it, a reader runs two commands from the comment:

gh run download <run id> --repo emberjs/ember.js --name api-docs-preview --dir api-docs-preview-<sha>
npx http-server api-docs-preview-<sha> -c-1

A new commit on a labeled PR starts a new build, and the same comment gets the new link.

Why there are two workflow files

The build installs and runs code from the PR, and the comment needs write access. One job with both is the "pwn request" problem.

File Trigger Token Runs PR code
api-docs-preview.yml pull_request read-only, no secrets yes
api-docs-preview-comment.yml workflow_run pull-requests: write no

A PR from a fork gets a read-only token on pull_request, so the build workflow cannot post the comment.

The comment workflow reads no file from the artifact. It finds the PR from the head repository, branch, and SHA that GitHub supplies. A PR cannot change those values, so it cannot make the bot comment on a different PR.

Limits

  • The version list has only the version of the PR.
  • The search box shows results from the released docs.
  • A push to a PR without the label makes one skipped run of each workflow.

Tests

I ran both workflows in my fork, on a test PR:

  • An unrelated label: both runs skipped.
  • The api-docs-preview label: the build passed in 1.5 minutes, and the comment showed.
  • Two more commits: the same comment showed the new commit and the new link each time.
  • An unrelated label during a build: the build continued.
  • I ran the commands from the comment. The site showed a sentence that exists only in the test PR, also after a reload of a deep URL.

actionlint and zizmor 1.30.1 report no findings for the two files.

Not tested in a run: a PR from a different repository. For that case, I ran the PR lookup query against this repository with the values of #21630, and it returned 21630.

🤖 Generated with Claude Code

A pull request with the `api-docs-preview` label gets a build of the
ember-api-docs app with the docs of that pull request. The build is an
artifact, and a comment on the pull request gives the link and the
commands to view it.

Two workflows do the work. The build runs the code of the pull request,
so it runs on `pull_request` with a read-only token. The comment needs
write access, so it runs on `workflow_run` and runs no code from the
pull request.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants