Skip to content

Commit

Permalink
Обновлено# Please enter the commit message for your changes. Lines st…
Browse files Browse the repository at this point in the history
…arting
  • Loading branch information
vanya-beat committed Oct 12, 2024
1 parent 8201ba0 commit c1bd6c8
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 40 deletions.
95 changes: 88 additions & 7 deletions .github/workflows/ci-cpp-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: C++ Build (Сборка проекта)
name: C++ Build and Run (Сборка и запуск проекта)

on:
push:
Expand All @@ -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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.30)
cmake_minimum_required(VERSION 3.28)
project(bmstu_cpp_course)

include(FetchContent)
Expand All @@ -12,4 +12,4 @@ FetchContent_MakeAvailable(googletest)
enable_testing()
include(GoogleTest)

add_subdirectory(tasks)
add_subdirectory(tasks)
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ services:
volumes:
- .:/cpp_bmstu
working_dir: /cpp_bmstu
command: ["/bin/bash", "-c", "cmake -B build -S . && cmake --build build && /cpp_bmstu/docker/run_tasks/run.sh"]
command: ["/bin/bash", "-c", "cmake -B build -S . && cmake --build build"]
container_name: cpp_course
4 changes: 1 addition & 3 deletions docker/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ubuntu:22.04

COPY docker/image/install_deps.sh /
RUN sh install_deps.sh

#COPY . /cpp_course
ENV TZ=Europe/Moscow

ENV LANG C.UTF-8
Expand All @@ -16,5 +16,3 @@ EXPOSE 22
RUN echo "StrictHostKeyChecking=no" >> /etc/ssh/ssh_config
RUN mkdir /var/run/sshd
CMD ["/usr/sbin/sshd", "-D"]


19 changes: 12 additions & 7 deletions tasks/task_basic_c/CMakeLists.txt
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
)
)
8 changes: 8 additions & 0 deletions tasks/task_basic_c/task_int2str/int2str.c
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;
}
15 changes: 15 additions & 0 deletions tasks/task_basic_c/task_int2str/int2str.h
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




22 changes: 22 additions & 0 deletions tasks/task_basic_c/task_int2str/int2str_tests.cpp
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");
}
20 changes: 1 addition & 19 deletions tasks/task_basic_c/task_str2int/str2int.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,5 @@
#include "stdio.h"

int str2int(const char *str) {
int znak = 1;
int result = 0;

if (*str == '-'){
znak = -1;
str++;
} else if (*str == '+') {
str++;
}

int count = 0;
while (*str != '\0') {
result = result * 10 + (*str - '0');
count += 1;
str++;
assert(znak == -1 && result == -2147483648 || znak == -1 && result >= 0 && count <= 9 || znak == 1 && result >= 0);
}
assert(count > 0);
return result * znak;
return 0;
}
1 change: 0 additions & 1 deletion tasks/task_basic_c/task_str2int/str2int_tests.cpp
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);
}
Expand Down

0 comments on commit c1bd6c8

Please sign in to comment.