-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (50 loc) · 1.65 KB
/
main.yml
File metadata and controls
51 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Continuous Integration
on: [ pull_request, workflow_dispatch ]
jobs:
unit_test:
runs-on: ubuntu-latest
env:
CODE_COVERAGE_THRESHOLD: 90
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 python dependencies
run: pip install -r app/requirements.txt
- name: Run flask app
run: |
export FLASK_APP=$PWD/app/run.py
flask run &
- name: Run unit test
run: coverage run -m pytest app/
- name: Print unit test report
run: coverage report
- name: Validate code coverage
run: |
COVERAGE=$(coverage report | tail -n 1 | awk '{print $4}' | head -c 2)
if [ "$COVERAGE" -lt "$CODE_COVERAGE_THRESHOLD" ]; then
echo "Error: Code coverage cannot be smaller than $CODE_COVERAGE_THRESHOLD%, got $COVERAGE%"
exit 1
fi
publish:
runs-on: ubuntu-latest
needs:
- unit_test
env:
IMAGE_ARTIFACT: ${{ secrets.DOCKER_HUB_USERNAME }}/sherlock:latest
environment: production
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub
run: docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build docker image
run: docker build --tag flask-sherlock $GITHUB_WORKSPACE
- name: Tag docker image
run: docker tag flask-sherlock $IMAGE_ARTIFACT
- name: Push image to DockerHub
run: docker push $IMAGE_ARTIFACT