Skip to content

Commit

Permalink
Merge pull request #7 from Gobi-Kumarasamy/homework4
Browse files Browse the repository at this point in the history
Homework4
  • Loading branch information
Gobi-Kumarasamy authored Jan 14, 2023
2 parents eee4550 + 6bdfef2 commit 5f7abef
Show file tree
Hide file tree
Showing 17 changed files with 595 additions and 165 deletions.
170 changes: 5 additions & 165 deletions .github/workflows/check-homework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,168 +3,8 @@ name: CI
on: [pull_request]

jobs:
add_progress_bar_comment:
runs-on: ubuntu-latest
steps:
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: With ❤️ from Homework Bot 🤖
- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Tests are running! Please wait!
![Progress gif](https://cdn.dribbble.com/users/2015153/screenshots/6592242/progess-bar2.gif)
> Progress gif from https://dribbble.com/shots/6592242-Please-wait-Animation#
With ❤️ from Homework Bot 🤖
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
## Tests are running! Please wait!
![Progress gif](https://cdn.dribbble.com/users/2015153/screenshots/6592242/progess-bar2.gif)
> Progress gif from https://dribbble.com/shots/6592242-Please-wait-Animation#
With ❤️ from Homework Bot 🤖
check_homework:
runs-on: ubuntu-latest
steps:
- name: Checkout this homework
uses: actions/checkout@v2
with:
path: homework
- name: Checkout homework definitions
uses: actions/checkout@v2
with:
repository: cpp-for-yourself/homework-definitions
path: definitions
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
architecture: 'x64'
- name: Install prerequisites
run: |
sudo apt install -y libgtest-dev
python -m pip install --upgrade pip pipenv ruamel.yaml schema homework-checker
- name: Run tests
run: |
mkdir checker
cp definitions/homework.yml checker/
cp -r homework/homeworks checker/
cd checker
check_homework -v -i homework.yml -o results.md
- name: Upload result md file
uses: actions/upload-artifact@v2
with:
name: homework_result
path: checker/results.md

upload_results_as_comment:
needs: check_homework
runs-on: ubuntu-latest
steps:
- name: Download result md file
uses: actions/download-artifact@v2
with:
name: homework_result
- name: Render template
id: template
uses: chuhlomin/[email protected]
with:
template: results.md
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: With ❤️ from Homework Bot 🤖
- name: Update comment with test results
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.template.outputs.result }}
edit-mode: replace

upload_results_to_wiki:
needs: check_homework
runs-on: ubuntu-latest
steps:
- name: Download result md file
uses: actions/download-artifact@v2
with:
name: homework_result
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: With 💙 from Homework Bot 🤖
- name: Checkout wiki
uses: actions/checkout@v2
with:
repository: ${{ github.repository }}.wiki
path: wiki
- name: Upload result to wiki
run: |
echo \`\`\` > wiki/Home.md
echo Author: ${{ github.actor }} >> wiki/Home.md
echo Branch: ${{ github.head_ref }} >> wiki/Home.md
echo Commit: ${{ github.sha }} >> wiki/Home.md
echo \`\`\` >> wiki/Home.md
cat results.md >> wiki/Home.md
cd wiki
git config user.name homework-bot
git config user.email [email protected]
git add .
git commit -m "Update results" --allow-empty
git push
- name: Comment on wiki access failure
uses: peter-evans/create-or-update-comment@v1
if: failure()
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
# ‼️ Wiki is empty ‼️
To fix this error you will have to perform the following actions once:
1. Create _any_ (even empty) page in the wiki by clicking this link: ${{ github.server_url }}/${{ github.repository }}/wiki/_new
2. Rerun the actions by clicking the <kbd>🔄 Re-run all jobs</kbd> button here: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
---
With 💙 from Homework Bot 🤖
edit-mode: replace
- name: Comment on wiki access success
uses: peter-evans/create-or-update-comment@v1
if: success()
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
# ✅ Wiki is available
Check it out at: ${{ github.server_url }}/${{ github.repository }}/wiki
With 💙 from Homework Bot 🤖
edit-mode: replace
run_all_tests:
name: Run all tests
uses: cpp-for-yourself/ci-jobs/.github/workflows/check-homework.yml@main
with:
homework-definitions-branch: main
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "homeworks/homework_4/no_strings_attached/external/googletest"]
path = homeworks/homework_4/no_strings_attached/external/googletest
url = https://github.com/google/googletest.git
29 changes: 29 additions & 0 deletions homeworks/homework_4/no_strings_attached/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.16..3.24)
project(no_strings_attached VERSION 1
DESCRIPTION "Writing a string processing library"
LANGUAGES CXX)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
endif()

message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

add_library(cxx_setup INTERFACE)
target_compile_options(cxx_setup INTERFACE -Wall -Wpedantic -Wextra)
target_compile_features(cxx_setup INTERFACE cxx_std_17)
target_include_directories(cxx_setup INTERFACE ${PROJECT_SOURCE_DIR})

# Update the submodules here
include(external/UpdateSubmodules.cmake)

# Enable testing for this project
include(CTest)

# 🚨 Make sure CMakeLists.txt file exists in the subdirectories!
add_subdirectory(examples)
add_subdirectory(external)
add_subdirectory(${PROJECT_NAME})



22 changes: 22 additions & 0 deletions homeworks/homework_4/no_strings_attached/compile_run_bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
echo " ******** Current working directory ******** "
pwd
echo " -------- -------- -------- -------- -------- -------- -------- -------- -------- --------"

echo " ******** BUILD directory ******** "
rm -r build
mkdir build
echo " -------- -------- -------- -------- -------- -------- -------- -------- -------- --------"

echo " ******** CMAKE ******** "
cmake -S . -B build
cmake --build build
echo " -------- -------- -------- -------- -------- -------- -------- -------- -------- --------"

echo " ******** Google Test ********"
GTEST_COLOR=1 ctest --test-dir build --output-on-failure
#GTEST_COLOR=1 ctest --test-dir build --verbose
echo " -------- -------- -------- -------- -------- -------- -------- -------- -------- --------"

#echo " ******** Run Binary ********"
#./build/examples/split_strings
echo " -------- -------- -------- -------- -------- -------- -------- -------- -------- --------"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(split_strings split_strings.cpp)
target_link_libraries(split_strings PRIVATE cxx_setup string_split)

add_executable(trim_strings trim_strings.cpp)
target_link_libraries(trim_strings PRIVATE cxx_setup string_trim)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <no_strings_attached/string_split.h>
#include <iostream>
#include <string>
#include <vector>

int main(){

std::string string_to_be_splitted;
std::string delimiter = " ";
int number_of_chunks_to_keep = 2;

std::cout << "Example program that splits strings."<<std::endl;
std::cout << "Please enter a string:"<<std::endl;
std::getline(std::cin, string_to_be_splitted);

std::vector<std::string> Splitted_string = no_strings_attached::Split(string_to_be_splitted,delimiter);
std::cout << "Your split string: ";
for(auto index1:Splitted_string) {
std::cout <<"'"<< index1 <<"'"<<' ';
}

std::cout <<std::endl;

// std::vector<std::string> Splitted_string2 = no_strings_attached::Split(string_to_be_splitted,delimiter,number_of_chunks_to_keep);
// std::cout << "Your split string2: ";
// for(auto index2:Splitted_string2) {
// std::cout <<"'"<< index2 <<"'"<<' ';
// }

// std::cout <<std::endl;

return 0;
}
28 changes: 28 additions & 0 deletions homeworks/homework_4/no_strings_attached/examples/trim_strings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <no_strings_attached/string_trim.h>
#include <iostream>
#include <string>
#include <vector>

using no_strings_attached::Side;

int main(){

std::string string_to_be_trimmed;
char char_to_trim =' ';

std::cout << "Example program that trims strings."<<std::endl;
std::cout << "Please enter a string:"<<std::endl;
std::getline(std::cin, string_to_be_trimmed);

// std::string Trimmed_string = no_strings_attached::Trim(string_to_be_trimmed,char_to_trim,Side::kLeft);
// std::cout << "Your trimmed string: ";
// std::cout <<"'"<< Trimmed_string <<"'";
// std::cout <<std::endl;

std::string Trimmed_string = no_strings_attached::Trim(string_to_be_trimmed);
std::cout << "Your trimmed string: ";
std::cout <<"'"<< Trimmed_string <<"'";
std::cout <<std::endl;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(googletest)

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
find_package(Git QUIET)

if(GIT_FOUND)

option(UPDATE_SUBMODULES "Check submodules during build" ON)

if(NOT UPDATE_SUBMODULES)
return()
endif()

execute_process(COMMAND ${GIT_EXECUTABLE} submodule
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE EXISTING_SUBMODULES
RESULT_VARIABLE RETURN_CODE)

message(STATUS "Updating git submodules:\n${EXISTING_SUBMODULES}")

execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE RETURN_CODE)

if(NOT RETURN_CODE EQUAL "0")
message(WARNING "Cannot update submodules. Git command failed with ${RETURN_CODE}.")
return()
endif()

message(STATUS "Git submodules updated successfully.")

endif()
Submodule googletest added at 356fc3
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
add_library(string_split string_split.cpp)
target_link_libraries(string_split PUBLIC cxx_setup)

add_library(string_trim string_trim.cpp)
target_link_libraries(string_trim PUBLIC cxx_setup)

# BUILD_TESTING variable is created by include(CTest)
# It is set to ON by default
if(BUILD_TESTING)
add_executable(string_split_test string_split_test.cpp)
target_link_libraries(string_split_test PRIVATE GTest::gtest_main)
target_link_libraries(string_split_test PRIVATE string_split)

add_executable(string_trim_test string_trim_test.cpp)
target_link_libraries(string_trim_test PRIVATE GTest::gtest_main)
target_link_libraries(string_trim_test PRIVATE string_trim)

include(GoogleTest)
# Finds all the Google tests associated with the executable
gtest_discover_tests(string_split_test)
gtest_discover_tests(string_trim_test)
endif()
Loading

0 comments on commit 5f7abef

Please sign in to comment.