Skip to content

Commit ce62e7e

Browse files
Merge pull request #170 from microsoft/PSL-additionOfGithubAction
ci: Add configuration files and workflows for enhanced CI/CD and quality checks
2 parents f952fd7 + 78d0731 commit ce62e7e

15 files changed

+432
-36
lines changed

.coveragerc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[run]
2+
omit =
3+
*/test_*.py

.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

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ Verify that the following are valid
3434
* ...
3535

3636
## Other Information
37+
3738
<!-- Add any other helpful information that may be needed here. -->
39+

.github/dependabot.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Dependabot configuration file
2+
# For more details, refer to: https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3+
4+
version: 2
5+
updates:
6+
# GitHub Actions dependencies
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "monthly"
11+
commit-message:
12+
prefix: "build"
13+
target-branch: "dependabotchanges"
14+
open-pull-requests-limit: 20
15+
16+
- package-ecosystem: "pip"
17+
directory: "/App"
18+
schedule:
19+
interval: "monthly"
20+
commit-message:
21+
prefix: "build"
22+
target-branch: "dependabotchanges"
23+
open-pull-requests-limit: 60
24+
25+
- package-ecosystem: "npm"
26+
directory: "/App/frontend"
27+
schedule:
28+
interval: "monthly"
29+
commit-message:
30+
prefix: "build"
31+
target-branch: "dependabotchanges"
32+
open-pull-requests-limit: 60
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: CI-Validate Deployment-KM-Generic
2+
on:
3+
push:
4+
branches:
5+
6+
- main
7+
- dev
8+
- demo
9+
10+
schedule:
11+
- cron: '0 6,18 * * *' # Runs at 6:00 AM and 6:00 PM GMT
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout Code
18+
uses: actions/checkout@v3
19+
20+
- name: Setup Azure CLI
21+
run: |
22+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
23+
az --version # Verify installation
24+
25+
- name: Login to Azure
26+
run: |
27+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
28+
29+
- name: Install Bicep CLI
30+
run: az bicep install
31+
32+
- name: Generate Resource Group Name
33+
id: generate_rg_name
34+
run: |
35+
echo "Generating a unique resource group name..."
36+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
37+
COMMON_PART="ci-KMGeneric"
38+
UNIQUE_RG_NAME="${COMMON_PART}${TIMESTAMP}"
39+
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
40+
echo "Generated Resource_GROUP_PREFIX: ${UNIQUE_RG_NAME}"
41+
42+
- name: Create Resource Group
43+
run: |
44+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location westeurope
45+
46+
- name: Generate Unique Solution Prefix
47+
id: generate_solution_prefix
48+
run: |
49+
set -e
50+
COMMON_PART="km"
51+
TIMESTAMP=$(date +%s)
52+
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 3)
53+
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
54+
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
55+
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
56+
57+
58+
- name: Determine Tag Name Based on Branch
59+
id: determine_tag
60+
run: echo "tagname=${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || github.head_ref || 'default' }}" >> $GITHUB_OUTPUT
61+
62+
- name: Deploy Bicep Template
63+
id: deploy
64+
run: |
65+
set -e
66+
az deployment group create \
67+
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
68+
--template-file Deployment/bicep/main.bicep \
69+
--parameters solutionPrefix=${{ env.SOLUTION_PREFIX }} otherLocation=centralus imageTag=${{ steps.determine_tag.outputs.tagname }}
70+
71+
72+
73+
- name: Send Notification on Failure
74+
if: failure()
75+
run: |
76+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
77+
78+
# Construct the email body
79+
EMAIL_BODY=$(cat <<EOF
80+
{
81+
"body": "<p>Dear Team,</p><p>We would like to inform you that the CKMv2 Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Build URL:</strong> ${RUN_URL}<br> ${OUTPUT}</p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>"
82+
}
83+
EOF
84+
)
85+
86+
# Send the notification
87+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
88+
-H "Content-Type: application/json" \
89+
-d "$EMAIL_BODY" || echo "Failed to send notification"
90+
91+
92+
- name: Delete Bicep Deployment
93+
94+
run: |
95+
set -e
96+
echo "Checking if resource group exists..."
97+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
98+
if [ "$rg_exists" = "true" ]; then
99+
echo "Resource group exist. Cleaning..."
100+
az group delete \
101+
--name ${{ env.RESOURCE_GROUP_NAME }} \
102+
--yes \
103+
--no-wait
104+
echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
105+
else
106+
echo "Resource group does not exists."
107+
fi
108+

.github/workflows/deploy.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ on:
33
push:
44
branches:
55
- ckm-v2
6-
schedule:
7-
- cron: '0 6,18 * * *' # Runs at 6:00 AM and 6:00 PM GMT
6+
87

98
jobs:
109
deploy:
@@ -92,4 +91,4 @@ jobs:
9291
# Send the notification
9392
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
9493
-H "Content-Type: application/json" \
95-
-d "$EMAIL_BODY" || echo "Failed to send notification"
94+
-d "$EMAIL_BODY" || echo "Failed to send notification"

.github/workflows/docker-build.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
- demo
9+
pull_request:
10+
types:
11+
- opened
12+
- ready_for_review
13+
- reopened
14+
- synchronize
15+
branches:
16+
- main
17+
- dev
18+
- demo
19+
workflow_dispatch:
20+
21+
jobs:
22+
build-and-push:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v2
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v1
31+
32+
- name: Log in to Azure Container Registry
33+
if: ${{ github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' ) }}
34+
uses: azure/docker-login@v2
35+
with:
36+
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
37+
username: ${{ secrets.ACR_USERNAME }}
38+
password: ${{ secrets.ACR_PASSWORD }}
39+
40+
- name: Get current date
41+
id: date
42+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
43+
44+
- name: Output ACR Login Server
45+
run: |
46+
echo "ACR Login Server: ${{ secrets.ACR_LOGIN_SERVER }}"
47+
48+
- name: Determine Tag Name Based on Branch
49+
id: determine_tag
50+
run: |
51+
if [[ "${{ github.ref_name }}" == "main" ]]; then
52+
echo "tagname=latest" >> $GITHUB_OUTPUT
53+
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
54+
echo "tagname=dev" >> $GITHUB_OUTPUT
55+
elif [[ "${{ github.ref_name }}" == "demo" ]]; then
56+
echo "tagname=demo" >> $GITHUB_OUTPUT
57+
else
58+
echo "tagname=default" >> $GITHUB_OUTPUT
59+
60+
fi
61+
- name: Build and Push Docker Image for WebApp
62+
uses: docker/build-push-action@v6
63+
with:
64+
context: ./App
65+
file: ./App/WebApp.Dockerfile
66+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' }}
67+
tags: |
68+
${{ secrets.ACR_LOGIN_SERVER }}/km-app:${{ steps.determine_tag.outputs.tagname }}
69+
${{ secrets.ACR_LOGIN_SERVER }}/km-app:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}
70+
71+
- name: Build and Push Docker Image for km-rag-function
72+
uses: docker/build-push-action@v6
73+
with:
74+
context: ./AzureFunctions/km-rag-function
75+
file: ./AzureFunctions/km-rag-function/Dockerfile
76+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' }}
77+
tags: |
78+
${{ secrets.ACR_LOGIN_SERVER }}/km-rag-function:${{ steps.determine_tag.outputs.tagname }}
79+
${{ secrets.ACR_LOGIN_SERVER }}/km-rag-function:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}
80+
81+
- name: Build and Push Docker Image for km-charts-function
82+
uses: docker/build-push-action@v6
83+
with:
84+
context: ./AzureFunctions/km-charts-function
85+
file: ./AzureFunctions/km-charts-function/Dockerfile
86+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' }}
87+
tags: |
88+
${{ secrets.ACR_LOGIN_SERVER }}/km-charts-function:${{ steps.determine_tag.outputs.tagname }}
89+
${{ secrets.ACR_LOGIN_SERVER }}/km-charts-function:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}

.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 App/requirements.txt
23+
pip install flake8 # Ensure flake8 is installed explicitly
24+
25+
- name: Run flake8 and pylint
26+
run: |
27+
flake8 --config=.flake8 App/backend # Specify the directory to lint

.github/workflows/test.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Test Workflow with Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
- demo
9+
pull_request:
10+
types:
11+
- opened
12+
- ready_for_review
13+
- reopened
14+
- synchronize
15+
branches:
16+
- main
17+
- dev
18+
- demo
19+
20+
jobs:
21+
# frontend_tests:
22+
# runs-on: ubuntu-latest
23+
24+
# steps:
25+
# - name: Checkout code
26+
# uses: actions/checkout@v3
27+
28+
# - name: Set up Node.js
29+
# uses: actions/setup-node@v3
30+
# with:
31+
# node-version: '20'
32+
33+
# - name: Check if Frontend Test Files Exist
34+
# id: check_frontend_tests
35+
# run: |
36+
# if [ -z "$(find App/frontend/src -type f -name '*.test.js' -o -name '*.test.ts' -o -name '*.test.tsx')" ]; then
37+
# echo "No frontend test files found, skipping frontend tests."
38+
# echo "skip_frontend_tests=true" >> $GITHUB_ENV
39+
# else
40+
# echo "Frontend test files found, running tests."
41+
# echo "skip_frontend_tests=false" >> $GITHUB_ENV
42+
# fi
43+
44+
# - name: Install Frontend Dependencies
45+
# if: env.skip_frontend_tests == 'false'
46+
# run: |
47+
# cd App/frontend
48+
# npm install
49+
50+
# - name: Run Frontend Tests with Coverage
51+
# if: env.skip_frontend_tests == 'false'
52+
# run: |
53+
# cd App/frontend
54+
# npm run test -- --coverage
55+
56+
# - name: Skip Frontend Tests
57+
# if: env.skip_frontend_tests == 'true'
58+
# run: |
59+
# echo "Skipping frontend tests because no test files were found."
60+
61+
backend_tests:
62+
runs-on: ubuntu-latest
63+
64+
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v3
68+
69+
- name: Set up Python
70+
uses: actions/setup-python@v4
71+
with:
72+
python-version: '3.11'
73+
74+
- name: Install Backend Dependencies
75+
run: |
76+
python -m pip install --upgrade pip
77+
pip install -r App/requirements.txt
78+
pip install pytest-cov
79+
pip install pytest-asyncio
80+
81+
- name: Check if Backend Test Files Exist
82+
id: check_backend_tests
83+
run: |
84+
if [ -z "$(find App/backend -type f -name 'test_*.py')" ]; then
85+
echo "No backend test files found, skipping backend tests."
86+
echo "skip_backend_tests=true" >> $GITHUB_ENV
87+
else
88+
echo "Backend test files found, running tests."
89+
echo "skip_backend_tests=false" >> $GITHUB_ENV
90+
fi
91+
92+
- name: Run Backend Tests with Coverage
93+
if: env.skip_backend_tests == 'false'
94+
run: |
95+
pytest --cov=. --cov-report=term-missing --cov-report=xml
96+
97+
98+
99+
- name: Skip Backend Tests
100+
if: env.skip_backend_tests == 'true'
101+
run: |
102+
echo "Skipping backend tests because no test files were found."

0 commit comments

Comments
 (0)