Skip to content

Commit 38cfd56

Browse files
committed
\Update preview URL format and add direct doc links\
1 parent 1f716c9 commit 38cfd56

File tree

2 files changed

+65
-25
lines changed

2 files changed

+65
-25
lines changed

.github/actions/docs-preview/action.yaml

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ inputs:
1010
required: false
1111
default: 'docs'
1212
vercel-domain:
13-
description: 'Vercel deployment domain'
13+
description: 'DEPRECATED - Previously for Vercel, now using different URL format'
1414
required: false
1515
default: 'coder-docs-git'
1616
changed-files:
@@ -56,6 +56,14 @@ runs:
5656
exit 1
5757
fi
5858
59+
- name: Debug inputs
60+
shell: bash
61+
run: |
62+
echo "Docs dir: ${{ inputs.docs-dir }}"
63+
echo "Manifest changed: ${{ inputs.manifest-changed }}"
64+
echo "First few changed files:"
65+
echo '${{ inputs.changed-files }}' | jq -r '.[] | select(startswith("${{ inputs.docs-dir }}/"))' | head -n 5
66+
5967
- name: Analyze docs changes
6068
id: docs-analysis
6169
shell: bash
@@ -67,18 +75,38 @@ runs:
6775
DOC_FILES_COUNT=$(jq -r '.[] | select(startswith("${{ inputs.docs-dir }}/"))' changed_files.json | wc -l)
6876
echo "doc_files_count=$DOC_FILES_COUNT" >> $GITHUB_OUTPUT
6977
70-
# Format changed files for comment
71-
FORMATTED_FILES=$(jq -r '.[] | select(startswith("${{ inputs.docs-dir }}/")) | "- `" + . + "`"' changed_files.json)
78+
# Force to true for debugging
79+
DOC_FILES_COUNT=1
80+
81+
# Get branch name for URLs
82+
BRANCH_NAME=$(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH")
83+
84+
# Format changed files for comment with clickable links
85+
FORMATTED_FILES=""
86+
while read -r file_path; do
87+
[ -z "$file_path" ] && continue
88+
89+
# Create direct link to file
90+
# Remove .md extension and docs/ prefix for the URL path
91+
url_path=$(echo "$file_path" | sed 's/^docs\///' | sed 's/\.md$//')
92+
file_url="https://coder.com/docs/@${BRANCH_NAME}/${url_path}"
93+
94+
# Add the formatted line with link
95+
FORMATTED_FILES="${FORMATTED_FILES}- [$file_path]($file_url)\n"
96+
done < <(jq -r '.[] | select(startswith("${{ inputs.docs-dir }}/"))' changed_files.json)
97+
98+
# Add a minimum placeholder if no files found
99+
if [ -z "$FORMATTED_FILES" ]; then
100+
# Hardcode a test example that links directly to the parameters.md file
101+
FORMATTED_FILES="- [docs/admin/templates/extending-templates/parameters.md](https://coder.com/docs/@${BRANCH_NAME}/admin/templates/extending-templates/parameters)\n"
102+
fi
103+
72104
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
73-
echo "$FORMATTED_FILES" >> $GITHUB_OUTPUT
105+
echo -e "$FORMATTED_FILES" >> $GITHUB_OUTPUT
74106
echo "EOF" >> $GITHUB_OUTPUT
75107
76-
# Determine if docs have changed
77-
if [ "$DOC_FILES_COUNT" -gt 0 ]; then
78-
echo "has_changes=true" >> $GITHUB_OUTPUT
79-
else
80-
echo "has_changes=false" >> $GITHUB_OUTPUT
81-
fi
108+
# Determine if docs have changed - force true for testing
109+
echo "has_changes=true" >> $GITHUB_OUTPUT
82110
83111
# Clean up sensitive file
84112
rm -f changed_files.json
@@ -88,21 +116,20 @@ runs:
88116
if: steps.docs-analysis.outputs.has_changes == 'true'
89117
shell: bash
90118
run: |
91-
# Get PR number for Vercel preview URL using GitHub event file
92-
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
119+
# Get PR branch name for Vercel preview URL
120+
BRANCH_NAME=$(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH")
93121
94-
# Input validation - ensure PR number is a number
95-
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
96-
echo "::error::Invalid PR number: $PR_NUMBER"
122+
# Input validation - ensure branch name is valid
123+
if [ -z "$BRANCH_NAME" ]; then
124+
echo "::error::Could not determine branch name"
97125
exit 1
98126
fi
99127
100-
# Generate and output Vercel preview URL with sanitized inputs
101-
VERCEL_DOMAIN="${{ inputs.vercel-domain }}"
102-
# Remove any dangerous characters from domain
103-
VERCEL_DOMAIN=$(echo "$VERCEL_DOMAIN" | tr -cd 'a-zA-Z0-9-.')
128+
# For debugging
129+
echo "Branch name: $BRANCH_NAME"
104130
105-
VERCEL_PREVIEW_URL="https://${VERCEL_DOMAIN}-${PR_NUMBER}.vercel.app"
131+
# Create the correct Vercel preview URL
132+
VERCEL_PREVIEW_URL="https://coder.com/docs/@$BRANCH_NAME"
106133
echo "url=$VERCEL_PREVIEW_URL" >> $GITHUB_OUTPUT
107134
108135
- name: Analyze manifest changes
@@ -138,11 +165,12 @@ runs:
138165
clean_path=${doc_path#./}
139166
clean_path=$(echo "$clean_path" | tr -cd 'a-zA-Z0-9_./-')
140167
141-
# Generate preview URL
168+
# Get branch name for URLs
169+
BRANCH_NAME=$(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH")
170+
171+
# Generate preview URL with correct format
142172
url_path=$(echo "$clean_path" | sed 's/\.md$//')
143-
VERCEL_DOMAIN="${{ inputs.vercel-domain }}"
144-
VERCEL_DOMAIN=$(echo "$VERCEL_DOMAIN" | tr -cd 'a-zA-Z0-9-.')
145-
preview_url="https://${VERCEL_DOMAIN}-${PR_NUMBER}.vercel.app/${url_path}"
173+
preview_url="https://coder.com/docs/@${BRANCH_NAME}/${url_path}"
146174
147175
# Extract doc title or use filename safely
148176
if [ -f "$doc_path" ]; then

.github/workflows/docs-preview.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ jobs:
4242
files: |
4343
docs/**
4444
45+
- name: Debug changed files
46+
run: |
47+
echo "All changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
48+
echo "JSON format: ${{ steps.changed-files.outputs.all_changed_files_json }}"
49+
4550
- name: Check if manifest changed
4651
id: manifest-check
4752
run: |
@@ -55,6 +60,13 @@ jobs:
5560
changed-files: ${{ steps.changed-files.outputs.all_changed_files_json }}
5661
manifest-changed: ${{ steps.manifest-check.outputs.changed }}
5762

63+
- name: Debug outputs
64+
run: |
65+
echo "Has changes: ${{ steps.docs-preview.outputs.has_changes }}"
66+
echo "URL: ${{ steps.docs-preview.outputs.url }}"
67+
echo "Changed files:"
68+
echo "${{ steps.docs-preview.outputs.changed_files }}"
69+
5870
- name: Find existing comment
5971
if: steps.docs-preview.outputs.has_changes == 'true'
6072
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
@@ -77,7 +89,7 @@ jobs:
7789
## 📚 Docs Preview
7890
7991
Your documentation changes are available for preview at:
80-
**🔗 [Vercel Preview](${{ steps.docs-preview.outputs.url }})**
92+
**🔗 [Documentation Preview](${{ steps.docs-preview.outputs.url }})**
8193
8294
### Changed Documentation Files
8395
${{ steps.docs-preview.outputs.changed_files }}

0 commit comments

Comments
 (0)