-
Notifications
You must be signed in to change notification settings - Fork 59
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
8201ba0
commit 54ef99f
Showing
9 changed files
with
127 additions
and
36 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,4 +1,4 @@ | ||
name: C++ Build (Сборка проекта) | ||
name: C++ Build and Run (Сборка и запуск проекта) | ||
|
||
on: | ||
push: | ||
|
@@ -10,16 +10,78 @@ on: | |
|
||
jobs: | ||
build: | ||
name: Build Docker Image | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
# 1. Checkout the repository | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run docker-compose | ||
uses: hoverkraft-tech/[email protected] | ||
# 2. Set up Docker Buildx | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
# 3. Cache Docker layers | ||
- name: Cache Docker layers | ||
id: cache-docker-layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-docker-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-docker- | ||
# 4. Build Docker image using Docker Compose | ||
- name: Build Docker image with Docker Compose | ||
run: | | ||
docker compose build bmstu | ||
docker compose up bmstu | ||
# Save the image as a tarball | ||
docker save bmstu_cpp_course-bmstu:latest -o cpp_course_image.tar | ||
# 5. Upload Docker image tarball as artifact | ||
- name: Upload Docker image tarball | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: cpp_course-image | ||
path: cpp_course_image.tar | ||
|
||
# 6. Save Docker layer cache | ||
- name: Save Docker layer cache | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: docker-layer-cache | ||
path: /tmp/.buildx-cache | ||
|
||
run-script: | ||
name: Run run.sh Script | ||
runs-on: ubuntu-latest | ||
needs: build | ||
|
||
steps: | ||
# 1. Download the Docker image tarball artifact | ||
- name: Download Docker image tarball | ||
uses: actions/download-artifact@v3 | ||
with: | ||
compose-file: "docker-compose.yml" | ||
name: cpp_course-image | ||
path: ./artifacts | ||
|
||
- name: | ||
# 2. Load the Docker image into Docker daemon | ||
- name: Load Docker image | ||
run: | | ||
docker compose up --build --abort-on-container-exit --exit-code-from bmstu | ||
docker load -i ./artifacts/cpp_course_image.tar | ||
# 3. Create a Docker network (optional, if needed) | ||
#- name: Create Docker network | ||
# run: docker network create my-network || echo "Network already exists" | ||
|
||
# 4. Run the Docker container and execute the script | ||
- name: Run run.sh Script inside Docker Container | ||
run: | | ||
docker run --rm -v ${{ github.workspace }}:/cppcourse bmstu_cpp_course-bmstu:latest bash -c "/cppcourse/docker/runtasks/run.sh" | ||
# 5. (Optional) Bring down any Docker Compose services if previously started | ||
#- name: Tear Down Docker Compose (if applicable) | ||
# run: docker compose down |
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
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,8 @@ | ||
#include <assert.h> | ||
#include "int2str.h" | ||
#include "stdio.h" | ||
|
||
char* int2str(int number) { | ||
char* str = "0"; | ||
return str; | ||
} |
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,15 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
char* int2str(int number); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
|
||
|
||
|
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,22 @@ | ||
#include <gtest/gtest.h> | ||
#include "int2str.h" | ||
|
||
TEST(int2str, BasicTest) { | ||
EXPECT_STREQ(int2str(0), "0"); | ||
} | ||
|
||
TEST(int2str, BasicTestZero) { | ||
EXPECT_STREQ(int2str(0), "0"); | ||
} | ||
|
||
TEST(int2str, BasicTestZeroNext) { | ||
EXPECT_STREQ(int2str(-0), "0"); | ||
} | ||
|
||
TEST(int2str, BasicTestNumbers) { | ||
EXPECT_STREQ(int2str(-5), "-5"); | ||
EXPECT_STREQ(int2str(-66), "-66"); | ||
EXPECT_STREQ(int2str(-123), "-123"); | ||
EXPECT_STREQ(int2str(2147483647), "2147483647"); | ||
EXPECT_STREQ(int2str(-2147483648), "-2147483648"); | ||
} |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#include <gtest/gtest.h> | ||
#include "str2int.h" | ||
|
||
|
||
TEST(str2int, BasicTest) { | ||
EXPECT_EQ(str2int("0"), 0); | ||
} | ||
|