forked from oracle-livelabs/common
-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (123 loc) · 5.56 KB
/
markdown-lint.yml
File metadata and controls
140 lines (123 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: LiveLabs Markdown Validation
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
jobs:
markdown-validation:
name: Validate Markdown Formatting
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get validation files from PR
id: changed-files
shell: bash
run: |
set -euo pipefail
BASE_SHA="${{ github.event.pull_request.base.sha }}"
PR_SHA="${{ github.sha }}"
git fetch --no-tags --prune origin "$BASE_SHA:$BASE_SHA" || true
# Get changed markdown files plus CDN-sensitive index.html / manifest.json files
VALIDATION_FILES=$(git diff --name-only --diff-filter=AM "$BASE_SHA" "$PR_SHA" | grep -E '\.md$|(^|/)(index\.html|manifest\.json)$' | grep -v '^\.github/' | grep -v '^node_modules/' || true)
MARKDOWN_FILES=$(printf '%s\n' "$VALIDATION_FILES" | grep '\.md$' || true)
if [ -z "$VALIDATION_FILES" ]; then
echo "No markdown, index.html, or manifest.json files changed"
echo "any_changed=false" >> $GITHUB_OUTPUT
else
echo "Changed validation files:"
echo "$VALIDATION_FILES"
# Store as space-separated for later use
echo "all_changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$VALIDATION_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "markdown_files<<EOF" >> $GITHUB_OUTPUT
echo "$MARKDOWN_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "any_changed=true" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install markdownlint-cli
if: steps.changed-files.outputs.any_changed == 'true'
run: npm install -g markdownlint-cli
- name: Run markdownlint
if: steps.changed-files.outputs.any_changed == 'true'
run: |
if [ -n "${{ steps.changed-files.outputs.markdown_files }}" ]; then
echo "Running markdownlint on PR markdown files..."
echo "${{ steps.changed-files.outputs.markdown_files }}" | xargs markdownlint --config .markdownlint.json || true
else
echo "No markdown files to lint."
fi
- name: Run LiveLabs format validation
if: steps.changed-files.outputs.any_changed == 'true'
run: |
curl -sSfL https://raw.githubusercontent.com/oracle-livelabs/common/refs/heads/main/.github/scripts/validate-livelabs-markdown.sh -o /tmp/validate-livelabs-markdown.sh
chmod +x /tmp/validate-livelabs-markdown.sh
echo "${{ steps.changed-files.outputs.all_changed_files }}" | xargs /tmp/validate-livelabs-markdown.sh
- name: Check image references exist
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo "Checking if referenced images exist..."
MISSING=0
while IFS= read -r file; do
[ -z "$file" ] && continue
dir=$(dirname "$file")
# Extract image paths from markdown - handle optional title like 
# Use perl regex for non-greedy matching and extract just the path before any space or quote
grep -oP '\!\[[^\]]*\]\(images/[^"\s\)]+' "$file" 2>/dev/null | grep -oP 'images/[^"\s\)]+' | while IFS= read -r img; do
full_path="$dir/$img"
if [ ! -f "$full_path" ]; then
echo "ERROR: Missing image in $file: $img"
echo "MISSING" > /tmp/missing_flag
fi
done
done <<< "${{ steps.changed-files.outputs.all_changed_files }}"
if [ -f /tmp/missing_flag ]; then
rm -f /tmp/missing_flag
echo "Some referenced images are missing!"
exit 1
fi
echo "All referenced images exist."
- name: Check filename conventions
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo "Checking filename conventions..."
INVALID=0
while IFS= read -r file; do
[ -z "$file" ] && continue
filename=$(basename "$file")
lowercase=$(echo "$filename" | tr '[:upper:]' '[:lower:]')
if [ "$filename" != "$lowercase" ]; then
echo "ERROR: Filename must be lowercase: $file"
INVALID=1
fi
if [[ "$filename" =~ [[:space:]] ]]; then
echo "ERROR: Filename contains spaces: $file"
INVALID=1
fi
done <<< "${{ steps.changed-files.outputs.all_changed_files }}"
if [ $INVALID -eq 1 ]; then
exit 1
fi
echo "All filenames follow conventions."
- name: Summary
if: always() && steps.changed-files.outputs.any_changed == 'true'
run: |
echo "## Markdown Validation Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Checked files from PR:" >> $GITHUB_STEP_SUMMARY
while IFS= read -r file; do
[ -z "$file" ] && continue
echo "- $file" >> $GITHUB_STEP_SUMMARY
done <<< "${{ steps.changed-files.outputs.all_changed_files }}"
- name: No validation files in PR
if: steps.changed-files.outputs.any_changed != 'true'
run: echo "No markdown, index.html, or manifest.json files in this PR."