-
-
Notifications
You must be signed in to change notification settings - Fork 117
73 lines (64 loc) · 2.49 KB
/
blog-validator.yml
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
name: Blog Validator
on:
pull_request:
paths: [ content/blog/** ]
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
check_date_and_tags:
if: github.repository_owner == 'adoptium'
name: Check Date and Tags
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
with:
persist-credentials: false
- id: files
uses: jitterbit/get-changed-files@b17fbb00bdc0c0f63fcf166580804b4d2cdc2a42 # v1
- run: |
# shellcheck disable=2043
for added_file in ${{ steps.files.outputs.added }}; do
if [[ ${added_file} =~ ^content/blog.*.md ]]; then
blog_date=$(grep 'date:' "${added_file}" | sed -n -e 's/^.*date: //p' | tr -d '"')
# Return difference in days between today and blog date
diff=$(( ($(date +%s) - $(date --date "${blog_date}" +%s)) / (60*60*24) ))
if [[ ${diff} -gt 0 ]]; then
line_number=$(grep -n 'date:' "${added_file}" | cut -d : -f 1)
echo "Blog date is in the past, please update the date to today's date"
echo "::error file=${added_file},line=${line_number}::Blog date is in the past, please update the date to today's date"
exit 1
fi
# Validate tags
tags=$(grep 'tags:' "${added_file}" | sed -n -e 's/^.*tags: //p' | tr -d '[]"')
valid_tags=(
"temurin"
"aqavit"
"emt4j"
"adoptium"
"java"
"openjdk"
"infrastructure"
"security"
"announcement"
"release-notes"
)
invalid_tags=()
IFS=", " read -r -a tag_array <<< "$tags"
for tag in "${tag_array[@]}"; do
lowercase_tag=$(echo "$tag" | tr '[:upper:]' '[:lower:]')
if ! [[ $lowercase_tag =~ ^[a-z0-9-]+$ ]] || ! [[ ${valid_tags[*]} =~ $lowercase_tag ]]; then
invalid_tags+=("$tag")
fi
done
if [ ${#invalid_tags[@]} -gt 0 ]; then
line_number=$(grep -n 'tags:' "${added_file}" | cut -d : -f 1)
echo "Invalid tags found: ${invalid_tags[*]}"
echo "::error file=${added_file},line=${line_number}::Invalid tags found: ${invalid_tags[*]}"
exit 1
fi
fi
done