Skip to content

Commit

Permalink
Merge branch 'feature/ci-testing'
Browse files Browse the repository at this point in the history
chore(workflows): Add integration and linting tests
  • Loading branch information
pheus committed Jul 22, 2024
2 parents ce4e927 + 525f442 commit d9a07cb
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 64 deletions.
38 changes: 38 additions & 0 deletions .ci/configuration.testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
###############################################################
# This NetBox configuration file serves as a base for testing #
# purposes only. It is not intended for production use. #
###############################################################

ALLOWED_HOSTS = ["*"]

DATABASE = {
"NAME": "netbox",
"USER": "netbox",
"PASSWORD": "netbox",
"HOST": "localhost",
"PORT": "",
"CONN_MAX_AGE": 300,
}

PLUGINS = [
"netbox_aci_plugin",
]

REDIS = {
"tasks": {
"HOST": "localhost",
"PORT": 6379,
"PASSWORD": "",
"DATABASE": 0,
"SSL": False,
},
"caching": {
"HOST": "localhost",
"PORT": 6379,
"PASSWORD": "",
"DATABASE": 1,
"SSL": False,
},
}

SECRET_KEY = "5i1(eGhHM_!*&E9-7rJ2y8wF8EA3iNvhRU#X&990-WJE&eT@@7"
94 changes: 94 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
name: Continuous Integration 🔄

on:
pull_request:
push:
branches:
- main

jobs:
pre-commit:
name: Run pre-commit hooks 🪝
runs-on: ubuntu-latest
steps:
- name: Set up repository 🧩
uses: actions/checkout@v4
- name: Set up Python 🐍
uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: "pip"
- name: Run pre-commit hooks 🪝
uses: pre-commit/[email protected]

test-plugin-integration:
name: >-
Run tests 🧪 [NB ${{ matrix.netbox-version }} |
Py ${{ matrix.python-version }}]
needs:
- pre-commit
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
netbox-version: ["v4.0.0", "master"]
services:
redis:
image: redis
ports:
- 6379:6379
postgres:
image: postgres
env:
POSTGRES_USER: netbox
POSTGRES_PASSWORD: netbox
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout repository of the plugin 🧩
uses: actions/checkout@v4
with:
path: netbox_aci_plugin

- name: Checkout repository of NetBox ${{ matrix.netbox-version }} 📦
uses: actions/checkout@v4
with:
repository: "netbox-community/netbox"
ref: ${{ matrix.netbox-version }}
path: netbox

- name: Set up Python ${{ matrix.python-version }} 🐍
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"

- name: Set up NetBox configuration for testing 🧪
working-directory: netbox
run: |
ln -s $(pwd)/../netbox_aci_plugin/.ci/configuration.testing.py \
netbox/netbox/configuration.py
- name: Install dependencies for NetBox 📦
working-directory: netbox
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -U
- name: Install Plugin in NetBox environment 🧩
working-directory: netbox_aci_plugin
run: |
pip install -e .
- name: Run Django tests 🧪
working-directory: netbox
run: |
python netbox/manage.py test netbox_aci_plugin.tests --parallel -v 2
...
20 changes: 11 additions & 9 deletions .github/workflows/mkdocs.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: ci
name: Deploy docs 📚 to GitHub pages

on:
push:
Expand All @@ -10,18 +10,19 @@ permissions:
contents: write

jobs:

deploy:
name: Deploy docs
name: Build and deploy docs 📚
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/[email protected]
- name: Checkout repository 🧩
uses: actions/checkout@v4
- name: Set up Python 🐍
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
cache: "pip"
- name: Install MKDocs and plugins 📚
run: >-
pip install
mkdocs-material
Expand All @@ -30,6 +31,7 @@ jobs:
mkdocstrings
mkdocstrings-python-legacy
mkdocs-include-markdown-plugin
- name: Deploy docs to GitHub pages
run: mkdocs gh-deploy --force
- name: Deploy docs to GitHub pages 📚
run: |
mkdocs gh-deploy --force
...
55 changes: 0 additions & 55 deletions .github/workflows/publish-pypi.yaml

This file was deleted.

123 changes: 123 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
# see:
# https://packaging.python.org/en/latest/guides/\
# publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
name: Publish Python 🐍 distribution 📦

on:
pull_request:
push:
branches:
- main
tags:
- "v*"

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- name: Checkout repository 🧩
uses: actions/checkout@v4
- name: Set up Python 🐍
uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: "pip"
- name: Install pypa/build 🏗️
run: |
python -m pip install build --user
- name: Build a binary wheel and a source tarball 📦
run: |
python -m build
- name: Store the distribution packages 📦
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

check-version:
name: Check project versioning 🏷️
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest

steps:
- name: Checkout repository 🧩
uses: actions/checkout@v4
- name: Set up Python 🐍
uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: "pip"
- name: Extract version from pyproject.toml and set as env variable 📝
run: |
PYPROJECT_VERSION=$(python -c "import tomllib; \
f = open('pyproject.toml', 'rb'); data = tomllib.load(f); \
print(data['project']['version']); f.close()")
echo "PACKAGE_VERSION=$PYPROJECT_VERSION" >> $GITHUB_ENV
shell: bash
- name: Check if project version matches the git tag 🏷️
run: |
TAG=$(git describe HEAD --tags --abbrev=0 | sed 's/^v//')
echo "Tag (without 'v'): $TAG"
echo "Package version: $PACKAGE_VERSION"
if [[ "$TAG" != "$PACKAGE_VERSION" ]]; then
echo "Error: Tag does not match the package version."
exit 1
fi
github-release:
name: Prepare GitHub release 🚀
if: startsWith(github.ref, 'refs/tags/')
needs:
- check-version
permissions:
contents: write
runs-on: ubuntu-latest

steps:
- name: Checkout repository 🧩
uses: actions/checkout@v4
- name: Extract version from git tag and set as env variable 📝
run: |
TAG=$(git describe HEAD --tags --abbrev=0 | sed 's/^v//')
echo "PACKAGE_VERSION=$TAG" >> $GITHUB_ENV
- name: Download all the dists 📦
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Prepare new release 🚀
uses: softprops/action-gh-release@v2
with:
body_path: ${{ github.workspace }}/CHANGELOG.md
draft: true
files: |
dist/netbox_aci_plugin-${{ env.PACKAGE_VERSION }}-py3-none-any.whl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-to-pypi:
name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
needs:
- check-version
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/netbox-aci-plugin
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists 📦
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI 🐍
uses: pypa/gh-action-pypi-publish@release/v1
...

0 comments on commit d9a07cb

Please sign in to comment.