Skip to content

Commit

Permalink
Merge branch 'main' into hw3
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarfovich committed Aug 4, 2024
2 parents 563f54d + 83a019f commit da36200
Show file tree
Hide file tree
Showing 24 changed files with 4,129 additions and 244 deletions.
59 changes: 42 additions & 17 deletions .github/workflows/HW2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,66 @@ permissions:

jobs:
build-and-run-job:
env:
target_name: ip_filter
homework_label: HW2
cmake_preset: linux-release
cmake_build_preset: linux-build-release
hw_path: ./HW2
build_folder: build
release_folder: linux-release
version_base: '1.0'
build_tests: ${{ true }}
# Variables to populate in "Initialize variables" step
build_path:
bin_path:
deb_path:
tests_path:
version:

runs-on: ubuntu-latest
steps:
- name: Initialize variables
run: |
echo "build_path=${{ env.hw_path }}/${{ env.build_folder }}" >> $GITHUB_ENV
echo "bin_path=${{ env.hw_path }}/${{ env.build_folder }}/${{ env.release_folder }}/bin" >> $GITHUB_ENV
echo "deb_path=${{ env.hw_path }}/${{ env.build_folder }}/${{ env.release_folder }}/deb" >> $GITHUB_ENV
echo "tests_path=${{ env.hw_path }}/${{ env.build_folder }}/${{ env.release_folder }}/tests" >> $GITHUB_ENV
echo "version=${{ env.version_base }}.${{ github.run_number }}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Update apt-get
run: sudo apt-get update
- name: Build ip_filter
working-directory: HW2
working-directory: ${{env.hw_path}}
run: |
cmake -DBuildTests=On --preset linux-release
cmake --build --preset linux-build-release
cmake -DBuildTests=${{ env.build_tests }} -DPROJECT_VERSION=${{ env.version }} --preset ${{ env.cmake_preset }}
cmake --build --preset ${{ env.cmake_build_preset }}
- name: Run tests
working-directory: HW2/build/linux-release/bin/
run: ./ip_read_operator_test
if: ${{ env.build_tests }}
working-directory: ${{ env.tests_path }}
run: ctest .
- name: Check tests results
if: '!success()'
if: ${{ env.build_tests && !success()}}
run: |
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build package
working-directory: HW2/build/linux-release
run: cpack -B deb
working-directory: ${{env.build_path}}/${{env.release_folder}}
run: cpack -G DEB
- name: Run ip_filter
working-directory: HW2
run: '[[ $(cat ip_filter.tsv | ./build/linux-release/bin/ip_filter | md5sum) == "24e7a7b2270daee89c64d3ca5fb3da1a -" ]] && echo "MD5 are equal"'
- name: Create release
run: '[[ $(cat ${{env.hw_path}}/ip_filter.tsv | ${{ env.bin_path }}/${{ env.target_name }} | md5sum) == "24e7a7b2270daee89c64d3ca5fb3da1a -" ]] && echo "MD5 are equal"'
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.run_number }}
release_name: Release ${{ github.run_number }}
tag_name: ${{ env.homework_label }}_${{ github.run_number }}
release_name: ${{ env.homework_label }} release ${{ github.run_number }}
draft: false
prerelease: false
- name: Upload package
Expand All @@ -57,8 +82,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: HW2/build/linux-release/deb/ip_filter-1.0.0-Linux.deb
asset_name: ip_filter-1.0.0-Linux.deb
asset_path: ${{ env.deb_path }}/${{ env.target_name }}-${{ env.version }}-Linux.deb
asset_name: ${{ env.target_name }}-${{ env.version }}-Linux.deb
asset_content_type: application/vnd.debian.binary-package
- name: Upload packet
id: upload-app-asset
Expand All @@ -67,6 +92,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: HW2/build/linux-release/bin/ip_filter
asset_name: ip_filter
asset_path: ${{ env.bin_path }}/${{ env.target_name }}
asset_name: ${{ env.target_name }}
asset_content_type: application/octet-stream
138 changes: 138 additions & 0 deletions .github/workflows/HW4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: 'HW4 action'

on:
workflow_dispatch:
push:
paths:
- 'HW4/**'
- '.github/workflows/HW4.yml'

permissions:
actions: write
contents: write

jobs:
build-and-run-job:
env:
target_name: print_ip
homework_label: HW4
cmake_preset: linux-release
cmake_build_preset: linux-build-release
hw_path: ./HW4
build_folder: build
release_folder: linux-release
version_base: '1.0'
build_tests: ${{ false }}
# Variables to populate in "Initialize variables" step
build_path:
bin_path:
deb_path:
version:

runs-on: ubuntu-latest
steps:
- name: Initialize variables
run: |
echo "build_path=${{ env.hw_path }}/${{ env.build_folder }}/${{ env.release_folder }}" >> $GITHUB_ENV
echo "bin_path=${{ env.hw_path }}/${{ env.build_folder }}/${{ env.release_folder }}/bin" >> $GITHUB_ENV
echo "deb_path=${{ env.hw_path }}/${{ env.build_folder }}/${{ env.release_folder }}/deb" >> $GITHUB_ENV
echo "version=${{ env.version_base }}.${{ github.run_number }}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4

#- name: Update apt-get
# run: sudo apt-get update

- name: Build package ${{ env.target_name }}
working-directory: ${{env.hw_path}}
run: |
cmake -DBuildTests=${{ env.build_tests }} -DPROJECT_VERSION=${{ env.version }} --preset ${{ env.cmake_preset }}
cmake --build --preset ${{ env.cmake_build_preset }}
- name: Run tests
if: ${{ env.build_tests }}
working-directory: ${{ env.build_path }}
run: ctest --test-dir .

- name: Check tests results
if: ${{ env.build_tests && !success()}}
run: |
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run packet ${{ env.target_name }}
run: '${{ env.bin_path }}/${{ env.target_name }}'

- name: Build package
working-directory: ${{env.build_path}}
run: cpack -G DEB

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.homework_label }}_${{ github.run_number }}
release_name: ${{ env.homework_label }} release ${{ github.run_number }}
draft: false
prerelease: false

- name: Upload packet
id: upload-app-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.bin_path }}/${{ env.target_name }}
asset_name: ${{ env.target_name }}
asset_content_type: application/octet-stream

- name: Upload package
id: upload-package-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.deb_path }}/${{ env.target_name }}-${{ env.version }}-Linux.deb
asset_name: ${{ env.target_name }}-${{ env.version }}-Linux.deb
asset_content_type: application/vnd.debian.binary-package

- name: Create Doxygen
uses: mattnotmitt/[email protected]
with:
doxyfile-path: ./Doxyfile
working-directory: ${{ env.hw_path }}

- name: GitHub Pages Deployment
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc/html/
enable_jekyll: false
allow_empty_commit: false
force_orphan: true
publish_branch: gh-pages

# Build the HTML documentation
- name: Doxygen Action
uses: mattnotmitt/[email protected]
with:
doxyfile-path: ${{ env.hw_path }}/Doxyfile
working-directory: .

# Deploy the HTML documentation to GitHub Pages
- name: GH Pages Deployment
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{ env.hw_path }}/doc/html/
enable_jekyll: false
allow_empty_commit: false
force_orphan: true
publish_branch: gh-pages
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#Submodules
Submodules/

.vscode
# Build results
[Bb]uild*/
[Dd]ebug/
Expand All @@ -27,6 +28,7 @@ bld/
[Oo]bj/
[Ll]og/
Output/
[Tt]esting/

# Vcpkg
vcpkg_installed/
Expand Down
34 changes: 7 additions & 27 deletions HW2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
cmake_minimum_required (VERSION 3.12)

option(BUILD_TESTS "BuildTests" OFF)
option(BUILD_TESTS "BuildTests" ON)
set(PROJECT_VERSION "0.0.3" CACHE INTERNAL "Version")
project (ip_filter_project VERSION ${PROJECT_VERSION})

project ("ip_filter")
add_executable (ip_filter "src/main.cpp" "src/ip.cpp" "include/ip.h")
include_directories("include")

set_property(TARGET ip_filter PROPERTY CXX_STANDARD 20)

# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

set_target_properties(ip_filter
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

# deb-package.
set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_NAME "ip_filter")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_PACKAGE_CONTACT [email protected])
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/deb")
include(CPack)

# Tests.
if(BuildTests)
add_subdirectory(ip_filter)
add_subdirectory(ip_lib)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
36 changes: 0 additions & 36 deletions HW2/include/ip.h

This file was deleted.

19 changes: 19 additions & 0 deletions HW2/ip_filter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
add_executable(ip_filter main.cpp)
target_link_libraries(ip_filter PUBLIC ip)

set_target_properties(ip_filter
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

# deb-package.
set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_NAME "ip_filter")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_PACKAGE_CONTACT [email protected])
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/deb")
include(CPack)
31 changes: 31 additions & 0 deletions HW2/ip_filter/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <sstream>
#include <fstream>
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <limits>

#include "ip_lib/ip.h"

int main(int argc, char* argv[])
{
std::istream& stream = std::cin;
std::ostream& outStream = std::cout;

auto [ips, success] = ip::readIps(stream);
if (!success) {
std::cerr << "Couldn't parse some IPs. Quiting." << std::endl;
return 1;
}

std::sort(ips.begin(), ips.end(), std::greater());
for (const auto& ip : ips) {
outStream << ip << '\n';
}
ip::filterPart0Is1(ips.begin(), ips.end(), std::cout);
ip::filterPart0Is46AndPart1Is70(ips.begin(), ips.end(), std::cout);
ip::filterAnyPartIs46(ips.begin(), ips.end(), std::cout);

return 0;
}
Loading

0 comments on commit da36200

Please sign in to comment.