Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .githooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# .githooks

This folder contains executable files that will be invoked by git at certain git operations.

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.

## Configuration

Normal development flows (see file [../README.md](../README.md) ) will call git to change the location of git hooks.

To make this change manually you can invoke following command from the root of the repository:

```sh
make git_hooks_config
```

## Git hooks implementation

Git hooks are simply executable files that follow the rules below:

* have executable permissions
* file name must correspond to git hook name with no extension(no `.sh` or `.py`) (see documentation section below)

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.

## Documentation

Git hooks documentation: <https://git-scm.com/docs/githooks>

50 changes: 50 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

if [ -z $GW_IGNORE_SYNTAX ] ; then
python_files_changed=$(git diff --cached --name-only --diff-filter=AM | grep -E '\.py$' | xargs)
echo $python_files_changed
if [ "x$python_files_changed" != "x" ] ; then
FAILED=0
for target in check_black check_flake8 ; do
CHECK_SYNTAX_FILES="${python_files_changed}" make ${target}
if [ $? != 0 ] ; then
FAILED=1
fi
echo ""
done
# We can't run isort on just a file name because it works differently
make check_isort
if [ $? != 0 ] ; then
FAILED=1
fi
if [ $FAILED == 1 ] ; then
exit 1
fi
fi
fi

if [ -z $GW_IGNORE_USER ] ; then
FAILED=0
export CHANGED_FILES=$(git diff --cached --name-only --diff-filter=AM)
echo "Running user pre commit for ${CHANGED_FILES}"
if [ -d ./pre-commit-user ] ; then
for SCRIPT in `find ./pre-commit-user -type f` ; do
if [ -x $SCRIPT ] ; then
echo "Running user pre-commit hook $SCRIPT"
$SCRIPT
if [ $? != 0 ] ; then
echo "User test $SCRIPT failed"
FAILED=1
fi
else
echo "FIle ${SCRIPT} is not executable"
fi
done
fi
if [ $FAILED == 1 ] ; then
echo "One or more user tests failed, see messages above"
exit 1
fi
else
echo "Ignoring user commit scripts due to GW_IGNORE_ERROR"
fi
46 changes: 46 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# Name of default branch from which feature branches are created and to which PRs will be merged back to
DEFAULT_BRANCH="devel"
# Regexp to match jira number AAP-NNNNN or magic string "NO_JIRA"
NO_JIRA_MARKER="NO_JIRA"
JIRA_REGEXP="(aap-[0-9]+|${NO_JIRA_MARKER})"

# Fetch current branch name and list of commits since diverging from default branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
CURRENT_COMMITS=$(git --no-pager log --format=%s --reverse ${DEFAULT_BRANCH}..)

# Extract Jira number or magic marker from branch and commit messages(filtered for unique values)
BRANCH_JIRA=$(grep -i -o -E "${JIRA_REGEXP}" <<< ${CURRENT_BRANCH})
COMMIT_JIRAS=$(grep -i -o -E "${JIRA_REGEXP}" <<< ${CURRENT_COMMITS} | uniq )
# Count all Jira numbers and those matching Jira from branch name
COMMIT_JIRA_COUNT=$(grep -c . <<< ${COMMIT_JIRAS})
MATCHING_JIRAS_COUNT=$(grep -ic -E "${BRANCH_JIRA}" <<< ${COMMIT_JIRAS})

echo "JIRA number from branch name: ${BRANCH_JIRA}"
echo "JIRA numbers from commits:"
echo "${COMMIT_JIRAS}"
echo "Number of JIRA numbers from commits matching JIRA number from branch name: ${MATCHING_JIRAS_COUNT}"

# if no Jira or no magic marker found in branch name, fail
echo "Checking branch name..."
if [ "${BRANCH_JIRA}" = "" ]; then
echo "Fail: Branch name does not contain a JIRA number or a ${NO_JIRA_MARKER} marker."
exit 1
# if branch does not have the magic marker, check the commits as well
elif [ "${BRANCH_JIRA}" != "${NO_JIRA_MARKER}" ]; then
echo "Checking commit messages..."
# if there is no Jira number or magic marker, fail
if [ ${COMMIT_JIRA_COUNT} -eq 0 ]; then
echo "Fail: No commit message contains a JIRA number or a ${NO_JIRA_MARKER} marker."
exit 1
# if no Jira numbers or magic marker match the Jira number from branch name, inform the user
# this case might be happening when code is being back-ported under different Jira number in branch name
elif [ ${MATCHING_JIRAS_COUNT} -eq 0 ]; then
echo "Warning: No Jira numbers or ${NO_JIRA_MARKER} marker in commit messages match Jira number from branch name."
else
echo "OK. Found Jira numbers(or ${NO_JIRA_MARKER} marker) in commit messages that match Jira number in branch name."
fi
else
echo "OK. Skipping checks of commit messages, branch name includes ${NO_JIRA_MARKER}."
fi
3 changes: 3 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Community Code of Conduct

Please see the official [Ansible Community Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html).
99 changes: 99 additions & 0 deletions .github/workflows/collection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
name: platform collection tests
on:
push:
pull_request:

jobs:
sanity:
name: platform collection sanity
runs-on: ubuntu-latest
env:
HEADLESS: "yes"
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
ansible:
- stable-2.16
- stable-2.17
- stable-2.18
- stable-2.19
steps:
- uses: actions/checkout@v3

- name: Perform sanity testing
uses: ansible-community/ansible-test-gh-action@release/v1
with:
ansible-core-version: ${{ matrix.ansible }}
collection-root: .
testing-type: sanity
target-python-version: 3.11

# TO-DO
# - name: Upload gateway jUnit test reports to the unified dashboard
# if: >-
# !cancelled()
# && steps.make-run.outputs.test-result-files != ''
# && github.event_name == 'push'
# && env.UPSTREAM_REPOSITORY_ID == github.repository_id
# && github.ref_name == github.event.repository.default_branch
# run: |
# for junit_file in $(echo '${{ steps.make-run.outputs.test-result-files }}' | sed 's/,/ /')
# do
# curl \
# -v \
# --user "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}" \
# --form "xunit_xml=@${junit_file}" \
# --form "component_name=gateway" \
# --form "git_commit_sha=${{ github.sha }}" \
# --form "git_repository_url=https://github.com/${{ github.repository }}" \
# "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}/api/results/upload/"
# done

docs:
name: Check module doc strings
runs-on: ubuntu-latest
env:
HEADLESS: "yes"
steps:
- name: Install python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install requirements
run: pip3.11 install --upgrade ansible

- uses: actions/checkout@v3

- name: Run ansible-doc
run: make collection-docs

- name: Get ansible-doc version
run: ansible-doc --version
if: failure()

lint:
name: Lint module
runs-on: ubuntu-latest
env:
HEADLESS: "yes"
steps:
- name: Install python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install requirements
run: pip3.11 install --upgrade ansible-lint

- uses: actions/checkout@v3

- name: Run ansible-lint
run: make collection-lint

- name: Get ansible-lint version
run: ansible-lint --version
if: failure()
...
41 changes: 41 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: Linting
env:
LC_ALL: "C.UTF-8" # prevent ERROR: Ansible could not initialize the preferred locale: unsupported locale setting
on:
pull_request:
push:
jobs:
common-tests:
name: ${{ matrix.tests.name }}
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
strategy:
fail-fast: false
matrix:
tests:
- name: api-flake8
command: check_flake8
- name: api-black
command: check_black
- name: api-isort
command: check_isort
steps:
- name: Install make
run: sudo apt install make

- uses: actions/checkout@v2

- name: Install python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install requirements
run: pip3.11 install -r requirements/requirements_dev.txt

- name: Run check ${{ matrix.tests.name }}
run: make ${{ matrix.tests.command }}
...
115 changes: 115 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# A collection directory, resulting from the use of the pytest-ansible-units plugin
collections/


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# ide
*.code-workspace
*.vscode/
.DS_Store

changelogs/.plugin-cache.yaml
Loading