From 641098d07a9c83f5033c80d1c81d2ae3a163706e Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Sun, 27 Feb 2022 20:27:46 -0500 Subject: [PATCH] Adapt workflow for conan. --- .github/workflows/build_and_test.yml | 64 ++++++++ .github/workflows/hosted-pure-workflow.yml | 94 ------------ conanfile.py | 2 +- test/auth/auth.cpp | 168 ++++++++++----------- test/calls/calls.cpp | 36 ++--- test/pubsub/pubsub.cpp | 49 +++--- 6 files changed, 183 insertions(+), 230 deletions(-) create mode 100644 .github/workflows/build_and_test.yml delete mode 100644 .github/workflows/hosted-pure-workflow.yml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml new file mode 100644 index 0000000..e33d117 --- /dev/null +++ b/.github/workflows/build_and_test.yml @@ -0,0 +1,64 @@ +name: build-and-test +on: [ push, workflow_dispatch ] + +jobs: + job: + name: ${{ matrix.os }}-${{ github.workflow }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + include: + - os: windows-latest + triplet: x64-windows + - os: ubuntu-latest + triplet: x64-linux + - os: macos-latest + triplet: x64-osx + + steps: + - uses: actions/checkout@v2 + with: + submodules: true + + - uses: actions/setup-python@v2 + with: + python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax + architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified + + - name: Prepare Docker. + uses: docker-practice/actions-setup-docker@master + + - name: Prepare Tools. + run: | + pip install conan + if [ "$RUNNER_OS" != "Windows" ]; then + docker pull crossbario/crossbar + else + echo "Skipping on Windows." + fi + shell: bash + + - name: Restore Dependency Cache. + uses: actions/cache@v2 + with: + path: | + /home/runner/.conan/data + # The key is composed in a way that it gets properly invalidated: this must happen whenever vcpkg's Git commit id changes, or the list of packages changes. In this case a cache miss must happen and a new entry with a new key with be pushed to GitHub the cache service. + # The key includes: hash of the vcpkg.json file, the hash of the vcpkg Git commit id, and the used vcpkg's triplet. The vcpkg's commit id would suffice, but computing an hash out it does not harm. + # Note: given a key, the cache content is immutable. If a cache entry has been created improperly, in order the recreate the right content the key must be changed as well, and it must be brand new (i.e. not existing already). + key: | + ${{ hashFiles( 'conanfile.py' ) }}-${{ matrix.triplet }} + + # Run CMake to generate Ninja project files, using the vcpkg's toolchain file to resolve and install the dependencies as specified in vcpkg.json. + - name: Build and Test. + run: | + mkdir build + cd build + cmake .. -DCMAKE_BUILD_TYPE=Release + make + if [ "$RUNNER_OS" != "Windows" ]; then + ctest + fi + shell: bash \ No newline at end of file diff --git a/.github/workflows/hosted-pure-workflow.yml b/.github/workflows/hosted-pure-workflow.yml deleted file mode 100644 index 004b52d..0000000 --- a/.github/workflows/hosted-pure-workflow.yml +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright (c) 2021 Luca Cappa -# Released under the term specified in file LICENSE.txt -# SPDX short identifier: MIT - -# A "pure" GitHub workflow using CMake, Ninja and vcpkg to build a C/C++ codebase. -# It leverages both CMakePresets.json and vcpkg.json to have consistent build locallly -# and on continuous integration servers (aka build agents). -# It is called "pure workflow" because it is an example which minimizes the usage of -# custom GitHub actions, but leverages directly the tools that could be easily run on -# your development machines (i.e. CMake, vcpkg, Ninja) to ensure a perfectly identical -# and reproducible build locally (on your development machine) and remotely (on build agents). -name: hosted-pure-workflow -on: [ push, workflow_dispatch ] - -jobs: - job: - name: ${{ matrix.os }}-${{ github.workflow }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ ubuntu-latest, macos-latest, windows-latest ] - include: - - os: windows-latest - triplet: x64-windows - - os: ubuntu-latest - triplet: x64-linux - - os: macos-latest - triplet: x64-osx - env: - # Indicates the location of the vcpkg as a Git submodule of the project repository. - VCPKG_ROOT: ${{ github.workspace }}/vcpkg - # Tells vcpkg where binary packages are stored. - VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg/bincache - - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - - name: "Create directory '${{ env.VCPKG_DEFAULT_BINARY_CACHE }}'" - run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE - shell: bash - - # Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service. - - uses: lukka/get-cmake@latest - - - uses: docker-practice/actions-setup-docker@master - - run: | - if [ "$RUNNER_OS" != "Windows" ]; then - docker pull crossbario/crossbar - else - echo "Skipping on Windows." - fi - shell: bash - # Restore both vcpkg and its artifacts from the GitHub cache service. - - name: Restore Dependency Cache. - uses: actions/cache@v2 - with: - # The first path is the location of vcpkg: it contains the vcpkg executable and data files, as long as the - # built package archives (aka binary cache) which are located by VCPKG_DEFAULT_BINARY_CACHE env var. - # The other paths starting with '!' are exclusions: they contain termporary files generated during the build of the installed packages. - path: | - ${{ env.VCPKG_ROOT }} - !${{ env.VCPKG_ROOT }}/buildtrees - !${{ env.VCPKG_ROOT }}/packages - !${{ env.VCPKG_ROOT }}/downloads - !${{ env.VCPKG_ROOT }}/installed - # The key is composed in a way that it gets properly invalidated: this must happen whenever vcpkg's Git commit id changes, or the list of packages changes. In this case a cache miss must happen and a new entry with a new key with be pushed to GitHub the cache service. - # The key includes: hash of the vcpkg.json file, the hash of the vcpkg Git commit id, and the used vcpkg's triplet. The vcpkg's commit id would suffice, but computing an hash out it does not harm. - # Note: given a key, the cache content is immutable. If a cache entry has been created improperly, in order the recreate the right content the key must be changed as well, and it must be brand new (i.e. not existing already). - key: | - ${{ hashFiles( 'vcpkg.json' ) }}-${{ hashFiles( '.git/modules/vcpkg/HEAD' )}}-${{ matrix.triplet }} - # On Windows runners, let's ensure to have the Developer Command Prompt environment setup correctly. As used here the Developer Command Prompt created is targeting x64 and using the default the Windows SDK. - - uses: ilammy/msvc-dev-cmd@v1 - - # Run CMake to generate Ninja project files, using the vcpkg's toolchain file to resolve and install the dependencies as specified in vcpkg.json. - - name: Install Dependencies. - run: | - cmake --preset ninja-multi-vcpkg - - # Build the whole project with Ninja (which is spawn by CMake). Debug configuration. - - name: Build. - run: | - cmake --build --preset ninja-multi-vcpkg-debug - # Test the whole project with CTest. - - name: Run Tests. - run: | - if [ "$RUNNER_OS" != "Windows" ]; then - ctest --preset ninja-multi-vcpkg-debug - else - echo "Skipping on Windows." - fi - shell: bash \ No newline at end of file diff --git a/conanfile.py b/conanfile.py index 58c2e25..4b84753 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,5 +1,6 @@ from conans import ConanFile, CMake, tools + class autobahn_cppConan(ConanFile): name = "autobahn-cpp" version = "v20.8.1" @@ -23,4 +24,3 @@ def package(self): def package_id(self): self.info.header_only() - diff --git a/test/auth/auth.cpp b/test/auth/auth.cpp index e0dbd2c..0ae44cf 100644 --- a/test/auth/auth.cpp +++ b/test/auth/auth.cpp @@ -31,100 +31,88 @@ #include "test/wamp_test.hpp" #include -struct Config -{ - std::string realm{"realm1"}; - std::string uri{"ws://127.0.0.1:8080/ws"}; - bool debug{false}; +struct Config { + std::string realm{"realm1"}; + std::string uri{"ws://127.0.0.1:8080/ws"}; + bool debug{false}; }; -TEST_CASE_METHOD(wamp_test::fixture, "wamp.auth.cra") -{ - bool joined_realm_with_success = join_realm( - "client1_cra", - wamp_test::Secret("client1_secret"), - [&](Transport& transport, Session& session) - { - auto welcome_details = session.welcome_details(); - REQUIRE(welcome_details["authprovider"].as() == "static"); - REQUIRE(welcome_details["realm"].as() == "realm1"); - REQUIRE(welcome_details["authid"].as() == "client1_cra"); - REQUIRE(welcome_details["authrole"].as() == "frontend"); - }); - REQUIRE(true == joined_realm_with_success); - joined_realm_with_success = join_realm( - "client2_cra", - wamp_test::Secret("client2_secret"), - [&](Transport& transport, Session& session) - { - auto welcome_details = session.welcome_details(); - REQUIRE(welcome_details["authprovider"].as() == "static"); - REQUIRE(welcome_details["realm"].as() == "realm1"); - REQUIRE(welcome_details["authid"].as() == "client2_cra"); - REQUIRE(welcome_details["authrole"].as() == "backend"); - }); - REQUIRE(true == joined_realm_with_success); - REQUIRE(false == join_realm("client3", wamp_test::Secret("unknown"))); +TEST_CASE_METHOD(wamp_test::fixture, "wamp.auth.cra") { + bool joined_realm_with_success = join_realm( + "client1_cra", wamp_test::Secret("client1_secret"), + [&](Transport &transport, Session &session) { + auto welcome_details = session.welcome_details(); + REQUIRE(welcome_details["authprovider"].as() == "static"); + REQUIRE(welcome_details["realm"].as() == "realm1"); + REQUIRE(welcome_details["authid"].as() == "client1_cra"); + REQUIRE(welcome_details["authrole"].as() == "frontend"); + }); + REQUIRE(true == joined_realm_with_success); + joined_realm_with_success = join_realm( + "client2_cra", wamp_test::Secret("client2_secret"), + [&](Transport &transport, Session &session) { + auto welcome_details = session.welcome_details(); + REQUIRE(welcome_details["authprovider"].as() == "static"); + REQUIRE(welcome_details["realm"].as() == "realm1"); + REQUIRE(welcome_details["authid"].as() == "client2_cra"); + REQUIRE(welcome_details["authrole"].as() == "backend"); + }); + REQUIRE(true == joined_realm_with_success); + REQUIRE(false == join_realm("client3", wamp_test::Secret("unknown"))); } -TEST_CASE_METHOD(wamp_test::fixture, "wamp.auth.ticket") -{ - bool joined_realm_with_success = join_realm( - "client1", - wamp_test::Ticket("client1_ticket"), - [&](Transport& transport, Session& session) - { - auto welcome_details = session.welcome_details(); - REQUIRE(welcome_details["authprovider"].as() == "static"); - REQUIRE(welcome_details["realm"].as() == "realm1"); - REQUIRE(welcome_details["authid"].as() == "client1"); - REQUIRE(welcome_details["authrole"].as() == "frontend"); - }); - REQUIRE(true == joined_realm_with_success); - joined_realm_with_success = join_realm( - "client2", - wamp_test::Ticket("client2_ticket"), - [&](Transport& transport, Session& session) - { - auto welcome_details = session.welcome_details(); - REQUIRE(welcome_details["authprovider"].as() == "static"); - REQUIRE(welcome_details["realm"].as() == "realm1"); - REQUIRE(welcome_details["authid"].as() == "client2"); - REQUIRE(welcome_details["authrole"].as() == "backend"); - }); - REQUIRE(true == joined_realm_with_success); - REQUIRE(false == join_realm("client3", wamp_test::Ticket("unknown"))); +TEST_CASE_METHOD(wamp_test::fixture, "wamp.auth.ticket") { + bool joined_realm_with_success = join_realm( + "client1", wamp_test::Ticket("client1_ticket"), + [&](Transport &transport, Session &session) { + auto welcome_details = session.welcome_details(); + REQUIRE(welcome_details["authprovider"].as() == "static"); + REQUIRE(welcome_details["realm"].as() == "realm1"); + REQUIRE(welcome_details["authid"].as() == "client1"); + REQUIRE(welcome_details["authrole"].as() == "frontend"); + }); + REQUIRE(true == joined_realm_with_success); + joined_realm_with_success = join_realm( + "client2", wamp_test::Ticket("client2_ticket"), + [&](Transport &transport, Session &session) { + auto welcome_details = session.welcome_details(); + REQUIRE(welcome_details["authprovider"].as() == "static"); + REQUIRE(welcome_details["realm"].as() == "realm1"); + REQUIRE(welcome_details["authid"].as() == "client2"); + REQUIRE(welcome_details["authrole"].as() == "backend"); + }); + REQUIRE(true == joined_realm_with_success); + REQUIRE(false == join_realm("client3", wamp_test::Ticket("unknown"))); } -TEST_CASE_METHOD(wamp_test::fixture, "wamp.auth.cryptosign") -{ - bool joined_realm_with_success = join_realm( - "3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29", - wamp_test::Cryptosign(Botan::secure_vector(32, 0)), - [&](Transport& transport, Session& session) - { - auto welcome_details = session.welcome_details(); - REQUIRE(welcome_details["authprovider"].as() == "static"); - REQUIRE(welcome_details["realm"].as() == "realm1"); - REQUIRE( - welcome_details["authid"].as() - == "3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29"); - REQUIRE(welcome_details["authrole"].as() == "frontend"); - }); - REQUIRE(true == joined_realm_with_success); - joined_realm_with_success = join_realm( - "8a88e3dd7409f195fd52db2d3cba5d72ca6709bf1d94121bf3748801b40f6f5c", - wamp_test::Cryptosign(Botan::secure_vector(32, 1)), - [&](Transport& transport, Session& session) - { - auto welcome_details = session.welcome_details(); - REQUIRE(welcome_details["authprovider"].as() == "static"); - REQUIRE(welcome_details["realm"].as() == "realm1"); - REQUIRE( - welcome_details["authid"].as() - == "8a88e3dd7409f195fd52db2d3cba5d72ca6709bf1d94121bf3748801b40f6f5c"); - REQUIRE(welcome_details["authrole"].as() == "backend"); - }); - REQUIRE(true == joined_realm_with_success); - REQUIRE(false == join_realm("unknown", wamp_test::Cryptosign(Botan::secure_vector(32, 3)))); +TEST_CASE_METHOD(wamp_test::fixture, "wamp.auth.cryptosign") { + bool joined_realm_with_success = join_realm( + "3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29", + wamp_test::Cryptosign(Botan::secure_vector(32, 0)), + [&](Transport &transport, Session &session) { + auto welcome_details = session.welcome_details(); + REQUIRE(welcome_details["authprovider"].as() == "static"); + REQUIRE(welcome_details["realm"].as() == "realm1"); + REQUIRE( + welcome_details["authid"].as() == + "3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29"); + REQUIRE(welcome_details["authrole"].as() == "frontend"); + }); + REQUIRE(true == joined_realm_with_success); + joined_realm_with_success = join_realm( + "8a88e3dd7409f195fd52db2d3cba5d72ca6709bf1d94121bf3748801b40f6f5c", + wamp_test::Cryptosign(Botan::secure_vector(32, 1)), + [&](Transport &transport, Session &session) { + auto welcome_details = session.welcome_details(); + REQUIRE(welcome_details["authprovider"].as() == "static"); + REQUIRE(welcome_details["realm"].as() == "realm1"); + REQUIRE( + welcome_details["authid"].as() == + "8a88e3dd7409f195fd52db2d3cba5d72ca6709bf1d94121bf3748801b40f6f5c"); + REQUIRE(welcome_details["authrole"].as() == "backend"); + }); + REQUIRE(true == joined_realm_with_success); + REQUIRE(false == + join_realm("unknown", wamp_test::Cryptosign( + Botan::secure_vector(32, 3)))); } diff --git a/test/calls/calls.cpp b/test/calls/calls.cpp index 6e9e22f..5f6293a 100644 --- a/test/calls/calls.cpp +++ b/test/calls/calls.cpp @@ -31,23 +31,25 @@ #include "test/wamp_test.hpp" #include -struct Config -{ - std::string realm{"realm1"}; - std::string uri{"ws://127.0.0.1:8080/ws"}; - bool debug{false}; +struct Config { + std::string realm{"realm1"}; + std::string uri{"ws://127.0.0.1:8080/ws"}; + bool debug{false}; }; -TEST_CASE_METHOD(wamp_test::fixture, "wamp.calls.simple") -{ - bool joined_realm_with_success = join_realm( - "client1", - wamp_test::Ticket("ticket"), - [&](Transport& transport, Session& session) - { - REQUIRE(3 == call("com.example.add2", std::tuple(1, 2)).get()); - REQUIRE(5 == call("com.example.add2", std::tuple(2, 3)).get()); - REQUIRE(!call("com.example.unknown", std::tuple(3, 4, 5)).has_value()); - }); - REQUIRE(true == joined_realm_with_success); +TEST_CASE_METHOD(wamp_test::fixture, "wamp.calls.simple") { + bool joined_realm_with_success = join_realm( + "client1", wamp_test::Ticket("ticket"), + [&](Transport &transport, Session &session) { + REQUIRE( + 3 == + call("com.example.add2", std::tuple(1, 2)).get()); + REQUIRE( + 5 == + call("com.example.add2", std::tuple(2, 3)).get()); + REQUIRE(!call("com.example.unknown", + std::tuple(3, 4, 5)) + .has_value()); + }); + REQUIRE(true == joined_realm_with_success); } diff --git a/test/pubsub/pubsub.cpp b/test/pubsub/pubsub.cpp index 6be4696..8a86325 100644 --- a/test/pubsub/pubsub.cpp +++ b/test/pubsub/pubsub.cpp @@ -31,34 +31,27 @@ #include "test/wamp_test.hpp" #include -struct Config -{ - std::string realm{"realm1"}; - std::string uri{"ws://127.0.0.1:8080/ws"}; - bool debug{false}; +struct Config { + std::string realm{"realm1"}; + std::string uri{"ws://127.0.0.1:8080/ws"}; + bool debug{false}; }; -TEST_CASE_METHOD(wamp_test::fixture, "WAMP AUTH: TICKET") -{ - bool joined_realm_with_success = join_realm( - "client1", - wamp_test::Ticket("ticket"), - [&](Transport& transport, Session& session) - { - std::string received_data; - session.subscribe( - "com.example.topic", - [&received_data](const autobahn::wamp_event& event) - { - received_data = event->argument(0); - } - ); - REQUIRE(1 == call("com.example.publish", std::tuple<>()).get()); - REQUIRE("data='1'" == received_data); - REQUIRE(2 == call("com.example.publish", std::tuple<>()).get()); - REQUIRE("data='2'" == received_data); - REQUIRE(3 == call("com.example.publish", std::tuple<>()).get()); - REQUIRE("data='3'" == received_data); - }); - REQUIRE(true == joined_realm_with_success); +TEST_CASE_METHOD(wamp_test::fixture, "WAMP AUTH: TICKET") { + bool joined_realm_with_success = join_realm( + "client1", wamp_test::Ticket("ticket"), + [&](Transport &transport, Session &session) { + std::string received_data; + session.subscribe("com.example.topic", + [&received_data](const autobahn::wamp_event &event) { + received_data = event->argument(0); + }); + REQUIRE(1 == call("com.example.publish", std::tuple<>()).get()); + REQUIRE("data='1'" == received_data); + REQUIRE(2 == call("com.example.publish", std::tuple<>()).get()); + REQUIRE("data='2'" == received_data); + REQUIRE(3 == call("com.example.publish", std::tuple<>()).get()); + REQUIRE("data='3'" == received_data); + }); + REQUIRE(true == joined_realm_with_success); }