Skip to content

Commit 3144baa

Browse files
committed
Add GHA workflows
Signed-off-by: NilashishC <nchakrab@redhat.com>
1 parent f114aa8 commit 3144baa

File tree

12 files changed

+559
-0
lines changed

12 files changed

+559
-0
lines changed

.githooks/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# .githooks
2+
3+
This folder contains executable files that will be invoked by git at certain git operations.
4+
5+
By default git hooks are located i `.git/hooks` folder at the root of the repository. Since the default folder is hidden by most IDEs, this repository reconfigures git's hook location in order to make the hooks visible and easier to maintain.
6+
7+
## Configuration
8+
9+
Normal development flows (see file [../README.md](../README.md) ) will call git to change the location of git hooks.
10+
11+
To make this change manually you can invoke following command from the root of the repository:
12+
13+
```sh
14+
make git_hooks_config
15+
```
16+
17+
## Git hooks implementation
18+
19+
Git hooks are simply executable files that follow the rules below:
20+
21+
* have executable permissions
22+
* file name must correspond to git hook name with no extension(no `.sh` or `.py`) (see documentation section below)
23+
24+
Return code other than zero(0) will cause the git operation that triggerred the hook to fail, while zero(0) return code indicates success and git opertaion will succeed.
25+
26+
## Documentation
27+
28+
Git hooks documentation: <https://git-scm.com/docs/githooks>
29+

.githooks/pre-commit

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -z $GW_IGNORE_SYNTAX ] ; then
4+
python_files_changed=$(git diff --cached --name-only --diff-filter=AM | grep -E '\.py$' | xargs)
5+
echo $python_files_changed
6+
if [ "x$python_files_changed" != "x" ] ; then
7+
FAILED=0
8+
for target in check_black check_flake8 ; do
9+
CHECK_SYNTAX_FILES="${python_files_changed}" make ${target}
10+
if [ $? != 0 ] ; then
11+
FAILED=1
12+
fi
13+
echo ""
14+
done
15+
# We can't run isort on just a file name because it works differently
16+
make check_isort
17+
if [ $? != 0 ] ; then
18+
FAILED=1
19+
fi
20+
if [ $FAILED == 1 ] ; then
21+
exit 1
22+
fi
23+
fi
24+
fi
25+
26+
if [ -z $GW_IGNORE_USER ] ; then
27+
FAILED=0
28+
export CHANGED_FILES=$(git diff --cached --name-only --diff-filter=AM)
29+
echo "Running user pre commit for ${CHANGED_FILES}"
30+
if [ -d ./pre-commit-user ] ; then
31+
for SCRIPT in `find ./pre-commit-user -type f` ; do
32+
if [ -x $SCRIPT ] ; then
33+
echo "Running user pre-commit hook $SCRIPT"
34+
$SCRIPT
35+
if [ $? != 0 ] ; then
36+
echo "User test $SCRIPT failed"
37+
FAILED=1
38+
fi
39+
else
40+
echo "FIle ${SCRIPT} is not executable"
41+
fi
42+
done
43+
fi
44+
if [ $FAILED == 1 ] ; then
45+
echo "One or more user tests failed, see messages above"
46+
exit 1
47+
fi
48+
else
49+
echo "Ignoring user commit scripts due to GW_IGNORE_ERROR"
50+
fi

.githooks/pre-push

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
# Name of default branch from which feature branches are created and to which PRs will be merged back to
4+
DEFAULT_BRANCH="devel"
5+
# Regexp to match jira number AAP-NNNNN or magic string "NO_JIRA"
6+
NO_JIRA_MARKER="NO_JIRA"
7+
JIRA_REGEXP="(aap-[0-9]+|${NO_JIRA_MARKER})"
8+
9+
# Fetch current branch name and list of commits since diverging from default branch
10+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
11+
CURRENT_COMMITS=$(git --no-pager log --format=%s --reverse ${DEFAULT_BRANCH}..)
12+
13+
# Extract Jira number or magic marker from branch and commit messages(filtered for unique values)
14+
BRANCH_JIRA=$(grep -i -o -E "${JIRA_REGEXP}" <<< ${CURRENT_BRANCH})
15+
COMMIT_JIRAS=$(grep -i -o -E "${JIRA_REGEXP}" <<< ${CURRENT_COMMITS} | uniq )
16+
# Count all Jira numbers and those matching Jira from branch name
17+
COMMIT_JIRA_COUNT=$(grep -c . <<< ${COMMIT_JIRAS})
18+
MATCHING_JIRAS_COUNT=$(grep -ic -E "${BRANCH_JIRA}" <<< ${COMMIT_JIRAS})
19+
20+
echo "JIRA number from branch name: ${BRANCH_JIRA}"
21+
echo "JIRA numbers from commits:"
22+
echo "${COMMIT_JIRAS}"
23+
echo "Number of JIRA numbers from commits matching JIRA number from branch name: ${MATCHING_JIRAS_COUNT}"
24+
25+
# if no Jira or no magic marker found in branch name, fail
26+
echo "Checking branch name..."
27+
if [ "${BRANCH_JIRA}" = "" ]; then
28+
echo "Fail: Branch name does not contain a JIRA number or a ${NO_JIRA_MARKER} marker."
29+
exit 1
30+
# if branch does not have the magic marker, check the commits as well
31+
elif [ "${BRANCH_JIRA}" != "${NO_JIRA_MARKER}" ]; then
32+
echo "Checking commit messages..."
33+
# if there is no Jira number or magic marker, fail
34+
if [ ${COMMIT_JIRA_COUNT} -eq 0 ]; then
35+
echo "Fail: No commit message contains a JIRA number or a ${NO_JIRA_MARKER} marker."
36+
exit 1
37+
# if no Jira numbers or magic marker match the Jira number from branch name, inform the user
38+
# this case might be happening when code is being back-ported under different Jira number in branch name
39+
elif [ ${MATCHING_JIRAS_COUNT} -eq 0 ]; then
40+
echo "Warning: No Jira numbers or ${NO_JIRA_MARKER} marker in commit messages match Jira number from branch name."
41+
else
42+
echo "OK. Found Jira numbers(or ${NO_JIRA_MARKER} marker) in commit messages that match Jira number in branch name."
43+
fi
44+
else
45+
echo "OK. Skipping checks of commit messages, branch name includes ${NO_JIRA_MARKER}."
46+
fi

.github/CODE_OF_CONDUCT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Community Code of Conduct
2+
3+
Please see the official [Ansible Community Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html).

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## Description
2+
<!-- Mandatory: Provide a clear, concise description of the changes and their purpose -->
3+
- What is being changed?
4+
- Why is this change needed?
5+
- How does this change address the issue?
6+
7+
## Type of Change
8+
<!-- Mandatory: Check one or more boxes that apply -->
9+
- [ ] Bug fix (non-breaking change which fixes an issue)
10+
- [ ] New feature (non-breaking change which adds functionality)
11+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
12+
- [ ] Documentation update
13+
- [ ] Test update
14+
- [ ] Refactoring (no functional changes)
15+
- [ ] Development environment change
16+
- [ ] Configuration change
17+
18+
## Self-Review Checklist
19+
<!-- These items help ensure quality - they complement our automated CI checks -->
20+
- [ ] I have performed a self-review of my code
21+
- [ ] I have added relevant comments to complex code sections
22+
- [ ] I have updated documentation where needed
23+
- [ ] I have considered the security impact of these changes
24+
- [ ] I have considered performance implications
25+
- [ ] I have thought about error handling and edge cases
26+
- [ ] I have tested the changes in my local environment
27+
28+
## Testing Instructions
29+
<!-- Optional for test-only changes. Mandatory for all other changes -->
30+
<!-- Must be detailed enough for reviewers to reproduce -->
31+
### Prerequisites
32+
<!-- List any specific setup required -->
33+
34+
### Steps to Test
35+
1.
36+
2.
37+
3.
38+
39+
### Expected Results
40+
<!-- Describe what should happen after following the steps -->
41+
42+
## Additional Context
43+
<!-- Optional but helpful information -->
44+
45+
### Required Actions
46+
<!-- Check if changes require work in other areas -->
47+
<!-- Remove section if no external actions needed -->
48+
- [ ] Requires documentation updates
49+
<!-- API docs, feature docs, deployment guides -->
50+
- [ ] Requires downstream repository changes
51+
<!-- Specify repos: django-ansible-base, eda-server, etc. -->
52+
- [ ] Requires infrastructure/deployment changes
53+
<!-- CI/CD, installer updates, new services -->
54+
- [ ] Requires coordination with other teams
55+
<!-- UI team, platform services, infrastructure -->
56+
- [ ] Blocked by PR/MR: #XXX
57+
<!-- Reference blocking PRs/MRs with brief context -->
58+
59+
### Screenshots/Logs
60+
<!-- Add if relevant to demonstrate the changes -->

.github/workflows/collection.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
name: platform collection tests
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
sanity:
9+
name: platform collection sanity
10+
runs-on: ubuntu-latest
11+
env:
12+
HEADLESS: "yes"
13+
timeout-minutes: 30
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
ansible:
18+
- stable-2.16
19+
- stable-2.17
20+
- stable-2.18
21+
- stable-2.19
22+
steps:
23+
- uses: actions/checkout@v3
24+
25+
- name: Perform sanity testing
26+
uses: ansible-community/ansible-test-gh-action@release/v1
27+
with:
28+
ansible-core-version: ${{ matrix.ansible }}
29+
collection-root: .
30+
testing-type: sanity
31+
target-python-version: 3.11
32+
33+
# TO-DO
34+
# - name: Upload gateway jUnit test reports to the unified dashboard
35+
# if: >-
36+
# !cancelled()
37+
# && steps.make-run.outputs.test-result-files != ''
38+
# && github.event_name == 'push'
39+
# && env.UPSTREAM_REPOSITORY_ID == github.repository_id
40+
# && github.ref_name == github.event.repository.default_branch
41+
# run: |
42+
# for junit_file in $(echo '${{ steps.make-run.outputs.test-result-files }}' | sed 's/,/ /')
43+
# do
44+
# curl \
45+
# -v \
46+
# --user "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}" \
47+
# --form "xunit_xml=@${junit_file}" \
48+
# --form "component_name=gateway" \
49+
# --form "git_commit_sha=${{ github.sha }}" \
50+
# --form "git_repository_url=https://github.com/${{ github.repository }}" \
51+
# "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}/api/results/upload/"
52+
# done
53+
54+
docs:
55+
name: Check module doc strings
56+
runs-on: ubuntu-latest
57+
env:
58+
HEADLESS: "yes"
59+
steps:
60+
- name: Install python 3.11
61+
uses: actions/setup-python@v4
62+
with:
63+
python-version: 3.11
64+
65+
- name: Install requirements
66+
run: pip3.11 install --upgrade ansible
67+
68+
- uses: actions/checkout@v3
69+
70+
- name: Run ansible-doc
71+
run: make collection-docs
72+
73+
- name: Get ansible-doc version
74+
run: ansible-doc --version
75+
if: failure()
76+
77+
lint:
78+
name: Lint module
79+
runs-on: ubuntu-latest
80+
env:
81+
HEADLESS: "yes"
82+
steps:
83+
- name: Install python 3.11
84+
uses: actions/setup-python@v4
85+
with:
86+
python-version: 3.11
87+
88+
- name: Install requirements
89+
run: pip3.11 install --upgrade ansible-lint
90+
91+
- uses: actions/checkout@v3
92+
93+
- name: Run ansible-lint
94+
run: make collection-lint
95+
96+
- name: Get ansible-lint version
97+
run: ansible-lint --version
98+
if: failure()
99+
...

.github/workflows/linting.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: Linting
3+
env:
4+
LC_ALL: "C.UTF-8" # prevent ERROR: Ansible could not initialize the preferred locale: unsupported locale setting
5+
on:
6+
pull_request:
7+
push:
8+
jobs:
9+
common-tests:
10+
name: ${{ matrix.tests.name }}
11+
runs-on: ubuntu-latest
12+
permissions:
13+
packages: write
14+
contents: read
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
tests:
19+
- name: api-flake8
20+
command: check_flake8
21+
- name: api-black
22+
command: check_black
23+
- name: api-isort
24+
command: check_isort
25+
steps:
26+
- name: Install make
27+
run: sudo apt install make
28+
29+
- uses: actions/checkout@v2
30+
31+
- name: Install python 3.11
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: 3.11
35+
36+
- name: Install requirements
37+
run: pip3.11 install -r requirements/requirements_dev.txt
38+
39+
- name: Run check ${{ matrix.tests.name }}
40+
run: make ${{ matrix.tests.command }}
41+
...

0 commit comments

Comments
 (0)