-
Notifications
You must be signed in to change notification settings - Fork 43
99 lines (83 loc) · 3.17 KB
/
content-check.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
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
name: Content Compliance Check
on: [pull_request]
permissions:
pull-requests: write
contents: read
jobs:
content-compliance:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Check for existing open PRs
id: check-prs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
contributor_login=$(jq -r '.pull_request.user.login' "$GITHUB_EVENT_PATH")
pr_branch=$(jq -r '.pull_request.head.ref' "$GITHUB_EVENT_PATH")
# Fetch open PRs from the repository
open_prs=$(gh pr list --repo $GITHUB_REPOSITORY --state open --json author,headRefName)
echo "All open PRs: $open_prs"
# Filter PRs by author and convert to array
contributor_prs=$(echo "$open_prs" | jq --arg login "$contributor_login" '[.[] | select(.author.login == $login)]')
echo "Filtered PRs: $contributor_prs"
pr_count=$(echo "$contributor_prs" | jq 'length')
echo "PR count: $pr_count"
if [ "$pr_count" -gt 1 ]; then
echo "has_open_prs=true" >> "$GITHUB_OUTPUT"
elif [ "$pr_count" -eq 1 ]; then
existing_branch=$(echo "$contributor_prs" | jq -r '.[0].headRefName')
if [ "$existing_branch" != "$pr_branch" ]; then
echo "has_open_prs=true" >> "$GITHUB_OUTPUT"
else
echo "has_open_prs=false" >> "$GITHUB_OUTPUT"
fi
else
echo "has_open_prs=false" >> "$GITHUB_OUTPUT"
fi
- name: Fail if multiple PRs
if: steps.check-prs.outputs.has_open_prs == 'true'
run: |
echo "::error::Our policy allows only one active PR per contributor. Please complete existing work before submitting new changes."
exit 1
- name: File Naming and Folder Structure Compliance
run: |
files_invalid=false
for file in $(git diff --name-only origin/main...HEAD)
do
if [[ $file == articles/* || $file == guides/* ]]
then
if ! [[ $file =~ ^(articles|guides)/[0-9]{8}_[a-z0-9_]+\.md$ ]]
then
echo "Error: File \"$file\" does not follow the naming convention YYYYMMDD_title_of_the_article.md in 'articles' or 'guides' folder" >&2
files_invalid=true
fi
fi
if [[ $file == assets/* ]]
then
if ! [[ $file =~ ^assets/[0-9]{8}_[a-z0-9_]+_img[0-9]+\.png$ ]]
then
echo "Error: File \"$file\" does not follow the naming convention YYYYMMDD_title_of_the_article_imgN.png in 'assets' folder" >&2
files_invalid=true
fi
fi
done
if [ $files_invalid = true ]; then
exit 1
fi
- name: Install markdownlint
run: npm install -g [email protected]
- name: Run Markdown Lint
run: |
markdownlint '**/*.md' \
--config .markdownlint.json \
--ignore node_modules \
--ignore .github