Skip to content

Commit e8bffba

Browse files
authored
Add GHA workflows (#1)
* Add GHA workflows Signed-off-by: NilashishC <nchakrab@redhat.com> --------- Signed-off-by: NilashishC <nchakrab@redhat.com>
1 parent f114aa8 commit e8bffba

File tree

11 files changed

+502
-0
lines changed

11 files changed

+502
-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/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+
...

.gitignore

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# A collection directory, resulting from the use of the pytest-ansible-units plugin
2+
collections/
3+
4+
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.coverage
46+
.coverage.*
47+
.cache
48+
nosetests.xml
49+
coverage.xml
50+
*.cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
63+
# Flask stuff:
64+
instance/
65+
.webassets-cache
66+
67+
# Scrapy stuff:
68+
.scrapy
69+
70+
# Sphinx documentation
71+
docs/_build/
72+
73+
# PyBuilder
74+
target/
75+
76+
# Jupyter Notebook
77+
.ipynb_checkpoints
78+
79+
# pyenv
80+
.python-version
81+
82+
# celery beat schedule file
83+
celerybeat-schedule
84+
85+
# SageMath parsed files
86+
*.sage.py
87+
88+
# Environments
89+
.env
90+
.venv
91+
env/
92+
venv/
93+
ENV/
94+
env.bak/
95+
venv.bak/
96+
97+
# Spyder project settings
98+
.spyderproject
99+
.spyproject
100+
101+
# Rope project settings
102+
.ropeproject
103+
104+
# mkdocs documentation
105+
/site
106+
107+
# mypy
108+
.mypy_cache/
109+
110+
# ide
111+
*.code-workspace
112+
*.vscode/
113+
.DS_Store
114+
115+
changelogs/.plugin-cache.yaml

0 commit comments

Comments
 (0)