Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Darwin CI/CD Github Actions #128

Merged
merged 4 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/scripts/write_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

content = """
[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.cppstd=gnu20
compiler.libcxx=libc++
compiler.version=17
os=Macos
"""

filepath = os.path.expanduser("~/.conan2/profiles/default")

f = open(filepath, "w")
f.write(content)
f.close()
74 changes: 72 additions & 2 deletions .github/workflows/exchange-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,77 @@ jobs:
UBSAN_OPTIONS: print_stacktrace=1
run: ctest --output-on-failure --no-tests=error -j 2 -R "Unit*"

unit-test:
unit-test-darwin:
needs: [lint]

strategy:
matrix:
os: [macos-14]

runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: exchange


env:
CC: /opt/homebrew/opt/llvm/bin/clang
CXX: /opt/homebrew/opt/llvm/bin/clang++
CLANG_DIR: '/opt/homebrew/opt/llvm/bin/clang'
LLVM_DIR: '/opt/homebrew/opt/llvm'

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install LLVM 17
run: |
brew install llvm@17
brew install clang-format

- name: Install static analyzers
if: matrix.os == 'macos-14'
run: >-
brew install cppcheck

- name: Install Python
uses: actions/setup-python@v4
with: { python-version: "3.12" }

- name: Install Python
uses: actions/setup-python@v4
with: { python-version: "3.12-dev" }

- name: Install dependencies
shell: bash
run: |
pip3 install conan
conan profile detect
python3 ../.github/scripts/write_config.py
conan install . -s build_type=Release -b missing

- name: Setup MultiToolTask
if: matrix.os == 'windows-2022'
run: |
Add-Content "$env:GITHUB_ENV" 'UseMultiToolTask=true'
Add-Content "$env:GITHUB_ENV" 'EnforceProcessCountAcrossBuilds=true'

- name: Configure
shell: pwsh
run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])"

- name: Build
run: cmake --build build --config Release -j

- name: Install
run: cmake --install build --config Release --prefix prefix

- name: Test
working-directory: exchange/build
run: ctest --output-on-failure --no-tests=error -C Release -j 2 -R "Unit*"

unit-test-linux:
needs: [lint]

strategy:
Expand Down Expand Up @@ -325,7 +395,7 @@ jobs:

docs:
# Deploy docs only when builds succeed
needs: [sanitize, unit-test, integration-test]
needs: [sanitize, unit-test-darwin, unit-test-linux, integration-test]

runs-on: ubuntu-22.04
defaults:
Expand Down
77 changes: 74 additions & 3 deletions .github/workflows/linter-cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ on:
- main
paths:
- 'linter/**'
- '.github/workflows/linter-cicd.yml'

pull_request:
branches:
- main
paths:
- 'linter/**'
- '.github/workflows/linter-cicd.yml'

workflow_dispatch:

Expand Down Expand Up @@ -121,7 +123,7 @@ jobs:
UBSAN_OPTIONS: print_stacktrace=1
run: ctest --output-on-failure --no-tests=error -j 2

test:
test-linux:
needs: [lint]

strategy:
Expand Down Expand Up @@ -198,9 +200,78 @@ jobs:
working-directory: linter/build
run: ctest --output-on-failure --no-tests=error -C Release -j 2

test-darwin:
needs: [lint]

strategy:
matrix:
os: [macos-14]

runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: linter

env:
CC: /opt/homebrew/opt/llvm/bin/clang
CXX: /opt/homebrew/opt/llvm/bin/clang++
CLANG_DIR: '/opt/homebrew/opt/llvm/bin/clang'
LLVM_DIR: '/opt/homebrew/opt/llvm'

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install LLVM 17
run: |
brew install llvm@17
brew install clang-format

- name: Install static analyzers
if: matrix.os == 'macos-14'
run: >-
brew install cppcheck

- name: Install Python
uses: actions/setup-python@v4
with: { python-version: "3.12" }

- name: Install Python Developer Headers
run: brew install [email protected]

- name: Install dependencies
shell: bash
run: |
pip3 install conan
conan profile detect
python3 ../.github/scripts/write_config.py
conan install . -s build_type=Release -b missing

- name: Setup MultiToolTask
if: matrix.os == 'windows-2022'
run: |
Add-Content "$env:GITHUB_ENV" 'UseMultiToolTask=true'
Add-Content "$env:GITHUB_ENV" 'EnforceProcessCountAcrossBuilds=true'

- name: Configure
shell: pwsh
run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])"

- name: Build
run: cmake --build build --config Release -j 2

- name: Install
run: cmake --install build --config Release --prefix prefix

- name: Test
working-directory: linter/build
run: ctest --output-on-failure --no-tests=error -C Release -j 2


docs:
# Deploy docs only when builds succeed
needs: [sanitize, test]
needs: [sanitize, test-darwin, test-linux]

runs-on: ubuntu-22.04
defaults:
Expand Down Expand Up @@ -272,7 +343,7 @@ jobs:


deploy-dockerimage:
needs: [lint, sanitize, test]
needs: [lint, sanitize, test-darwin, test-linux]

# don't want to deploy if PR
if: github.event_name == 'push'
Expand Down
10 changes: 10 additions & 0 deletions exchange/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@
"cacheVariables": {
"USE_GIT_VERSION_TRACKING": "OFF"
}
},
{
"name": "ci-sanitize-darwin",
"binaryDir": "${sourceDir}/build/sanitize",
"inherits": ["ci-darwin", "dev-mode", "conan"],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Sanitize",
"CMAKE_CXX_FLAGS_SANITIZE": "-O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common",
"CMAKE_MAP_IMPORTED_CONFIG_SANITIZE": "Sanitize;RelWithDebInfo;Release;Debug;"
}
}

]
Expand Down
2 changes: 1 addition & 1 deletion exchange/cmake/lint.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ foreach(file IN LISTS files)
if(NOT result EQUAL "0")
message(FATAL_ERROR "'${file}': formatter returned with ${result}")
endif()
if(NOT FIX AND output MATCHES "\n<replacement offset")
if(NOT FIX AND output MATCHES "incomplete_format='true'")
string(SUBSTRING "${file}" "${path_prefix_length}" -1 relative_file)
list(APPEND badly_formatted "${relative_file}")
endif()
Expand Down
2 changes: 1 addition & 1 deletion exchange/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def layout(self):

def requirements(self):
# Exchange
self.requires("fmt/[>=10.1.0]")
self.requires("fmt/10.2.1")
self.requires("quill/3.7.0")
self.requires("rabbitmq-c/0.14.0")
self.requires("libcurl/8.6.0")
Expand Down
19 changes: 16 additions & 3 deletions exchange/scripts/check_rabbitmq.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
#!/bin/bash

wait_for_rabbitmq() {
local pid_path="/var/lib/rabbitmq/mnesia/rabbit@$(hostname).pid"
if [[ "$(uname)" == "Darwin" ]]; then
pid_path="/usr/local/var/lib/rabbitmq/mnesia/rabbit@$(hostname).pid"
fi
echo "Waiting for RabbitMQ to be ready..."
rabbitmqctl wait "$pid_path"
echo "RabbitMQ is ready."
}

USERNAME="NUFT"
PASSWORD="ADMIN"

if docker ps | grep -q nutc-rabbitmq-server; then
echo "'nutc-rabbitmq-server' container is already running."
true
elif docker ps -a | grep -q nutc-rabbitmq-server; then
echo "Starting the existing 'nutc-rabbitmq-server' container..."
docker start nutc-rabbitmq-server
echo "'nutc-rabbitmq-server' container started."
sleep 5
wait_for_rabbitmq
else
echo "Starting RabbitMQ container..."
docker run -d \
Expand All @@ -20,5 +30,8 @@ else
-e RABBITMQ_DEFAULT_PASS=$PASSWORD \
rabbitmq:management
echo "RabbitMQ container started with username: $USERNAME and password: $PASSWORD."
sleep 5
wait_for_rabbitmq
fi



11 changes: 7 additions & 4 deletions exchange/src/exchange/algos/normal_mode/normal_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ namespace algo_mgmt {
void
NormalModeAlgoManager::initialize_client_manager(manager::TraderManager& users)
{
constexpr std::array<const char*, 3> REQUIRED_FIEDS = {
static constexpr const std::array<const char*, 3> REQUIRED_FIEDS = {
"latestAlgoId", "firstName", "lastName"
};
int starting_cap = config::Config::get_instance().constants().STARTING_CAPITAL;
static const int STARTING_CAPITAL =
config::Config::get_instance().constants().STARTING_CAPITAL;

glz::json_t::object_t firebase_users = get_all_users();
for (const auto& [user_id, user] : firebase_users) {
for (const auto& user_it : firebase_users) {
const auto& user_id = user_it.first;
const auto& user = user_it.second;
bool contains_all_fields = std::all_of(
REQUIRED_FIEDS.begin(), REQUIRED_FIEDS.end(),
[&user](const char* field) { return user.contains(field); }
Expand All @@ -34,7 +37,7 @@ NormalModeAlgoManager::initialize_client_manager(manager::TraderManager& users)
);
std::string algo_id = user["latestAlgoId"].get<std::string>();
users.add_trader<manager::RemoteTrader>(
user_id, full_name, algo_id, starting_cap
user_id, full_name, algo_id, STARTING_CAPITAL
);
}
}
Expand Down
2 changes: 0 additions & 2 deletions exchange/src/exchange/algos/normal_mode/normal_mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace nutc {
namespace algo_mgmt {

class NormalModeAlgoManager : public AlgoManager {
size_t num_clients_{};

public:
void initialize_client_manager(manager::TraderManager& users) override;

Expand Down
5 changes: 2 additions & 3 deletions exchange/src/exchange/concurrency/exchange_lock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ namespace nutc {
namespace concurrency {

class ExchangeLock {
std::atomic_flag flag_;

ExchangeLock() : flag_(ATOMIC_FLAG_INIT) {}
std::atomic_flag flag_{};

ExchangeLock() = default;
~ExchangeLock() = default;

public:
Expand Down
16 changes: 8 additions & 8 deletions exchange/src/exchange/dashboard/dashboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,37 +267,37 @@ Dashboard::display_performance(WINDOW* window, int start_y)
if (tick_manager.get_current_tick() < 100) {
mvwprintw(
window, start_y + 4, window->_maxx / 2 - 23,
"Current tick (%lu) below 100. Not enough data",
"Current tick (%llu) below 100. Not enough data",
tick_manager.get_current_tick()
);
return;
}
mvwprintw(
window, start_y++, window->_maxx / 2 - 8, "Current Tick: %lu",
window, start_y++, window->_maxx / 2 - 8, "Current Tick: %llu",
tick_manager.get_current_tick()
);
mvwprintw(
window, start_y++, window->_maxx / 2 - 13, "Top 1p tick times(ms): %lu",
window, start_y++, window->_maxx / 2 - 13, "Top 1p tick times(ms): %llu",
metrics.top_1p_ms.count()
);
mvwprintw(
window, start_y++, window->_maxx / 2 - 13, "Top 5p tick times(ms): %lu",
window, start_y++, window->_maxx / 2 - 13, "Top 5p tick times(ms): %llu",
metrics.top_5p_ms.count()
);
mvwprintw(
window, start_y++, window->_maxx / 2 - 13, "Top 10p tick times(ms): %lu",
window, start_y++, window->_maxx / 2 - 13, "Top 10p tick times(ms): %llu",
metrics.top_10p_ms.count()
);
mvwprintw(
window, start_y++, window->_maxx / 2 - 13, "Top 50p tick times(ms): %lu",
window, start_y++, window->_maxx / 2 - 13, "Top 50p tick times(ms): %llu",
metrics.top_50p_ms.count()
);
mvwprintw(
window, start_y++, window->_maxx / 2 - 13, "Average tick time(ms): %lu",
window, start_y++, window->_maxx / 2 - 13, "Average tick time(ms): %llu",
metrics.avg_tick_ms.count()
);
mvwprintw(
window, start_y++, window->_maxx / 2 - 12, "Median tick time(ms): %lu",
window, start_y++, window->_maxx / 2 - 12, "Median tick time(ms): %llu",
metrics.median_tick_ms.count()
);
mvwprintw(
Expand Down
Loading
Loading