SWDEV-123456 - add PR validation (#202)
[ROCm/hip-tests commit: 0653734882]
This commit is contained in:
committed by
GitHub
orang tua
104cc15010
melakukan
ea29de484f
@@ -0,0 +1,73 @@
|
||||
name: Keywords checker
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, edited]
|
||||
branches:
|
||||
- amd-staging
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
check-keywords:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
KEYWORDS: ${{ vars.KEYWORDS }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check keywords
|
||||
run: |
|
||||
set -e
|
||||
|
||||
if [ -z "$KEYWORDS" ]; then
|
||||
echo "No keywords set. Skipping check"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
IFS=',' read -ra KEYWORDS_ARRAY <<< "$KEYWORDS"
|
||||
echo "Checking against list of keywords: ${KEYWORDS_ARRAY[*]}"
|
||||
|
||||
MATCHED=0
|
||||
BASE_BRANCH=${{github.event.pull_request.base.ref}}
|
||||
HEAD_BRANCH=${{github.event.pull_request.head.ref}}
|
||||
PR_TITLE="${{ github.event.pull_request.title }}"
|
||||
|
||||
for file in $(git diff --name-only origin/$BASE_BRANCH..origin/$HEAD_BRANCH); do
|
||||
if [ -f "$file" ]; then
|
||||
for keyword in "${KEYWORDS_ARRAY[*]}"; do
|
||||
grep -in -E "${keyword}" "$file" | while IFS= read -r line; do
|
||||
echo "Matched in '$file': $line"
|
||||
MATCHED=1
|
||||
done
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
for commit in $(git log --format=%H origin/$BASE_BRANCH..origin/$HEAD_BRANCH); do
|
||||
msg=$(git log -1 --format=%B "$commit")
|
||||
for keyword in "${KEYWORDS_ARRAY[*]}"; do
|
||||
if echo "$msg" | grep -i -q "$keyword"; then
|
||||
echo "Match in commit $commit: $msg"
|
||||
MATCHED=1
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
for keyword in "${KEYWORDS_ARRAY[*]}"; do
|
||||
if echo "$PR_TITLE" | grep -i -q "$keyword"; then
|
||||
echo "Match in PR title"
|
||||
MATCHED=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$MATCHED" -eq 1 ]; then
|
||||
echo "Keywords found, please see diagnostics higher"
|
||||
exit 1
|
||||
else
|
||||
echo "No keywords found"
|
||||
exit 0
|
||||
fi
|
||||
@@ -0,0 +1,42 @@
|
||||
name: Validate PR Title
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, edited, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
validate-pr-title:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check PR Title
|
||||
id: check-pr-title
|
||||
run: |
|
||||
PR_TITLE="${{ github.event.pull_request.title }}"
|
||||
|
||||
if [[ ! "$PR_TITLE" =~ ^SWDEV-[0-9]+ ]]; then
|
||||
echo "::error::PR title must start with a Jira ticket ID, SWDEV-<num>"
|
||||
exit 1
|
||||
else
|
||||
echo "PR title is valid"
|
||||
fi
|
||||
|
||||
validate-commit-messages:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check all commit messages
|
||||
id: validate-commit-messags
|
||||
run: |
|
||||
COMMITS=$(git log --format="%H %s" origin/${{ github.event.pull_request.base.ref }}..origin/${{ github.event.pull_request.head.ref }})
|
||||
echo "$COMMITS"
|
||||
echo "$COMMITS" | while read -r hash message; do
|
||||
echo -e "$hash $message\n "
|
||||
if [[ ! "$message" =~ ^SWDEV-[0-9]+ ]]; then
|
||||
echo "::error:: $hash commit should start with Jira ticket ID, SWDEV-<num>"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
@@ -0,0 +1,22 @@
|
||||
name: Validate PR desription
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, edited, synchronize]
|
||||
|
||||
jobs:
|
||||
validate-pr-description:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.13"
|
||||
|
||||
- name: Validate PR description
|
||||
env:
|
||||
PR_DESCRIPTION: ${{ github.event.pull_request.body }}
|
||||
run: python .github/scripts/validate_pr_description.py
|
||||
Reference in New Issue
Block a user