mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
ci: post docs preview link on PRs that change docs (#24283)
*Disclaimer: implemented by a Coder Agent using Claude Opus 4.6* --- Adds a lightweight workflow that posts a docs preview link as a PR comment whenever a pull request touches files under `docs/`. The preview is served by coder.com's branch-preview feature at `/docs/@<branch>`. The branch name is URL-encoded so names with slashes (e.g. `user/feature`) produce correct links like `/docs/@user%2Ffeature` instead of broken paths. The comment is created on open and updated in-place on subsequent pushes using the `peter-evans/find-comment` + `create-or-update-comment` pattern already used by the `pr-deploy` workflow. --- Depends on https://github.com/coder/coder.com/pull/708
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
# This workflow posts a docs preview link as a PR comment whenever a
|
||||
# pull request that touches files under docs/ is opened. The preview
|
||||
# is served by coder.com's branch-preview feature at /docs/@<branch>.
|
||||
#
|
||||
# Branch names are URL-encoded so that names containing slashes or
|
||||
# other special characters produce working links.
|
||||
|
||||
name: docs-preview
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
paths:
|
||||
- "docs/**"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
docs-preview:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write # needed for commenting on PRs
|
||||
steps:
|
||||
- name: Post docs preview comment
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
BRANCH: ${{ github.event.pull_request.head.ref }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
run: |
|
||||
# URL-encode the branch name so slashes and special
|
||||
# characters don't break the preview URL.
|
||||
encoded=$(jq -rn --arg b "$BRANCH" '$b | @uri')
|
||||
url="https://coder.com/docs/@${encoded}"
|
||||
|
||||
gh pr comment "${PR_NUMBER}" \
|
||||
--repo "${{ github.repository }}" \
|
||||
--body "## Docs preview
|
||||
[:book: View docs preview](${url})
|
||||
|
||||
<!-- docs-preview -->"
|
||||
Reference in New Issue
Block a user