Skip to content

BugFix

BugFix #161

# GitHub Action workflow to build and run KnowsMore's tests
#
name: Test Build
on:
push:
branches: [ main ]
paths-ignore:
- .gitignore
- README.md
- LICENSE
- TODO
- knowsmore/__meta__.py
- .github/workflows/build_and_test.yml
- .github/workflows/build_and_publish.yml
pull_request:
branches: [ main ]
paths-ignore:
- .gitignore
- README.md
- LICENSE
- TODO
- knowsmore/__meta__.py
- .github/workflows/build_and_test.yml
- .github/workflows/build_and_publish.yml
jobs:
lint:
name: Check syntaxs errors and warnings
runs-on: ubuntu-latest
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
steps:
- name: Checkout KnowsMore
uses: actions/checkout@v3
- name: Setup Python 3.9
uses: actions/setup-python@v3
with:
python-version: 3.9
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8
- name: Check syntax errors
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Check PEP8 warnings
run: |
flake8 . --count --ignore=E1,E2,E3,E501,W291,W293 --exit-zero --max-complexity=65 --max-line-length=127 --statistics
bloodhound_ingestor:
name: Check bloodhound ingestor integrity
needs: lint
runs-on: ubuntu-latest
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
steps:
- name: Checkout KnowsMore
uses: actions/checkout@v3
- name: Setup Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r tests/requirements-test.txt
- name: Install knowsmore
run: |
pip install .
- name: Install dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: docker-compose jq
version: 1.0
- name: Clonning repository
run: |
git clone https://github.com/SpecterOps/BloodHound.git /opt/BloodHound
cd /opt/BloodHound/
cp examples/docker-compose/* ./
jq -r '.features.enable_auth |= false | .default_admin.email_address |= "[email protected]" | .default_admin.password |= "@Pass123456" | .default_admin.expire_now |= false' examples/docker-compose/bloodhound.config.json > bloodhound.config.json
- name: Creatting docker image
run: |
cd /opt/BloodHound
docker-compose up --detach
- name: Running ingestor
run: |
chmod +x ./tests/bh.sh
./tests/bh.sh
- name: Run BloodHound unit tests
run: |
pytest -s tests/tests_bh.py
- name: Removing docker image
run: |
cd /opt/BloodHound
docker-compose down -v --rmi all
test:
name: Run unit tests and build wheel
needs: bloodhound_ingestor
runs-on: ${{ matrix.os }}
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
experimental: [false]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- python-version: "3.11"
experimental: true
os: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
steps:
- name: Checkout KnowsMore
uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r tests/requirements-test.txt
- name: Install knowsmore
run: |
pip install .
- name: Run unit tests
run: |
pytest -s tests/tests.py
- name: Remove tests folder (Windows)
if: "contains(matrix.os, 'windows')"
run: |
Remove-Item tests -Force -Recurse
- name: Remove tests folder (Unix)
if: "!contains(matrix.os, 'windows')"
run: |
rm -rf ./tests/
- name: Build artifact
run: |
python setup.py sdist
publish:
name: Publish on Test Environment
needs: test
runs-on: ubuntu-latest
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
experimental: [false]
continue-on-error: ${{ matrix.experimental }}
steps:
- name: Checkout KnowsMore
uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r tests/requirements-test.txt
- name: Change Package version
run: |
oldv=$( grep '__version__' knowsmore/__meta__.py | grep -oE '[0-9\.]+')
current=$(date '+%Y%m%d%H%M%S')
meta=$(cat knowsmore/__meta__.py | sed "s/__version__.*/__version__ = '"${oldv}"-"${current}"'/")
echo "$meta" > knowsmore/__meta__.py
- name: Install knowsmore
run: |
pip install .
- name: Build artifact
run: |
rm -rf ./tests/
python setup.py sdist
- name: Publish package in Test Environment
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true