Skip to content

docs: unify documentation workflows with improved validation #17522

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d0fe1f8
Add simplified docs preview GitHub action
EdwardAngert Apr 9, 2025
3010c77
Merge branch 'main' into simplified-docs-preview
EdwardAngert Apr 9, 2025
afbdde9
\Fix tj-actions/changed-files SHA to match existing usage\n\nUpdate t…
EdwardAngert Apr 9, 2025
1f716c9
\Fix docs preview workflow to ensure PR comments are posted\n\nUpdate…
EdwardAngert Apr 9, 2025
38cfd56
\Update preview URL format and add direct doc links\
EdwardAngert Apr 9, 2025
e072e92
Add shared docs GitHub action
EdwardAngert Apr 9, 2025
07e93b0
test: Add heading to docs README
EdwardAngert Apr 9, 2025
6a7a2bc
Add test workflow
EdwardAngert Apr 9, 2025
4fcb322
Unified documentation workflow
EdwardAngert Apr 23, 2025
777bddc
Enhance documentation workflows with cross-reference checking
EdwardAngert Apr 23, 2025
992c592
Enhance PR comment with informative status overview and collapsible s…
EdwardAngert Apr 23, 2025
6420b3f
Optimize workflow logic and improve Vale style checking
EdwardAngert Apr 23, 2025
0a464f3
enhance: optimize workflow with unified reporting and concurrency
EdwardAngert Apr 23, 2025
3840432
refactor: replace linkspector with lychee for link checking
EdwardAngert Apr 23, 2025
b555621
refactor: combine documentation workflow optimizations
EdwardAngert Apr 23, 2025
00a4fb0
fix: address workflow issues for GitHub Actions compatibility
EdwardAngert Apr 23, 2025
ba403f2
docs: update GitHub Actions documentation
EdwardAngert Apr 23, 2025
168b54b
Merge branch 'main' into feature/unified-docs-workflow-combined
EdwardAngert Apr 23, 2025
6a0c1c1
fix: remove duplicate docs example workflows and fix caching issues
EdwardAngert Apr 23, 2025
8a29450
fix: update lychee-action configuration for v1 compatibility
EdwardAngert Apr 23, 2025
e37cda8
fix readme
EdwardAngert Apr 23, 2025
749d142
fix: correct YAML syntax in docs-link-check.yaml
EdwardAngert Apr 23, 2025
90a9ca8
chore: use caret versioning for tj-actions/changed-files
EdwardAngert Apr 23, 2025
bb9e393
fix: update actions and preview URL handling
EdwardAngert Apr 23, 2025
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
Prev Previous commit
Next Next commit
\Update preview URL format and add direct doc links\
  • Loading branch information
EdwardAngert committed Apr 9, 2025
commit 38cfd56eaf6e8c21604341083b50ed4ffa95c8f9
76 changes: 52 additions & 24 deletions .github/actions/docs-preview/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
required: false
default: 'docs'
vercel-domain:
description: 'Vercel deployment domain'
description: 'DEPRECATED - Previously for Vercel, now using different URL format'
required: false
default: 'coder-docs-git'
changed-files:
Expand Down Expand Up @@ -56,6 +56,14 @@ runs:
exit 1
fi

- name: Debug inputs
shell: bash
run: |
echo "Docs dir: ${{ inputs.docs-dir }}"
echo "Manifest changed: ${{ inputs.manifest-changed }}"
echo "First few changed files:"
echo '${{ inputs.changed-files }}' | jq -r '.[] | select(startswith("${{ inputs.docs-dir }}/"))' | head -n 5

- name: Analyze docs changes
id: docs-analysis
shell: bash
Expand All @@ -67,18 +75,38 @@ runs:
DOC_FILES_COUNT=$(jq -r '.[] | select(startswith("${{ inputs.docs-dir }}/"))' changed_files.json | wc -l)
echo "doc_files_count=$DOC_FILES_COUNT" >> $GITHUB_OUTPUT

# Format changed files for comment
FORMATTED_FILES=$(jq -r '.[] | select(startswith("${{ inputs.docs-dir }}/")) | "- `" + . + "`"' changed_files.json)
# Force to true for debugging
DOC_FILES_COUNT=1

# Get branch name for URLs
BRANCH_NAME=$(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH")

# Format changed files for comment with clickable links
FORMATTED_FILES=""
while read -r file_path; do
[ -z "$file_path" ] && continue

# Create direct link to file
# Remove .md extension and docs/ prefix for the URL path
url_path=$(echo "$file_path" | sed 's/^docs\///' | sed 's/\.md$//')
file_url="https://coder.com/docs/@${BRANCH_NAME}/${url_path}"

# Add the formatted line with link
FORMATTED_FILES="${FORMATTED_FILES}- [$file_path]($file_url)\n"
done < <(jq -r '.[] | select(startswith("${{ inputs.docs-dir }}/"))' changed_files.json)

# Add a minimum placeholder if no files found
if [ -z "$FORMATTED_FILES" ]; then
# Hardcode a test example that links directly to the parameters.md file
FORMATTED_FILES="- [docs/admin/templates/extending-templates/parameters.md](https://coder.com/docs/@${BRANCH_NAME}/admin/templates/extending-templates/parameters)\n"
fi

echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$FORMATTED_FILES" >> $GITHUB_OUTPUT
echo -e "$FORMATTED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

# Determine if docs have changed
if [ "$DOC_FILES_COUNT" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
# Determine if docs have changed - force true for testing
echo "has_changes=true" >> $GITHUB_OUTPUT

# Clean up sensitive file
rm -f changed_files.json
Expand All @@ -88,21 +116,20 @@ runs:
if: steps.docs-analysis.outputs.has_changes == 'true'
shell: bash
run: |
# Get PR number for Vercel preview URL using GitHub event file
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
# Get PR branch name for Vercel preview URL
BRANCH_NAME=$(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH")

# Input validation - ensure PR number is a number
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "::error::Invalid PR number: $PR_NUMBER"
# Input validation - ensure branch name is valid
if [ -z "$BRANCH_NAME" ]; then
echo "::error::Could not determine branch name"
exit 1
fi

# Generate and output Vercel preview URL with sanitized inputs
VERCEL_DOMAIN="${{ inputs.vercel-domain }}"
# Remove any dangerous characters from domain
VERCEL_DOMAIN=$(echo "$VERCEL_DOMAIN" | tr -cd 'a-zA-Z0-9-.')
# For debugging
echo "Branch name: $BRANCH_NAME"

VERCEL_PREVIEW_URL="https://${VERCEL_DOMAIN}-${PR_NUMBER}.vercel.app"
# Create the correct Vercel preview URL
VERCEL_PREVIEW_URL="https://coder.com/docs/@$BRANCH_NAME"
echo "url=$VERCEL_PREVIEW_URL" >> $GITHUB_OUTPUT

- name: Analyze manifest changes
Expand Down Expand Up @@ -138,11 +165,12 @@ runs:
clean_path=${doc_path#./}
clean_path=$(echo "$clean_path" | tr -cd 'a-zA-Z0-9_./-')

# Generate preview URL
# Get branch name for URLs
BRANCH_NAME=$(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH")

# Generate preview URL with correct format
url_path=$(echo "$clean_path" | sed 's/\.md$//')
VERCEL_DOMAIN="${{ inputs.vercel-domain }}"
VERCEL_DOMAIN=$(echo "$VERCEL_DOMAIN" | tr -cd 'a-zA-Z0-9-.')
preview_url="https://${VERCEL_DOMAIN}-${PR_NUMBER}.vercel.app/${url_path}"
preview_url="https://coder.com/docs/@${BRANCH_NAME}/${url_path}"

# Extract doc title or use filename safely
if [ -f "$doc_path" ]; then
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/docs-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ jobs:
files: |
docs/**

- name: Debug changed files
run: |
echo "All changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
echo "JSON format: ${{ steps.changed-files.outputs.all_changed_files_json }}"

- name: Check if manifest changed
id: manifest-check
run: |
Expand All @@ -55,6 +60,13 @@ jobs:
changed-files: ${{ steps.changed-files.outputs.all_changed_files_json }}
manifest-changed: ${{ steps.manifest-check.outputs.changed }}

- name: Debug outputs
run: |
echo "Has changes: ${{ steps.docs-preview.outputs.has_changes }}"
echo "URL: ${{ steps.docs-preview.outputs.url }}"
echo "Changed files:"
echo "${{ steps.docs-preview.outputs.changed_files }}"

- name: Find existing comment
if: steps.docs-preview.outputs.has_changes == 'true'
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
Expand All @@ -77,7 +89,7 @@ jobs:
## 📚 Docs Preview

Your documentation changes are available for preview at:
**🔗 [Vercel Preview](${{ steps.docs-preview.outputs.url }})**
**🔗 [Documentation Preview](${{ steps.docs-preview.outputs.url }})**

### Changed Documentation Files
${{ steps.docs-preview.outputs.changed_files }}
Expand Down
Loading