File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : " Check Front Matter Date"
2+
3+ on :
4+ push :
5+ paths :
6+ - " draft-*.md"
7+ pull_request :
8+ paths :
9+ - " draft-*.md"
10+
11+ jobs :
12+ check-date :
13+ name : " Validate Document Date"
14+ runs-on : ubuntu-latest
15+ steps :
16+ - uses : actions/checkout@v4
17+
18+ - name : Check date is recent
19+ run : |
20+ for f in draft-*.md; do
21+ [ -f "$f" ] || continue
22+ doc_date=$(grep -m1 '^date:' "$f" | sed 's/date:[[:space:]]*//')
23+ if [ -z "$doc_date" ]; then
24+ echo "::error file=$f::No date field found in front matter"
25+ exit 1
26+ fi
27+ doc_ts=$(date -d "$doc_date" +%s 2>/dev/null)
28+ if [ -z "$doc_ts" ]; then
29+ echo "::error file=$f::Cannot parse date: $doc_date"
30+ exit 1
31+ fi
32+ min_ts=$(date -d "7 days ago" +%s)
33+ max_ts=$(date -d "tomorrow" +%s)
34+ if [ "$doc_ts" -lt "$min_ts" ] || [ "$doc_ts" -gt "$max_ts" ]; then
35+ echo "::error file=$f::Document date '$doc_date' is not within the allowed range (last 7 days to tomorrow). Please update the date field."
36+ exit 1
37+ fi
38+ echo "$f: date '$doc_date' OK"
39+ done
You can’t perform that action at this time.
0 commit comments