Skip to content

increase test coverage #194

increase test coverage

increase test coverage #194

Workflow file for this run

name: Docker CD
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
types: [opened, synchronize, reopened]
jobs:
code-test:
# Kicks off the workflow and prepares Github to run coverage test using a ubuntu-latest container.
name: Code Test
runs-on: ubuntu-latest
env:
OS: ubuntu-latest
PYTHON: '3.9'
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.9
# Install dependencies required for tests
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install libxml2-dev libxmlsec1-dev -y --no-install-recommends
python -m pip install --upgrade pip
pip install -r ./requirements.txt
# Start running test scripts and generate the coverage report
- name: Generate Coverage Report
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
CERT_VOLUME: ${{ secrets.CERT_VOLUME }}
run: |
echo "Cloning private repository"
git clone https://openlxp-host:${{ secrets.ACCESS_TOKEN }}@github.com/OpenLXP/openlxp-private.git
echo "Private repository cloned successfully"
echo "Copying .env file from openlxp-private to current working directory"
cp ./openlxp-private/openlxp-xds-env/.env .
echo "Copied .env file successfully"
echo "Create openlxp docker network"
docker network create openlxp
echo "Docker network successfully created"
echo "Running coverage unit test"
docker-compose --env-file ./.env run app sh -c "python manage.py waitdb && coverage run manage.py test --tag=unit && flake8 && coverage report && coverage report --fail-under=80"
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
build:
# requires dependency from step above
needs: code-test
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Docker login
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "Authenticate to Docker"
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: Docker build
run: |
echo "Start docker build"
docker build . -t openlxp/openlxp-xds
- name: Push Image
run: |
echo "Push new image to the Dockerhub repository"
docker push openlxp/openlxp-xds