Skip to content

Commit 40e9ff4

Browse files
authored
Enabled unit tests in cicd
1 parent b7216f2 commit 40e9ff4

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

.github/workflows/dev_workflow.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
Build:
1212
environment: Development
1313
runs-on: ubuntu-latest
14+
if: github.event.pull_request.merged == true
1415
steps:
1516
- uses: actions/checkout@v2
1617
- uses: azure/docker-login@v1
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
######### Stage Workflow ########
3+
on:
4+
pull_request:
5+
branches: [stage]
6+
types:
7+
- closed
8+
workflow_dispatch:
9+
10+
jobs:
11+
Build:
12+
environment: Stage
13+
runs-on: ubuntu-latest
14+
if: github.event.pull_request.merged == true
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: azure/docker-login@v1
18+
with:
19+
login-server: ${{ secrets.REGISTRY_DOMAIN }}
20+
username: ${{ secrets.REGISTRY_USERNAME }}
21+
password: ${{ secrets.REGISTRY_PASSWORD }}
22+
- name: Publish image to Azure Registry
23+
run: |
24+
docker build -t ${{ secrets.REGISTRY_DOMAIN }}/${{ secrets.REGISTRY_REPO }}:${{ github.sha }} -t ${{ secrets.REGISTRY_DOMAIN }}/${{ secrets.REGISTRY_REPO }}:${{ github.ref_name == 'master' && 'prod' || github.ref_name }}${{ github.ref_name != 'master' && '-latest' || 'latest' }} .
25+
docker push ${{ secrets.REGISTRY_DOMAIN }}/${{ secrets.REGISTRY_REPO }} --all-tags
26+
Deploy:
27+
needs: Build
28+
environment:
29+
name: Development
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Deploy to Stage
33+
uses: azure/webapps-deploy@v2
34+
with:
35+
app-name: ${{ secrets.AZURE_WEBAPP_NAME }}
36+
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
37+
images: ${{ secrets.REGISTRY_DOMAIN }}/${{ secrets.REGISTRY_REPO }}:${{ github.sha }}.

.github/workflows/unit_tests.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
name: Unit Tests
3+
4+
#############################
5+
# Start the job on all push #
6+
#############################
7+
on:
8+
push:
9+
branches-ignore:
10+
- '**'
11+
# Remove the line above to run when pushing to master
12+
pull_request:
13+
branches: [master, dev]
14+
15+
###############
16+
# Set the Job #
17+
###############
18+
jobs:
19+
UnitTest:
20+
name: Unit Test Cases
21+
# Set the agent to run on
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v3
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: "3.10" # Use the appropriate Python version
31+
32+
- name: Install dependencies
33+
run: |
34+
pip install -r requirements.txt
35+
pip install -i https://test.pypi.org/simple/ python-osw-validation==0.0.3
36+
37+
- name: Run unit tests
38+
run: |
39+
python test_report.py
40+
coverage run --source=src -m unittest discover -s tests/
41+
coverage report -m
42+
exit_status=$?
43+
44+
# Set the exit status as an output for later use
45+
echo "::set-output name=exit_status::$exit_status"
46+
47+
- name: Archive Coverage Report
48+
if: ${{ always() }} # Upload the coverage report even if tests fail
49+
uses: actions/upload-artifact@v2
50+
with:
51+
name: htmlcov
52+
path: htmlcov

0 commit comments

Comments
 (0)