-
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.
Обновлено# Please enter the commit message for your changes. Lines st…
…arting
- Loading branch information
1 parent
8201ba0
commit c1bd6c8
Showing
10 changed files
with
150 additions
and
40 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,97 @@ on: | |
|
||
jobs: | ||
build: | ||
name: Build Docker Image | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run docker-compose | ||
uses: hoverkraft-tech/[email protected] | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- 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- | ||
- 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 | ||
- name: Upload Docker image tarball | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: cpp_course-image | ||
path: cpp_course_image.tar | ||
|
||
- name: Save Docker layer cache | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: docker-layer-cache | ||
path: /tmp/.buildx-cache | ||
|
||
test: | ||
name: Build and Test Inside Docker Container (Сборка и тестирование внутри контейнера Docker) | ||
needs: build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Download Docker image tarball (Загрузка tarball образа Docker) | ||
uses: actions/download-artifact@v3 | ||
with: | ||
compose-file: "docker-compose.yml" | ||
name: cpp_course-image | ||
path: . | ||
|
||
- name: Load Docker image (Загрузка образа Docker) | ||
run: docker load -i cpp_course_image.tar | ||
|
||
- name: | ||
- name: Checkout repository (Клонирование репозитория) | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run Build and Tests Inside Container (Запуск сборки и тестов внутри контейнера) | ||
run: | | ||
docker compose up --build --abort-on-container-exit --exit-code-from bmstu | ||
# Run a container from the loaded image in detached mode | ||
docker run -d --name cpp_course_container bmstu_cpp_course-bmstu:latest tail -f /dev/null | ||
# Install dependencies inside the container if necessary | ||
# Example: | ||
# docker exec cpp_course_container apt-get update | ||
# docker exec cpp_course_container apt-get install -y your-dependencies | ||
# Copy the repository code into the container | ||
docker cp . cpp_course_container:/workspace | ||
# Execute build steps inside the container | ||
docker exec cpp_course_container bash -c " | ||
cd /workspace | ||
mkdir -p build | ||
cd build | ||
cmake .. | ||
cmake --build . | ||
cd .. | ||
bash docker/run_tasks/run.sh | ||
" | ||
# Optionally, retrieve test results | ||
docker cp cpp_course_container:/workspace/build/test-results ./test-results | ||
# Stop and remove the container | ||
docker stop cpp_course_container | ||
docker rm cpp_course_container | ||
# - name: Upload test results (Загрузка результатов тестов) | ||
# if: failure() || always() | ||
# uses: actions/upload-artifact@v3 | ||
# with: | ||
# name: test_results_xml | ||
# path: ./test-results/**/*.xml |
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
message(STATUS "Running tasks/basic_c/CMakeLists.txt") | ||
set(CMAKE_CXX_STANDARD 26) | ||
set(CMAKE_CXX_STANDARD 23) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
get_filename_component(NAME_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR} NAME) | ||
#glob all path to folder in task_* an | ||
|
||
#save all folders in tasks with prefix task_ to array | ||
file(GLOB TASKS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/task_*) | ||
#find all files in folder with name *.c and *.h and *.cpp *.hpp and add them to the project | ||
|
||
foreach(TASK ${TASKS}) | ||
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/${TASK} ${CMAKE_CURRENT_SOURCE_DIR}/${TASK}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/${TASK}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/${TASK}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${TASK}/*.hpp) | ||
endforeach () | ||
message(STATUS "TASKS: ${TASKS}") | ||
message(STATUS "FIND IN: " ${TASK}) | ||
file(GLOB FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_SOURCE_DIR}/${TASK}/*.[ch]pp | ||
${CMAKE_CURRENT_SOURCE_DIR}/${TASK}/*.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/${TASK}/*.c) | ||
list(APPEND SOURCES ${FILES}) | ||
endforeach() | ||
message(STATUS "SOURCES: ${SOURCES}") | ||
add_executable(${NAME_EXECUTABLE} ${SOURCES}) | ||
target_link_libraries( | ||
${NAME_EXECUTABLE} | ||
GTest::gtest_main | ||
) | ||
) |
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); | ||
} | ||
|