build: use github actions for CI/CD ()

This commit is contained in:
Nick Satterly 2021-01-06 01:23:41 +01:00 committed by GitHub
parent 2efa8e1e47
commit 614aa32efe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 178 additions and 52 deletions
.github/workflows
.travis.yml
integrations/mailer
requirements-dev.txt

174
.github/workflows/github-ci.yml vendored Normal file
View file

@ -0,0 +1,174 @@
name: CI Tests
on:
push:
branches: [ master, release/* ]
pull_request:
branches: [ master ]
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
jobs:
test-postgres:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_DB: alerta
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
python-version: [3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
id: install-deps
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install -r requirements-dev.txt
- name: Lint with flake8
id: lint
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=50 --max-line-length=127 --statistics
- name: Unit Test Plugins
id: unit-test-plugins
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/alerta
run: |
pytest -v plugins/*/test*.py --cov=plugins
- name: Unit Test Webhooks
id: unit-test-webhooks
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/alerta
run: |
pytest -v webhooks/*/test*.py --cov=webhooks
- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
if: failure()
test-mongodb:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo
ports:
- 27017:27017
strategy:
matrix:
python-version: [3.6, 3.7]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
id: install-deps
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install -r requirements-dev.txt
- name: Lint with flake8
id: lint
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=50 --max-line-length=127 --statistics
- name: Unit Test Plugins
id: unit-test-plugins
env:
DATABASE_URL: mongodb://127.0.0.1:27017/alerta
run: |
pytest -v plugins/*/test*.py --cov=plugins
- name: Unit Test Webhooks
id: unit-test-webhooks
env:
DATABASE_URL: mongodb://127.0.0.1:27017/alerta
run: |
pytest -v webhooks/*/test*.py --cov=webhooks
- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
if: failure()
test-integration:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo
ports:
- 27017:27017
ldap:
image: rroemhild/test-openldap
ports:
- 389:389
saml-idp:
image: jamedjo/test-saml-idp
ports:
- 9443:8443
- 9080:8080
env:
SIMPLESAMLPHP_SP_ENTITY_ID: http://localhost:8080
SIMPLESAMLPHP_SP_ASSERTION_CONSUMER_SERVICE: http://localhost:8080/auth/saml
steps:
- uses: actions/checkout@v2
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
python3-dev \
libldap2-dev \
libsasl2-dev \
xmlsec1
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x'
architecture: 'x64'
- name: Install dependencies
id: install-deps
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install -r requirements-dev.txt
- name: Integration Tests
id: integration-test
env:
DATABASE_URL: mongodb://127.0.0.1:27017/alerta
run: |
pylint -v integrations/*/*.py
- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
if: failure()

View file

@ -1,50 +0,0 @@
if: tag IS present OR type = pull_request OR (branch = master AND type = push) # we only CI the master, tags and PRs
language: python
cache: pip
dist: xenial
python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
env:
- DB=mongodb DATABASE_URL=mongodb://localhost:27017/alerta
- DB=postgres DATABASE_URL=postgres://localhost:5432/alerta
services:
- mongodb
- postgresql
addons:
postgresql: "9.6"
before_script:
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS alerta;' -U postgres; fi"
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'CREATE DATABASE alerta;' -U postgres; fi"
install:
- pip install -r requirements-dev.txt
script:
- pytest -v integrations/*/test*.py --cov=integrations
- pytest -v plugins/*/test*.py --cov=plugins
- pytest -v webhooks/*/test*.py --cov=webhooks
stages:
- Checks
- Test
jobs:
include:
- stage: Checks
name: Integrations
script: pylint -v integrations/*/*.py
- name: Plugins
script: pylint -v plugins/*/*.py
- name: Web Hooks
script: pylint -v webhooks/*/*.py
after_success:
- coveralls

View file

@ -10,6 +10,7 @@ import signal
import smtplib
import socket
from functools import reduce
import six
import sys
import threading
@ -215,7 +216,7 @@ class MailSender(threading.Thread):
return True
LOG.debug('Regex %s matches nothing', regex)
return False
elif isinstance(value, str) or isinstance(value, unicode): # pylint: disable=undefined-variable
elif isinstance(value, six.string_types): # pylint: disable=undefined-variable
LOG.debug('Trying to match %s to %s',
value, regex)
return re.search(regex, value) is not None

View file

@ -2,10 +2,11 @@ alerta-server[postgres]
alerta-server[mongodb]
alerta
kombu
six
mock
mypy
pre-commit
PyJWT==1.7.1
pylint
pytest>=5.4.3
pytest-cov