Skip to content

Commit fcf538e

Browse files
Harmanpreet-MicrosoftHarmanpreet Kaur
andauthored
chore: Addition of PyLint,Test WorkFlow and Docker Integartion Workflow file (microsoft#38)
* edit 1 * edit 2 * Repository Governance * added stale-bot * stalebot test * chNGED TO 1 DAY * edit 3 * Create test * edit1 * edit2 * edit 4 * edit 5 * edit 6 * edit 6 * edit 7 * edit 8 * edit 5 * edit 10 * edit 11 * edit 12 * edit 13 * Update stale-bot.yml * edit 14 * edit 15 * edit 16 * edit 17 * Update stale-bot.yml * Update CODEOWNER * Create nwetest * added pylint * changed flak loc * edit 1 * add backend test workflow * added test file * edit 2 * added sample test file * changed py version * made edits to workflow * pass even if test filesa r not present * removed test file * added sample test file * Create docker-build-and-push.yml * Delete test * Delete src/backend/middleware/test_health_check.py * Delete .github/nwetest * Delete .github/workflows/CI.yml * updated docker * Update test.yml --------- Co-authored-by: Harmanpreet Kaur <[email protected]>
1 parent 93acd29 commit fcf538e

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E501
4+
exclude = .venv, frontend
5+
ignore = E203, W503, G004, G200
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
- demo
9+
- hotfix
10+
pull_request:
11+
types:
12+
- opened
13+
- ready_for_review
14+
- reopened
15+
- synchronize
16+
branches:
17+
- main
18+
- dev
19+
- demo
20+
- hotfix
21+
workflow_dispatch:
22+
23+
jobs:
24+
build-and-push:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v2
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v1
33+
34+
- name: Log in to Azure Container Registry
35+
if: ${{ github.ref_name == 'main' }}
36+
uses: azure/docker-login@v2
37+
with:
38+
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
39+
username: ${{ secrets.ACR_USERNAME }}
40+
password: ${{ secrets.ACR_PASSWORD }}
41+
42+
- name: Log in to Azure Container Registry (Dev/Demo)
43+
if: ${{ github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }}
44+
uses: azure/docker-login@v2
45+
with:
46+
login-server: ${{ secrets.ACR_DEV_LOGIN_SERVER }}
47+
username: ${{ secrets.ACR_DEV_USERNAME }}
48+
password: ${{ secrets.ACR_DEV_PASSWORD }}
49+
50+
- name: Set Docker image tag
51+
run: |
52+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
53+
echo "TAG=latest" >> $GITHUB_ENV
54+
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
55+
echo "TAG=dev" >> $GITHUB_ENV
56+
elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then
57+
echo "TAG=demo" >> $GITHUB_ENV
58+
elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then
59+
echo "TAG=hotfix" >> $GITHUB_ENV
60+
fi
61+
- name: Build and push Docker images
62+
if: ${{ github.ref_name == 'main' }}
63+
run: |
64+
cd src/backend
65+
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} -f Dockerfile . && \
66+
docker push ${{ secrets.ACR_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} && \
67+
echo "Backend image built and pushed successfully."
68+
cd ../frontend
69+
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} -f Dockerfile . && \
70+
docker push ${{ secrets.ACR_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} && \
71+
echo "Frontend image built and pushed successfully."
72+
- name: Build and push Docker images (Dev/Demo/hotfix)
73+
if: ${{ github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }}
74+
run: |
75+
cd src/backend
76+
docker build -t ${{ secrets.ACR_DEV_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} -f Dockerfile . && \
77+
docker push ${{ secrets.ACR_DEV_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} && \
78+
echo "Dev/Demo/Hotfix Backend image built and pushed successfully."
79+
cd ../frontend
80+
docker build -t ${{ secrets.ACR_DEV_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} -f Dockerfile . && \
81+
docker push ${{ secrets.ACR_DEV_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} && \
82+
echo "Dev/Demo/Hotfix Frontend image built and pushed successfully."
83+

.github/workflows/pylint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Pylint and Flake8
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.11"]
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v3
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -r src/backend/requirements.txt
23+
pip install flake8 # Ensure flake8 is installed explicitly
24+
25+
- name: Run flake8 and pylint
26+
run: |
27+
flake8 --config=.flake8 src/backend # Specify the directory to lint

.github/workflows/test.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Test Workflow with Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
- demo
9+
- hotfix
10+
pull_request:
11+
types:
12+
- opened
13+
- ready_for_review
14+
- reopened
15+
- synchronize
16+
branches:
17+
- main
18+
- main
19+
- dev
20+
- demo
21+
- hotfix
22+
23+
jobs:
24+
test:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v3
30+
31+
- name: Set up Python
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: '3.11'
35+
36+
- name: Install dependencies
37+
run: |
38+
python -m pip install --upgrade pip
39+
pip install -r src/backend/requirements.txt
40+
pip install pytest-cov
41+
42+
- name: Check if test files exist
43+
id: check_tests
44+
run: |
45+
if [ -z "$(find src -type f -name 'test_*.py')" ]; then
46+
echo "No test files found, skipping tests."
47+
echo "skip_tests=true" >> $GITHUB_ENV
48+
else
49+
echo "Test files found, running tests."
50+
echo "skip_tests=false" >> $GITHUB_ENV
51+
fi
52+
53+
- name: Run tests with coverage
54+
if: env.skip_tests == 'false'
55+
run: |
56+
pytest --cov=. --cov-report=term-missing --cov-report=xml
57+
58+
- name: Skip coverage report if no tests
59+
if: env.skip_tests == 'true'
60+
run: |
61+
echo "Skipping coverage report because no tests were found."

0 commit comments

Comments
 (0)