Skip to content

Commit e2a1db6

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

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
cat temp/added-files.txt
33+
34+
while IFS= read -r line; do
35+
if [[ "$line" =~ ^content/blog/.*/index.md$ ]]; then
36+
echo "$line" >> temp/index.txt
37+
dirname "$line" >> temp/folders.txt
38+
fi
39+
done < temp/added-files.txt
40+
41+
- name: Validate year and month folder
42+
run: |
43+
CURRENT_YEAR=$(date +%Y)
44+
CURRENT_MONTH=$(date +%m)
45+
46+
while IFS= read -r folder; do
47+
if [[ "$folder" =~ ^content/blog/([0-9]{4})/([0-9]{2})/ ]]; then
48+
year="${BASH_REMATCH[1]}"
49+
month="${BASH_REMATCH[2]}"
50+
if [[ "$year" != "$CURRENT_YEAR" || "$month" != "$CURRENT_MONTH" ]]; then
51+
echo "$folder" >> temp/incorrect-yyyy-mm.txt
52+
fi
53+
else
54+
echo "$folder" >> temp/no-yyyy-mm.txt
55+
fi
56+
done < temp/folders.txt
57+
58+
cat temp/no-yyyy-mm.txt
59+
cat temp/incorrect-yyyy-mm.txt
60+
61+
- name: Make sure folders are under current YYYY/MM
62+
run: |
63+
error_found=0
64+
65+
CURRENT_YEAR=$(date +%Y)
66+
CURRENT_MONTH=$(date +%m)
67+
68+
if [[ -s temp/no-yyyy-mm.txt ]]; then
69+
echo "::error ::Move your article folder(s) to the current 'content/blog/${CURRENT_YEAR}/${CURRENT_MONTH}/' folder:"
70+
cat temp/no-yyyy-mm.txt
71+
cat temp/incorrect-yyyy-mm.txt
72+
error_found=1
73+
fi
74+
75+
exit $error_found
76+
77+
- name: Check index.md dates
78+
run: |
79+
error_found=0 # Initialize the error_found variable
80+
81+
today=$(date +%Y-%m-%d)
82+
83+
while IFS= read -r mdfile; do
84+
if [[ -f "$mdfile" ]]; then
85+
post_date=$(awk '/^date:/ {print $2}' "$mdfile")
86+
87+
if [[ ! "$post_date" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
88+
echo "::error ::Date in '$mdfile' is not in YYYY-MM-DD format."
89+
error_found=1
90+
elif [[ "$post_date" != "$today" ]]; then
91+
echo "::error ::Date in '$mdfile' must be today ($today)."
92+
error_found=1
93+
fi
94+
fi
95+
done < temp/index.txt
96+
97+
exit $error_found

0 commit comments

Comments
 (0)