-
Notifications
You must be signed in to change notification settings - Fork 1.1k
156 lines (133 loc) · 4.97 KB
/
validate-tutorials.yml
File metadata and controls
156 lines (133 loc) · 4.97 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Validate Tutorials
on:
push:
branches: [master]
paths:
- '**101/**'
- '**201/**'
- 'cka/**'
- 'intermediate/**'
- 'scripts/validate-tutorials.sh'
- '.github/workflows/validate-tutorials.yml'
pull_request:
branches: [master]
paths:
- '**101/**'
- '**201/**'
- 'cka/**'
- 'intermediate/**'
- 'scripts/validate-tutorials.sh'
- '.github/workflows/validate-tutorials.yml'
workflow_dispatch:
inputs:
directory:
description: 'Specific tutorial directory to validate (leave empty for all)'
required: false
default: ''
jobs:
# ---------------------------------------------------------------------------
# Job 1: Validate tutorial structure and YAML syntax
# ---------------------------------------------------------------------------
validate-structure:
name: Validate Tutorial Structure
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install yamllint
run: pip install yamllint
- name: Make validator executable
run: chmod +x scripts/validate-tutorials.sh
- name: Run tutorial validator (all tutorials)
if: ${{ github.event.inputs.directory == '' || github.event.inputs.directory == null }}
run: ./scripts/validate-tutorials.sh
- name: Run tutorial validator (specific directory)
if: ${{ github.event.inputs.directory != '' && github.event.inputs.directory != null }}
run: ./scripts/validate-tutorials.sh "${{ github.event.inputs.directory }}"
# ---------------------------------------------------------------------------
# Job 2: Lint Markdown files
# ---------------------------------------------------------------------------
lint-markdown:
name: Lint Markdown
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install markdownlint-cli
run: npm install -g markdownlint-cli
- name: Lint all Markdown files in tutorial directories
run: |
# Find all markdown files in tutorial directories
find . -maxdepth 3 -type f -name '*.md' \
\( -path './*101/*' -o -path './*201/*' \
-o -path './cka/*' -o -path './intermediate/*' \
-o -name 'README.md' -o -name 'CONTRIBUTING.md' \) \
! -path './_site/*' \
! -path './.git/*' \
| sort > /tmp/md_files.txt
echo "Files to lint:"
cat /tmp/md_files.txt
# Run markdownlint; allow warnings but fail on errors
markdownlint \
--config .markdownlint.yaml \
--ignore _site \
--ignore node_modules \
$(cat /tmp/md_files.txt) || true
# ---------------------------------------------------------------------------
# Job 3: Validate YAML manifests in changed tutorial directories
# ---------------------------------------------------------------------------
validate-yaml:
name: Validate YAML Manifests
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install yamllint
run: pip install yamllint
- name: Validate all YAML files in tutorial directories
run: |
find . -maxdepth 3 -type f \( -name '*.yaml' -o -name '*.yml' \) \
! -path './_site/*' \
! -path './.git/*' \
! -path './.github/workflows/*' \
| sort | while read -r f; do
echo "Checking: $f"
yamllint -d relaxed "$f" && echo " ✔ OK" || echo " ✗ FAILED: $f"
done
# ---------------------------------------------------------------------------
# Job 4: Check for new tutorials and summarise changes
# ---------------------------------------------------------------------------
summarise-changes:
name: Summarise Tutorial Changes
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: List changed tutorial directories
run: |
echo "### Changed Tutorial Directories" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
git diff --name-only origin/${{ github.base_ref }}...HEAD \
| grep -E '^[^/]+101/|^[^/]+201/|^cka/|^intermediate/' \
| cut -d'/' -f1 \
| sort -u \
| while read -r dir; do
echo "- \`$dir\`" >> $GITHUB_STEP_SUMMARY
done
echo "" >> $GITHUB_STEP_SUMMARY
echo "Validation complete. See job results above for details." >> $GITHUB_STEP_SUMMARY