Skip to content

Commit

Permalink
Github Action Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Suraj-Yadav committed Jul 9, 2024
1 parent 10a178f commit bd180b4
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 85 deletions.
46 changes: 14 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- '!master'
tags:
- '**' # matches every tag
defaults:
run:
shell: bash
jobs:
build-windows:
env:
Expand All @@ -16,58 +19,37 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/github-script@v6
- uses: './.github/workflows/setup'
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Setup OpenCppCoverage and add to PATH
id: setup_opencppcoverage
run: |
choco install OpenCppCoverage -y
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
- name: cmake configure
run: |
$env:CMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake"
cmake -B build -S .
- name: cmake test
run: cmake --build build --target coverage
- name: cmake build
run: cmake --build build --target package --config Release
- uses: actions/upload-artifact@v3
if: startsWith(github.ref, 'refs/tags/v')
with:
name: windows-zip
path: build/comic_reader-*.zip
zip-output: windows-zip
build-linux:
env:
VCPKG_DEFAULT_TRIPLET: x64-linux
VCPKG_BINARY_SOURCES: clear;x-gha,readwrite
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Install wxWidgets
run: sudo apt update && sudo apt install -y x11-xserver-utils libxi-dev libxtst-dev python3-jinja2 libxrandr-dev
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/github-script@v6
- uses: './.github/workflows/setup'
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: cmake configure
run: |
CMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake cmake -B build -S .
- name: cmake build
run: cmake --build build --target package --config Release
zip-output: linux-zip

create-release:
if: startsWith(github.ref, 'refs/tags/v')
needs:
- build-windows
- build-linux
runs-on: macos-latest
steps:
- uses: actions/download-artifact@v3
with:
name: windows-zip
- uses: actions/download-artifact@v3
with:
name: linux-zip
- run: ls
- uses: marvinpinto/action-automatic-releases@latest
with:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Build'
inputs:
zip-output:
required: true
runs:
using: "composite"
steps:
- uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: cmake configure
shell: bash
run: |
export CMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake
cmake -B build -S . || cat build/vcpkg_installed/vcpkg/issue_body.md
- name: cmake build
shell: bash
run: cmake --build build --target package --config Release
- uses: actions/upload-artifact@v3
if: startsWith(github.ref, 'refs/tags/v')
with:
name: ${{ inputs.zip-output }}
path: build/comic_reader-*.zip
109 changes: 58 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,87 @@ parse_git_tag()
project(comic_reader LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE INTERNAL "")

find_package(LibArchive REQUIRED)
find_package(Tweeny CONFIG REQUIRED)
find_package(WebP CONFIG REQUIRED)
find_package(wxWidgets CONFIG REQUIRED)

add_library(common_lib STATIC
src/archive.cpp
src/comic_gallery.cpp
src/comic_viewer.cpp
src/comic.cpp
src/fuzzy.cpp
src/image_utils.cpp
src/viewport.cpp
src/wxUtil.cpp
)
target_link_libraries(common_lib PUBLIC
LibArchive::LibArchive
tweeny
WebP::webp
wx::core
)
add_library(
common_lib STATIC
src/archive.cpp
src/comic_gallery.cpp
src/comic_viewer.cpp
src/comic.cpp
src/fuzzy.cpp
src/image_utils.cpp
src/viewport.cpp
src/wxUtil.cpp)

target_link_libraries(common_lib PUBLIC LibArchive::LibArchive tweeny
WebP::webp wx::core)

target_include_directories(common_lib PUBLIC "${CMAKE_SOURCE_DIR}/include")

add_executable(comic_reader WIN32 src/main.cpp)
target_link_libraries(comic_reader PRIVATE common_lib)

if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
target_sources(comic_reader PRIVATE resource/main.rc resource/main.manifest)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
target_sources(comic_reader PRIVATE resource/main.rc resource/main.manifest)
endif()

if(MSVC)
set(CPACK_GENERATOR "ZIP")
install(TARGETS comic_reader
RUNTIME_DEPENDENCIES
PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-" "hvsifiletrust" "pdmutilities"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
RUNTIME DESTINATION .
)
set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
include(CPack)
endif()
set(CPACK_GENERATOR "ZIP")
install(
TARGETS comic_reader
RUNTIME_DEPENDENCIES
PRE_EXCLUDE_REGEXES
"api-ms-"
"ext-ms-"
"hvsifiletrust"
"pdmutilities"
POST_EXCLUDE_REGEXES
".*system32/.*\\.dll"
RUNTIME DESTINATION .)
set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
include(CPack)

# Setup Test, coverage and benchmarks
find_package(benchmark CONFIG REQUIRED)
find_package(GTest CONFIG REQUIRED)

SET(TEST_SRCS
src/archive_test.cpp
src/comic_test.cpp
src/fuzzy_test.cpp
src/lru_test.cpp
)
set(TEST_SRCS src/archive_test.cpp src/comic_test.cpp src/fuzzy_test.cpp
src/lru_test.cpp)

add_executable(tests ${TEST_SRCS})
target_link_libraries(tests PRIVATE
common_lib GTest::gtest benchmark::benchmark GTest::gtest_main)
target_link_libraries(tests PRIVATE common_lib GTest::gtest
benchmark::benchmark GTest::gtest_main)

add_executable(benchmarks ${TEST_SRCS})
target_link_libraries(benchmarks PRIVATE
common_lib GTest::gtest benchmark::benchmark benchmark::benchmark_main)
target_link_libraries(
benchmarks PRIVATE common_lib GTest::gtest benchmark::benchmark
benchmark::benchmark_main)

if(MSVC)
add_custom_target(
coverage
OpenCppCoverage
-q --export_type cobertura:${CMAKE_BINARY_DIR}/cov.xml
--sources $<SHELL_PATH:${CMAKE_SOURCE_DIR}/src>
--sources $<SHELL_PATH:${CMAKE_SOURCE_DIR}/include>
--modules $<SHELL_PATH:${CMAKE_BINARY_DIR}>
--cover_children -- $<TARGET_FILE:tests> --gtest_output=xml:${CMAKE_BINARY_DIR}/test.xml
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS tests
)
add_custom_target(
coverage
OpenCppCoverage
-q
--export_type
cobertura:${CMAKE_BINARY_DIR}/cov.xml
--sources
$<SHELL_PATH:${CMAKE_SOURCE_DIR}/src>
--sources
$<SHELL_PATH:${CMAKE_SOURCE_DIR}/include>
--modules
$<SHELL_PATH:${CMAKE_BINARY_DIR}>
--cover_children
--
$<TARGET_FILE:tests>
--gtest_output=xml:${CMAKE_BINARY_DIR}/test.xml
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS tests)
endif()
1 change: 1 addition & 0 deletions include/comic_viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ComicViewer : public wxPanel {
void OnLeftUp(wxMouseEvent&);
void OnSize(wxSizeEvent&);
void OnCaptureLost(wxMouseCaptureLostEvent&);
void OnClose(wxCloseEvent&);

void StartPan(const wxPoint2DDouble&, PanSource);
void ProcessPan(const wxPoint2DDouble&, bool, PanSource);
Expand Down
1 change: 1 addition & 0 deletions include/image_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ class ImagePool {
const wxSize size(int index);
const wxBitmap& bitmap(int index);
auto empty() const { return paths.empty() || bitmaps.empty(); }
void clear();
};
2 changes: 1 addition & 1 deletion src/comic_gallery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ComicGallery::ComicGallery(
GALLERY_UPDATE_ID);

SetBackgroundStyle(wxBG_STYLE_PAINT);
SetBackgroundColour(wxColour(25, 25, 25, 1));
SetBackgroundColour(wxColour(25, 25, 25));

loadComics(paths);
}
Expand Down
8 changes: 7 additions & 1 deletion src/comic_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ ComicViewer::ComicViewer(wxWindow* parent, Comic& comic)
Bind(wxEVT_LEFT_DOWN, &ComicViewer::OnLeftDown, this);
Bind(wxEVT_LEFT_DCLICK, &ComicViewer::OnLeftDClick, this);
Bind(wxEVT_SIZE, &ComicViewer::OnSize, this);
Bind(wxEVT_CLOSE_WINDOW, &ComicViewer::OnClose, this);
SetBackgroundStyle(wxBG_STYLE_PAINT);
SetBackgroundColour(wxColour(25, 25, 25, 1));
SetBackgroundColour(wxColour(25, 25, 25));
}

void ComicViewer::load() {
Expand All @@ -26,6 +27,11 @@ void ComicViewer::load() {
for (auto& page : comic.pages) { pool.addImage(page); }
}

void ComicViewer::OnClose(wxCloseEvent& event) {
comic.unload();
pool.clear();
}

bool ComicViewer::verify(const wxGraphicsContext* gc, int i) {
if (i < 0 || i >= comic.length()) { return false; }
return true;
Expand Down
7 changes: 7 additions & 0 deletions src/image_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ const wxBitmap& ImagePool::bitmap(int index) {
load(index);
return bitmaps[index];
}

void ImagePool::clear() {
int size = static_cast<int>(bitmaps.size());
for (int i = 0; i < size; i++) { unload(i); }
paths.clear();
bitmaps.clear();
}

0 comments on commit bd180b4

Please sign in to comment.