Preview pull requests
Build a viewer site per pull request, opened on Compare from the base branch to the pull request, and comment the Changes on it.
Before you start
Section titled “Before you start”- The Workspace publishes from CI. See Publish to GitHub Pages or Publish to GitLab Pages.
- You know what Compare shows. See Revisions and history.
1. Build the preview locally
Section titled “1. Build the preview locally”To see what CI will build, fetch the base branch, then build the preview from your pull request’s branch:
git fetch origin mainarchidocs build --preview --base main --out previewWrote the preview site to preview: Compare origin/main (83d7816) → PR (783c53a)Archidocs reads the base from origin/<base> and never fetches it. The flags are in the archidocs build reference.
2. Build it on every pull request
Section titled “2. Build it on every pull request”On GitHub, add a workflow that runs the Action with preview: true. It uploads the preview as the archidocs-preview workflow artifact:
name: Architecture previewon: pull_request
permissions: contents: read
jobs: preview: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: chalharb/archidocs@v1 id: archidocs with: preview: trueOn GitLab, skip this step: the template’s archidocs-preview job builds a preview on every merge request.
3. Deploy it where reviewers can browse it
Section titled “3. Deploy it where reviewers can browse it”Skip this step if reviewers download the artifact. GitHub Pages can’t host a site per pull request, so deploy the Action’s site output to a host that can:
- Netlify:
netlify deploy --dir "$SITE" --alias "pr-$PR_NUMBER". - Cloudflare Pages:
wrangler pages deploy "$SITE" --project-name <project> --branch "pr-$PR_NUMBER". - An S3-style bucket: sync it under a prefix, such as
s3://<bucket>/pr/<n>/.
4. Comment the Changes
Section titled “4. Comment the Changes”archidocs diff --format markdown writes the Changes as a table. Archidocs posts nothing itself, so post it as your CI user. On GitHub, add this job to the preview workflow:
comment: runs-on: ubuntu-latest permissions: contents: read pull-requests: write steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: 24 - run: npm install --global archidocs - name: Comment the architecture changes env: GH_TOKEN: ${{ github.token }} BASE: ${{ github.base_ref }} PR: ${{ github.event.pull_request.number }} run: | archidocs diff "origin/$BASE" HEAD --format markdown > architecture.md # Edit the comment this job posted before, or post one. gh pr comment "$PR" --body-file architecture.md --edit-last --create-if-noneOn GitLab, post architecture.md with the Notes API and a project access token.
Check it worked
Section titled “Check it worked”Open a pull request that changes the Model. The comment lists each Change:
### Model changes `origin/main (83d7816)` → `HEAD (783c53a)`
2 added, 0 removed, 0 changed.
| Change | Kind | Id | Fields || --- | --- | --- | --- || added | Element | `payments:payments-cache` | || added | Relationship | `payments:payments-service -> payments:payments-cache` | |Open the preview: it starts on the C2 Landscape with Compare “base → PR” on, and the added Elements marked.
If it didn’t
Section titled “If it didn’t”The build stops when the base branch isn’t in the checkout:
archidocs: origin/develop is not in this checkout; fetch the base branch before building (archidocs never fetches).Check out with fetch-depth: 0, or run git fetch origin <base> first.
If everything shows as added, the base branch has no Workspace yet. Compare then starts from an empty Model, which is expected for the first pull request.
Related
Section titled “Related”Documents the beta branch at cd98671, ahead of the latest release, v1.4.0.