forked from inno-devops-labs/S25-core-course-labs
-
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
1 parent
0e2e1d6
commit e38da0d
Showing
5 changed files
with
126 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: C++ Application CI | ||
|
||
on: | ||
push: | ||
paths: | ||
'app_C\+\+/**' | ||
|
||
env: | ||
USERNAME: voronm1522 | ||
DOCKER_IMAGE: voronm1522/devops | ||
DOCKER_TAG: cpp-app | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Cache python | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.cache/pip | ||
key: ubuntu-python-${{ hashFiles('app_C++/requirements.txt') }} | ||
restore-keys: | | ||
ubuntu-python- | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Install dependencies and linter | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r app_C++/requirements.txt | ||
sudo apt update | ||
sudo apt install cppcheck | ||
- name: Lint with Cppcheck | ||
run: | | ||
cppcheck app_C++/app.cpp | ||
- name: Run tests | ||
run: | | ||
python app_C++/unittests.py | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ env.USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ubuntu-docker-${{ hashFiles('app_python/Dockerfile') }} | ||
restore-keys: | | ||
ubuntu-docker- | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: app_python | ||
push: true | ||
tags: ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} | ||
|
||
- name: Install snyk | ||
run: npm install -g snyk | ||
|
||
- name: Run snyk | ||
run: | | ||
cd app_C++ | ||
snyk test | ||
env: | ||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | ||
|
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,7 +1,9 @@ | ||
name: Application CI | ||
name: Python Application CI | ||
|
||
on: | ||
push: | ||
paths: | ||
- "app_python/**" | ||
|
||
env: | ||
USERNAME: voronm1522 | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
certifi==2025.1.31 | ||
charset-normalizer==3.4.1 | ||
idna==3.10 | ||
requests==2.32.3 | ||
urllib3==2.3.0 |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import unittest, subprocess, time, requests, os | ||
|
||
SERVER="http://127.0.0.1:8080/" | ||
|
||
class TestServer(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.server_process = subprocess.Popen(["./server"]) | ||
time.sleep(2) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.server_process.terminate() | ||
cls.server_process.wait() | ||
|
||
def test_response_status_code(self): | ||
response = requests.get(SERVER) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_response_format(self): | ||
response = requests.get(SERVER) | ||
self.assertTrue(response.text.startswith("Random number is: ")) | ||
|
||
number_str = response.text[len("Random number is: "):] | ||
self.assertTrue(number_str.isdigit()) | ||
|
||
if __name__ == "__main__": | ||
os.system("g++ app.cpp -o server") | ||
|
||
try: | ||
unittest.main() | ||
finally: | ||
if os.path.exists("server"): | ||
os.remove("server") |