Skip to content

Commit

Permalink
ci: Add Python tests to the CI
Browse files Browse the repository at this point in the history
Signed-off-by: Sergei Petrosian <[email protected]>
  • Loading branch information
spetrosi committed Dec 8, 2023
1 parent c0d7bda commit 60f379b
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 8 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ jobs:
echo "Created $branch branch"
else
echo "Branch $branch already exists"
fi
- name: Checkout the docs branch
fi- name: Checkout the docs branch
uses: actions/checkout@v4
with:
ref: docs
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/changelog_to_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ jobs:
name: Version ${{ steps.tag.outputs.tagname }}
bodyFile: ./.tagmsg.txt
makeLatest: true

- name: Publish role to Galaxy
uses: robertdebock/[email protected]
with:
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
name: CodeQL
on: # yamllint disable-line rule:truthy
push:
branches: ["main"]
pull_request:
branches: ["main"]
merge_group:
branches:
- main
types:
- checks_requested
schedule:
- cron: 48 9 * * 6
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [python]
steps:
- name: Update pip, git
run: |
set -euxo pipefail
sudo apt update
sudo apt install -y git
- name: Checkout
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{ matrix.language }}"
3 changes: 1 addition & 2 deletions .github/workflows/pr-title-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ jobs:

- name: Run commitlint on PR title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
# Echo from env variable to avoid bash errors with extra characters
PR_TITLE: ${{ github.event.pull_request.title }}# Echo from env variable to avoid bash errors with extra characters
run: echo "$PR_TITLE" | npx commitlint --verbose
84 changes: 84 additions & 0 deletions .github/workflows/python-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
# yamllint disable rule:line-length
name: Python Unit Tests
on: # yamllint disable-line rule:truthy
pull_request:
merge_group:
branches:
- main
types:
- checks_requested
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
jobs:
python:
strategy:
matrix:
pyver_os:
- ver: "2.7"
os: ubuntu-20.04
- ver: "3.6"
os: ubuntu-20.04
- ver: "3.8"
os: ubuntu-latest
- ver: "3.9"
os: ubuntu-latest
- ver: "3.10"
os: ubuntu-latest
- ver: "3.11"
os: ubuntu-latest
runs-on: ${{ matrix.pyver_os.os }}
steps:
- name: Update git
run: |
set -euxo pipefail
sudo apt update
sudo apt install -y git
- name: checkout PRuses: actions/checkout@v4

- name: Set up Python 2.7
if: ${{ matrix.pyver_os.ver == '2.7' }}
run: |
set -euxo pipefail
sudo apt install -y python2.7
- name: Set up Python 3
if: ${{ matrix.pyver_os.ver != '2.7' }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.pyver_os.ver }}

- name: Install platform dependencies, python, tox, tox-lsr
run: |
set -euxo pipefail
python -m pip install --upgrade pippip install "git+https://github.com/linux-system-roles/[email protected]"
# If you have additional OS dependency packages e.g. libcairo2-dev
# then put them in .github/config/ubuntu-requirements.txt, one
# package per line.
if [ -f .github/config/ubuntu-requirements.txt ]; then
sudo apt-get install -y $(cat .github/config/ubuntu-requirements.txt)
fi
- name: Run unit tests
run: |
set -euxo pipefail
toxpyver=$(echo "${{ matrix.pyver_os.ver }}" | tr -d .)
toxenvs="py${toxpyver}"
# NOTE: The use of flake8, pylint, black with specific
# python envs is arbitrary and must be changed in tox-lsr
# We really should either do those checks using the latest
# version of python, or in every version of python
case "$toxpyver" in
27) toxenvs="${toxenvs},coveralls,flake8,pylint" ;;
36) toxenvs="${toxenvs},coveralls,black" ;;
*) toxenvs="${toxenvs},coveralls" ;;
esac
TOXENV="$toxenvs" lsr_ci_runtox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion .github/workflows/weekly_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
git push -f --set-upstream origin ${{ env.BRANCH_NAME }}
- name: Create and comment pull request
uses: actions/github-script@v7
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_PUSH_TOKEN }}
script: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Role Name

[![ansible-lint.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-lint.yml) [![ansible-test.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-test.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-test.yml) [![markdownlint.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/markdownlint.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/markdownlint.yml) [![woke.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/woke.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/woke.yml)
[![ansible-lint.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-lint.yml) [![ansible-test.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-test.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-test.yml) [![codeql.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/codeql.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/codeql.yml) [![markdownlint.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/markdownlint.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/markdownlint.yml) [![python-unit-test.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/python-unit-test.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/python-unit-test.yml) [![woke.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/woke.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/woke.yml)

An Ansible role for bootloader and kernel command line management.

Expand Down
31 changes: 31 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,34 @@ are likely to be suitable for new contributors!

**Code** is managed on [Github](https://github.com/linux-system-roles/bootloader), using
[Pull Requests](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests).

## Python Code

The Python code needs to be **compatible with the Python versions supported by
the role platform**.

For example, see [meta](https://github.com/linux-system-roles/bootloader/blob/main/meta/main.yml)
for the platforms supported by the role.

If the role provides Ansible modules (code in `library/` or `module_utils/`) -
these run on the *managed* node, and typically[1] use the default system python:

* EL6 - python 2.6
* EL7 - python 2.7 or python 3.6 in some cases
* EL8 - python 3.6
* EL9 - python 3.9

If the role provides some other sort of Ansible plugin such as a filter, test,
etc. - these run on the *control* node and typically use whatever version of
python that Ansible uses, which in many cases is *not* the system python, and
may be a modularity release such as python311.

In general, it is a good idea to ensure the role python code works on all
versions of python supported by `tox-lsr` from py36 on, and on py27 if the role
supports EL7, and on py26 if the role supports EL6.[1]

[1] Advanced users may set
[ansible_python_interpreter](https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#term-ansible_python_interpreter)
to use a non-system python on the managed node, so it is a good idea to ensure
your code has broad python version compatibility, and do not assume your code
will only ever be run with the default system python.

0 comments on commit 60f379b

Please sign in to comment.