Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add GitHub Action for automatic docs preview comments#20254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
david-fraley wants to merge3 commits intomain
base:main
Choose a base branch
Loading
fromdf/docs-preview-comment-action
Draft
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions.github/workflows/docs-preview-comment.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
# Automatically comment on PRs with doc preview links when docs/ files are changed
name: Docs Preview Comment

on:
# zizmor: ignore[dangerous-triggers] We explicitly want to run on pull_request_target for write permissions.
pull_request_target:
types: [opened, synchronize, reopened]
paths:
- 'docs/**'

permissions:
pull-requests: write
contents: read

jobs:
comment-preview-links:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
with:
egress-policy: audit

- name: Checkout PR
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false

- name: Get changed docs files
id: changed-files
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
# Get the list of changed files in docs/
git fetch origin "$BASE_REF"
CHANGED_DOCS=$(git diff --name-only "origin/$BASE_REF...HEAD" | grep '^docs/' | grep '\.md$' || true)

if [ -z "$CHANGED_DOCS" ]; then
echo "No markdown files changed in docs/"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi

echo "has_changes=true" >> "$GITHUB_OUTPUT"

# URI-encode the branch name
ENCODED_BRANCH=$(echo -n "$HEAD_REF" | jq -sRr @uri)

# Build the comment with preview links
COMMENT="## 📚 Documentation Preview Links\n\n"
COMMENT+="The following documentation pages have been modified and are available for preview:\n\n"

while IFS= read -r file; do
# Remove 'docs/' prefix and '.md' suffix
DOC_PATH="${file#docs/}"
DOC_PATH="${DOC_PATH%.md}"

# Build the preview URL
PREVIEW_URL="https://coder.com/docs/@${ENCODED_BRANCH}/${DOC_PATH}"

# Add to comment
COMMENT+="- [\`${file}\`](${PREVIEW_URL})\n"
done <<< "$CHANGED_DOCS"

COMMENT+="\n---\n"
COMMENT+="_Preview links are generated for branch: \`${HEAD_REF}\`_"

# Save comment to file for next step
echo -e "$COMMENT" > comment.txt

echo "Generated comment:"
cat comment.txt

- name: Find existing comment
if: steps.changed-files.outputs.has_changes == 'true'
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '## 📚 Documentation Preview Links'

- name: Create or update comment
if: steps.changed-files.outputs.has_changes == 'true'
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: comment.txt
edit-mode: replace

[8]ページ先頭

©2009-2025 Movatter.jp