-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,54 @@ | ||
name: Pylint and API Testing | ||
|
||
on: | ||
name: API CI/CD | ||
# This is a trigger for any push to the repo, and tells github when the actions have to be run | ||
# Every time we do a push, the action will be executed | ||
# The actions should be run only when there is a push from main and develop | ||
on: | ||
push: | ||
branches: [Milestone-5_feature_branch] | ||
branches: | ||
- MileStone5eric | ||
|
||
#Tells github actions what to execute when trigger condition is met | ||
jobs: | ||
test-and-lint: | ||
runs-on: self-hosted # or ubuntu-latest | ||
# Each job runs in parallel | ||
tests: #This is the job name | ||
|
||
# runs-on indicates which GitHub "Runners" will run this CICD pipeline | ||
# For all CSE-2102 repos, just use the following line as is | ||
runs-on: self-hosted | ||
# This next block allows you to run this ENTIRE job on different python versions | ||
strategy: | ||
matrix: | ||
python-version: ["3.10"] | ||
#python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] | ||
python-version: ["3.8"] | ||
|
||
# Steps are run in sequence in this job. If one step fails, the entire job fails. | ||
steps: | ||
#Checkout code | ||
- uses: actions/checkout@v2 # Updated to correct version | ||
|
||
#Set up Python | ||
# Use this next line to pull your repo into the Docker container running the job | ||
- uses: actions/checkout@v3 | ||
# This block sets up the python version | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
#Install everything | ||
- name: Install dependencies | ||
# Pylint is a static code analysis tool. Use this block as is to install pylint | ||
# in the Docker container running the job | ||
- name: Install pylint | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pylint flask flask_cors flasgger pytest | ||
#Run pylint on all Python files | ||
- name: Analyze code with pylint, excluding main.py | ||
run: | | ||
pylint $(git ls-files '*.py') | ||
pip install pylint | ||
#Build Docker Image for API | ||
- name: Build API Docker Image | ||
- name: Install pytest | ||
run: | | ||
docker build -t api-image -f Backend/dockerfile . | ||
# Stop and Remove Existing Container (if any). this was the error | ||
- name: Stop and Remove Existing API Container | ||
run: | | ||
docker stop api-container || true # Stop if running, ignore if not | ||
sleep 10 | ||
docker rm api-container || true # Remove if exists, ignore if not | ||
sleep 1 | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
#Start API Container | ||
- name: Start API Container | ||
- name: Run Api | ||
run: | | ||
docker run -d -p 5000:5000 --name api-container --memory=7g api-image # Start container on port 5000 | ||
python3 Backend/main.py & | ||
#Run all Python tests in the directory | ||
- name: Run the Python tests in directory | ||
run: | | ||
docker exec api-container python3 main.py # Execute main.py | ||
#docker exec api-container pytest test_main.py # Execute test_main.py | ||
#Stop and Remove API Container after tests | ||
- name: Stop and Remove API Container | ||
- name: pytest | ||
run: | | ||
docker stop api-container # Stop container after tests | ||
docker rm api-container # Remove container after tests | ||
pytest | ||