8000 fix: address workflow issues for GitHub Actions compatibility · coder/coder@00a4fb0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 00a4fb0

Browse files
EdwardAngertclaude
andcommitted
fix: address workflow issues for GitHub Actions compatibility
- Fix branch name extraction with fallbacks for CI environments - Add conditional handling for PR context in docs-unified workflow - Improve error handling in cross-reference validation - Use fixed string matching instead of regex for safer pattern matching - Remove hardcoded assignee in favor of team assignments - Improve JSON parsing with proper error handling for lychee results - Add more reliable newline handling for GitHub issue creation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b555621 commit 00a4fb0

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ runs:
448448
echo "status=success" >> $GITHUB_OUTPUT
449449
echo "result=" >> $GITHUB_OUTPUT
450450
451-
# Setup regex patterns for cross-references
452-
MD_LINK_PATTERN='\[([^\]]+)\]\(([^)]+)\)'
451+
# Setup regex patterns for cross-references (escape special regex characters)
452+
MD_LINK_PATTERN='\[[^\]]+\]\([^)]+\)'
453453
ANCHOR_LINK_PATTERN='\(#[^)]+\)'
454454
455455
# Get the base commit to compare against
@@ -474,8 +474,14 @@ runs:
474474
475475
# Check if file exists in commit
476476
if git cat-file -e $commit:$file 2>/dev/null; then
477-
git show $commit:$file | grep -E '^#{1,6} ' | sed 's/^#* //' | tr -d '`' | \
478-
tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9 -]//g' | sed 's/ /-/g'
477+
# Extract and process headings with error handling
478+
git show $commit:$file 2>/dev/null | grep -E '^#{1,6} ' |
479+
while IFS= read -r line; do
480+
echo "$line" | sed 's/^#* //' | tr -d '`' |
481+
tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9 -]//g' | sed 's/ /-/g' || echo ""
482+
done
483+
else
484+
echo "File not found in commit: $file@$commit" >&2
479485
fi
480486
}
481487
@@ -537,9 +543,10 @@ runs:
537543
for heading in $old_headings; do
538544
if ! echo "$new_headings" | grep -q "$heading"; then
539545
# This heading was removed or changed
540-
# Look for references to this heading
541-
sanitized=${heading//\//\\/} # Escape / for grep
542-
refs=$(grep -r --include="*.md" -l "#$sanitized)" . || echo "")
546+
# Look for references to this heading with proper escaping
547+
# Use grep -F for fixed string matching instead of regex
548+
sanitized="${heading}"
549+
refs=$(grep -r --include="*.md" -F -l "#$sanitized)" . || echo "")
543550
544551
if [ -n "$refs" ]; then
545552
for ref_file in $refs; do
@@ -573,8 +580,10 @@ runs:
573580
id: generate-preview
574581
shell: bash
575582
run: |
576-
# Simple branch name extraction and URL generation
577-
BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's/[^a-zA-Z0-9_-]/-/g')
583+
# Robust branch name extraction with fallbacks for CI environments
584+
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" | sed 's/[^a-zA-Z0-9_-]/-/g')
585+
# Store branch for other steps
586+
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
578587
echo "url=https://coder.com/docs/@$BRANCH" >> $GITHUB_OUTPUT
579588
580589
# Generate direct links to changed docs

.github/workflows/docs-link-check.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@ jobs:
8787
if [ -f "./lychee-result.json" ]; then
8888
echo "Reading link check results from lychee-result.json"
8989
90-
# Count broken links - lychee format is different from linkspector
91-
BROKEN_LINKS=$(jq '.data.failed | length' "./lychee-result.json")
90+
# Count broken links with error handling
91+
BROKEN_LINKS=0
92+
if jq -e '.data.failed' "./lychee-result.json" > /dev/null 2>&1; then
93+
BROKEN_LINKS=$(jq '.data.failed | length' "./lychee-result.json" || echo "0")
94+
fi
9295
echo "broken_links=$BROKEN_LINKS" >> $GITHUB_OUTPUT
9396
9497
if [ "$BROKEN_LINKS" -gt 0 ]; then
@@ -130,6 +133,15 @@ jobs:
130133
ISSUE_CONTENT+="2. Update the link if needed or remove it\n"
131134
ISSUE_CONTENT+="3. If the link is valid but fails the check, consider adding it to the ignore list in `.github/docs/.lycheeignore`\n\n"
132135
136+
# Use cat with heredoc instead of echo -e for more reliable newline handling
137+
cat << 'EOT' >> /tmp/issue-guidance.txt
138+
### Additional Guidance
139+
- For 404 errors: Check if the resource was moved or renamed
140+
- For timeout errors: The site might be temporarily down, consider retrying
141+
- For redirect issues: Update to the final URL
142+
EOT
143+
ISSUE_CONTENT+=$(cat /tmp/issue-guidance.txt)
144+
133145
ISSUE_CONTENT+="### For Broken Cross-References\n\n"
134146
ISSUE_CONTENT+="1. Update references to deleted or renamed files\n"
135147
ISSUE_CONTENT+="2. Update references to removed headings\n"
@@ -164,7 +176,8 @@ jobs:
164176
documentation
165177
bug
166178
needs-triage
167-
assignees: EdwardAngert # Assign to docs team lead
179+
# Configure assignee through CODEOWNERS or a team instead of hardcoding
180+
# Additional reviewers can be added in codeowners file or docs team
168181

169182
# Log result for troubleshooting
170183
- name: Log issue creation status

.github/workflows/docs-unified.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
# Phase 2: Prepare PR Information
6666
- name: Get PR info
6767
id: pr_info
68+
if: github.event.pull_request
6869
run: |
6970
set -euo pipefail
7071
PR_NUMBER=${{ github.event.pull_request.number }}

0 commit comments

Comments
 (0)
0