Skip to content

Commit

Permalink
Update GitHub actions for new CI/CD checks and deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alef-Burzmali committed Jul 18, 2024
1 parent b824839 commit 40f2571
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/RELEASE-TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Use version 0.8 if you need compatibility with NetBox 3.7
## Update procedure
* Run NetBox's `upgrade.sh`, and restart NetBox

Check [the documentation](https://github.com/Alef-Burzmali/netbox-data-flows/blob/main/docs/installation-configuration.md#upgrade) for further instructions.
Check [the documentation](https://alef-burzmali.github.io/netbox-data-flows/installation-configuration/#upgrade) for further instructions.

## Changes
* ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@ permissions:
contents: read

jobs:
check-linting:
uses: ./.github/workflows/check-linting.yml

run-tests:
uses: ./.github/workflows/run-tests.yml

build:
name: Check and build project
needs: [check-linting, run-tests]
runs-on: "ubuntu-latest"

steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Compare version from tag and from project
run: |
PROJECT_VERSION=$(grep -F "__version__ =" netbox_data_flows/__init__.py | cut -d\" -f2)
Expand All @@ -33,13 +45,16 @@ jobs:
echo "Version mismatch" >&2
exit 1
fi
- name: Build project
run: python -m build .

- name: Verify build
run: python -m twine check --strict dist/*

- name: Save build artifacts
uses: actions/upload-artifact@v4
with:
name: distributions
path: dist/*
retention-days: 2
retention-days: 3
37 changes: 37 additions & 0 deletions .github/workflows/check-documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test the documentation build

on:
push:
paths:
- 'docs/**'
branches-ignore:
- 'gh-pages'
pull_request:
workflow_call:
workflow_dispatch:

permissions:
contents: read

jobs:
check-documentation:
name: Check documentation
runs-on: "ubuntu-latest"

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements_docs.txt
- name: Check documentation build
run: |
mkdocs build --strict
49 changes: 49 additions & 0 deletions .github/workflows/check-linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Check linting on push and pull request

on:
push:
paths-ignore:
- 'docs/**'
branches-ignore:
- 'gh-pages'
pull_request:
workflow_call:
workflow_dispatch:

permissions:
contents: read

jobs:
check-linting:
name: Check linting
runs-on: ubuntu-latest

steps:
- name: "Checkout repository"
uses: actions/checkout@v4

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

- name: Install dependencies & set up configuration
run: |
python -m pip install --upgrade pip
pip install -r requirements_dev.txt
- name: "Check code formatting with black"
run: |
black --check netbox_data_flows
- name: "Check PEP8 compliance with Flake8"
run: |
flake8 --extend-ignore=D100,D101,D102,D103,D104,D105,D106,D107,D401 --max-line-length 120 netbox_data_flows
- name: "Check import order"
run: |
isort --check netbox_data_flows
- name: "Check manifest"
run: |
check-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,36 @@ permissions:
contents: write

jobs:
black:
uses: ./.github/workflows/python-black.yml
build:
needs: black
uses: ./.github/workflows/python-build.yml
build-package:
uses: ./.github/workflows/build-package.yml

autorelease:
name: Create Draft Release
needs: [black, build]
needs: [build-package]
runs-on: "ubuntu-latest"

steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

- name: Get version of project
run: |
PROJECT_VERSION=$(grep -F "__version__ =" netbox_data_flows/__init__.py | cut -d\" -f2)
echo "Version from __init__.py: ${PROJECT_VERSION}"
echo "PROJECT_VERSION=${PROJECT_VERSION}" >> $GITHUB_ENV
- run: mkdir dist
- uses: actions/download-artifact@v4
- name: Create staging directory
run: mkdir dist

- name: Fetch build artifacts
uses: actions/download-artifact@v4
with:
name: distributions
path: dist/
- name: Prepare release Notes
run: git log $(git describe HEAD~ --tags --abbrev=0)..HEAD --pretty='format:* %h %s%n * %an <%ae>' --no-merges >> ".github/RELEASE-TEMPLATE.md"

- name: Prepare Release Notes
run: git log $(git describe HEAD~ --tags --abbrev=0)..HEAD --pretty='format:* %h %s' --no-merges >> ".github/RELEASE-TEMPLATE.md"

- name: Create Release Draft
uses: softprops/action-gh-release@v2
with:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/publish-documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Create documentation and publish it to GitHub pages

on:
workflow_call:
workflow_dispatch:

permissions:
contents: write

jobs:
publish-documentation:
name: Publish documentation
runs-on: "ubuntu-latest"

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements_docs.txt
- name: Check documentation build
run: |
mkdocs build --strict
- name: Publish documentation
run: |
mkdocs gh-deploy --force
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,33 @@ permissions:
contents: read

jobs:
build:
uses: ./.github/workflows/python-build.yml
testpypi-publish:
build-package:
uses: ./.github/workflows/build-package.yml

publish-pypi:
name: Upload release to PyPI
needs: build
needs: [build-package]
runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/p/netbox-data-flows

permissions:
id-token: write

steps:
- run: mkdir dist
- uses: actions/download-artifact@v4
- name: Create staging directory
run: mkdir dist

- name: Fetch build artifacts
uses: actions/download-artifact@v4
with:
name: distributions
path: dist/

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish-documentation:
uses: ./.github/workflows/publish-documentation.yml
17 changes: 0 additions & 17 deletions .github/workflows/python-black.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ on:
branches-ignore:
- 'gh-pages'
pull_request:
paths-ignore:
- 'docs/**'
workflow_call:
workflow_dispatch:

permissions:
contents: read

jobs:
check-linting:
run-tests:
name: Run tests
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -89,3 +87,4 @@ jobs:
working-directory: netbox
run: |
python netbox/manage.py test --parallel auto netbox_data_flows
58 changes: 58 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
default_stages: [pre-commit]
default_install_hook_types: [pre-commit, pre-push]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: no-commit-to-branch
- id: check-ast
- id: check-toml
- id: end-of-file-fixer
stages: ["pre-commit"]
- id: trailing-whitespace
stages: ["pre-commit"]

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black

- repo: local
hooks:
- id: pyproject-flake8
name: pyproject-flake8
language: system
pass_filenames: true
entry: pflake8
types: ["python"]

- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
hooks:
- id: check-manifest

- repo: local
hooks:
- id: check-missing-migrations
name: check-missing-migrations
entry: python /opt/netbox-dev/netbox/manage.py makemigrations netbox_data_flows --check
language: system
pass_filenames: false
types: ["python"]
stages: ["pre-push", "manual"]
- id: check-pending-migrations
name: check-pending-migrations
entry: python /opt/netbox-dev/netbox/manage.py migrate netbox_data_flows --check
language: system
pass_filenames: false
types: ["python"]
stages: ["pre-push", "manual"]
- id: run-tests
name: run-tests
entry: python /opt/netbox-dev/netbox/manage.py test --parallel auto netbox_data_flows
language: system
pass_filenames: false
types: ["python"]
stages: ["manual"]
verbose: true
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
include *.md
recursive-include netbox_data_flows/templates *.html
recursive-include docs *.md *.png

exclude .editorconfig .pre-commit-config.yaml
exclude mkdocs.yml
exclude requirements_dev.txt requirements_docs.txt

0 comments on commit 40f2571

Please sign in to comment.