update: added a step on the github actions to check for multiple open prs #493
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Content Compliance Check | |
on: [pull_request] | |
permissions: | |
pull-requests: write | |
contents: read | |
issues: write | |
jobs: | |
content-compliance: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- 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") | |
echo "Contributor login: $contributor_login" | |
echo "PR Branch: $pr_branch" | |
# Fetch open PRs from the repository | |
open_prs=$(gh pr list --state open --json number,title,author,headRefName --jq '.[] | select(.author.login=="'"$contributor_login"'")') | |
echo "Open PRs by contributor: $open_prs" | |
pr_count=$(echo "$open_prs" | jq 'length') | |
if [ "$pr_count" -gt 1 ]; then | |
echo "has_open_prs=true" >> "$GITHUB_OUTPUT" | |
elif [ "$pr_count" -eq 1 ]; then | |
existing_branch=$(echo "$open_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: Comment and Fail If Contributor Has Any Open PRs | |
if: steps.check-prs.outputs.has_open_prs == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh pr comment ${{ github.event.pull_request.number }} \ | |
--body "Hi @${{ github.event.pull_request.user.login }}, our policy allows contributors to work on one issue at a time. Please complete or close your existing pull requests before creating a new one." | |
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: Run Markdown Lint | |
run: npx markdownlint '**/*.md --ignore "node_modules"' |