Skip to content

Commit d054849

Browse files
feat: Added workflows to integrate github actions for PR validations (#420)
Added workflows to integrate github actions for PR validations This change will enable 3 jobs : 1. Validate PR title 2. Check for the description 3. Ansible lint check for the files changed as part of the PR raised. As a first step, adding these checks. we can make 1 & 2 as mandatory checks and 3 as an optional check. --------- Signed-off-by: DAMISETTI-VEERABHADRARAO <[email protected]>
1 parent a805101 commit d054849

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Ansible_Syntax_Checks
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
ansible-lint:
9+
name: Ansible_Lint
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout PR code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Install Ansible and ansible-lint
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install ansible ansible-lint
27+
28+
- name: Fetch base branch from upstream (handles forks)
29+
run: |
30+
git remote add upstream https://github.com/${{ github.repository }}.git
31+
git fetch upstream ${{ github.base_ref }}
32+
33+
- name: Run ansible-lint on changed Ansible files
34+
run: |
35+
files=$(git diff --name-only --diff-filter=ACMRT upstream/${{ github.base_ref }} -- '*.yml' '*.yaml')
36+
if [[ -z "$files" ]]; then
37+
echo "No yaml files changed"
38+
exit 0
39+
fi
40+
echo "Linting changed Ansible files:"
41+
echo "$files"
42+
echo "$files" | xargs ansible-lint
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Metadata_Validator
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
7+
jobs:
8+
check-pr-title:
9+
name: PR_Title_Linter
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Validate PR title syntax
13+
uses: actions/github-script@v7
14+
with:
15+
script: |
16+
const validKeywords = ['fix', 'feat', 'chore', 'docs', 'perf', 'test'];
17+
const title = context.payload.pull_request?.title || '';
18+
19+
const match = title.match(/^(\w+):\s.+/);
20+
if (!match) {
21+
core.setFailed(
22+
`Invalid PR title format: "${title}"\n\n` +
23+
`PR title must follow this format -> prefix: descriptive message\n\n` +
24+
`Example -> feat: Add optional setup_file_server.yaml playbook\n\n` +
25+
`Allowed keywords:\n` +
26+
` - {"type": "feat", "section": "Features"}\n` +
27+
` - {"type": "fix", "section": "Bug Fixes"}\n` +
28+
` - {"type": "chore", "section": "Miscellaneous"}\n` +
29+
` - {"type": "docs", "section": "Documentation"}\n` +
30+
` - {"type": "perf", "section": "Performance"}\n` +
31+
` - {"type": "test", "section": "Tests"}\n\n` +
32+
`This format helps organize changelogs and enforces clarity.`
33+
);
34+
return;
35+
}
36+
37+
const keyword = match[1];
38+
if (!validKeywords.includes(keyword)) {
39+
core.setFailed(`Invalid Prefix "${keyword}"\n` +
40+
`Allowed keywords:\n` +
41+
` - {"type": "feat", "section": "Features"}\n` +
42+
` - {"type": "fix", "section": "Bug Fixes"}\n` +
43+
` - {"type": "chore", "section": "Miscellaneous"}\n` +
44+
` - {"type": "docs", "section": "Documentation"}\n` +
45+
` - {"type": "perf", "section": "Performance"}\n` +
46+
` - {"type": "test", "section": "Tests"}\n\n`
47+
);
48+
}
49+
50+
check-pr-description:
51+
name: PR_Description_Validator
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: Validate PR description presence
55+
uses: actions/github-script@v7
56+
with:
57+
script: |
58+
const body = context.payload.pull_request?.body || '';
59+
60+
if (!body.trim()) {
61+
core.setFailed('PR description (body) must not be empty.');
62+
}

0 commit comments

Comments
 (0)