Skip to content

Commit 98a26d3

Browse files
committed
ci: check publishing dates
1 parent 4989ef6 commit 98a26d3

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Check publishing dates
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'content/blog/**'
7+
8+
env:
9+
TARGET_REPO_URL: "https://github.com/espressif/developer-portal.git"
10+
TARGET_BRANCH: "main"
11+
12+
jobs:
13+
check-publishing-dates:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout PR contents
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Get added folders and files
22+
id: added-files
23+
run: |
24+
# Add target remote and fetch its branches
25+
git remote add target "$TARGET_REPO_URL"
26+
git fetch target "$TARGET_BRANCH"
27+
28+
mkdir -p temp
29+
30+
git diff --name-only --diff-filter=A origin/${{ github.base_ref }}...HEAD > temp/added-files.txt
31+
32+
echo "List of added files:"
33+
cat temp/added-files.txt
34+
35+
while IFS= read -r line; do
36+
if [[ "$line" =~ ^content/blog/.*/index.md$ ]]; then
37+
echo "$line" >> temp/index.txt
38+
dirname "$line" >> temp/folders.txt
39+
fi
40+
done < temp/added-files.txt
41+
42+
- name: Validate year and month folder
43+
run: |
44+
CURRENT_YEAR=$(date +%Y)
45+
CURRENT_MONTH=$(date +%m)
46+
47+
while IFS= read -r folder; do
48+
if [[ "$folder" =~ ^content/blog/([0-9]{4})/([0-9]{2})/ ]]; then
49+
year="${BASH_REMATCH[1]}"
50+
month="${BASH_REMATCH[2]}"
51+
if [[ "$year" != "$CURRENT_YEAR" || "$month" != "$CURRENT_MONTH" ]]; then
52+
echo "$folder" >> temp/incorrect-yyyy-mm.txt
53+
fi
54+
else
55+
echo "$folder" >> temp/no-yyyy-mm.txt
56+
fi
57+
done < temp/folders.txt
58+
59+
- name: Make sure folders are under current YYYY/MM
60+
run: |
61+
error_found=0
62+
63+
CURRENT_YEAR=$(date +%Y)
64+
CURRENT_MONTH=$(date +%m)
65+
66+
if [[ -s temp/no-yyyy-mm.txt ]]; then
67+
echo "::error ::Move your article folder(s) to the 'content/blog/${CURRENT_YEAR}/${CURRENT_MONTH}/' folder:"
68+
cat temp/no-yyyy-mm.txt
69+
cat temp/incorrect-yyyy-mm.txt
70+
error_found=1
71+
fi
72+
73+
if [[ -s temp/incorrect-yyyy-mm.txt ]]; then
74+
echo "::error ::Move your article folder(s) to the current 'content/blog/${CURRENT_YEAR}/${CURRENT_MONTH}' folder:"
75+
cat temp/incorrect-yyyy-mm.txt
76+
error_found=1
77+
fi
78+
79+
exit $error_found
80+
81+
- name: Check index.md dates
82+
run: |
83+
error_found=0 # Initialize the error_found variable
84+
85+
today=$(date +%Y-%m-%d)
86+
87+
while IFS= read -r mdfile; do
88+
if [[ -f "$mdfile" ]]; then
89+
post_date=$(awk '/^date:/ {print $2}' "$mdfile")
90+
91+
if [[ ! "$post_date" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
92+
echo "::error ::Date in '$mdfile' is not in YYYY-MM-DD format."
93+
error_found=1
94+
elif [[ "$post_date" != "$today" ]]; then
95+
echo "::error ::Date in '$mdfile' must be today ($today)."
96+
error_found=1
97+
fi
98+
fi
99+
done < temp/index.txt
100+
101+
exit $error_found

0 commit comments

Comments
 (0)