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

Commitf536a15

Browse files
claudedavid-fraley
authored andcommitted
feat(ci): add docs preview comment workflow for pull requests
1 parentb48e367 commitf536a15

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name:Docs Preview Comment
2+
3+
on:
4+
pull_request:
5+
types:[opened, synchronize, reopened]
6+
paths:
7+
-"docs/**"
8+
9+
permissions:
10+
pull-requests:write
11+
contents:read
12+
13+
jobs:
14+
comment-preview-link:
15+
runs-on:ubuntu-latest
16+
steps:
17+
-name:Checkout
18+
uses:actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8# v5.0.0
19+
with:
20+
persist-credentials:false
21+
22+
-name:Get changed docs files
23+
id:changed-files
24+
uses:tj-actions/changed-files@4563c729c555b4141fac99c80f699f571219b836# v45.0.7
25+
with:
26+
files:|
27+
docs/**/*.md
28+
separator:"\n"
29+
30+
-name:Generate preview links
31+
id:preview-links
32+
if:steps.changed-files.outputs.any_changed == 'true'
33+
run:|
34+
# URI encode the branch name
35+
BRANCH_NAME="${{ github.head_ref }}"
36+
ENCODED_BRANCH=$(printf '%s' "$BRANCH_NAME" | jq -sRr @uri)
37+
38+
# Generate preview links for each changed docs file
39+
PREVIEW_LINKS=""
40+
while IFS= read -r file; do
41+
if [[ -n "$file" && "$file" == docs/*.md ]]; then
42+
# Convert file path to URL path
43+
# Remove 'docs/' prefix and '.md' suffix
44+
DOC_PATH="${file#docs/}"
45+
DOC_PATH="${DOC_PATH%.md}"
46+
47+
# Generate preview URL
48+
PREVIEW_URL="https://coder.com/docs/@${ENCODED_BRANCH}/${DOC_PATH}"
49+
PREVIEW_LINKS="${PREVIEW_LINKS}- [\`${file}\`](${PREVIEW_URL})"$'\n'
50+
fi
51+
done <<< "${{ steps.changed-files.outputs.all_changed_files }}"
52+
53+
# Store the links in output
54+
echo "links<<EOF" >> $GITHUB_OUTPUT
55+
echo "$PREVIEW_LINKS" >> $GITHUB_OUTPUT
56+
echo "EOF" >> $GITHUB_OUTPUT
57+
58+
echo "encoded_branch=$ENCODED_BRANCH" >> $GITHUB_OUTPUT
59+
60+
-name:Find existing comment
61+
id:find-comment
62+
if:steps.changed-files.outputs.any_changed == 'true'
63+
uses:peter-evans/find-comment@1e8dcc190e7b1c9f00b5e9e0e8ce9c95ae6fb9d0# v3.2.0
64+
with:
65+
issue-number:${{ github.event.pull_request.number }}
66+
comment-author:"github-actions[bot]"
67+
body-includes:"📚 Documentation Preview"
68+
69+
-name:Create or update comment
70+
if:steps.changed-files.outputs.any_changed == 'true'
71+
uses:peter-evans/create-or-update-comment@e3e50edcbcd6c45e77fc2c35e9cc7d4cd6ad7541# v4.0.0
72+
with:
73+
comment-id:${{ steps.find-comment.outputs.comment-id }}
74+
issue-number:${{ github.event.pull_request.number }}
75+
edit-mode:replace
76+
body:|
77+
## 📚 Documentation Preview
78+
79+
Preview the documentation changes from this PR at:
80+
81+
**Base preview URL:** https://coder.com/docs/@${{ steps.preview-links.outputs.encoded_branch }}
82+
83+
### Changed documentation files:
84+
85+
${{ steps.preview-links.outputs.links }}
86+
87+
---
88+
89+
*Note: Preview links are generated based on the branch name `${{ github.head_ref }}`. It may take a few minutes for the preview to be available after pushing changes.*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp