From dd8038b2c19d72551f222a733a1f0ca141f0a40d Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Wed, 13 Apr 2022 06:49:18 +0000 Subject: [PATCH] Publish lib and aggregator as artifacts --- .github/workflows/ci.yml | 23 +++++++++++++++++++ .../mithril-aggregator/src/http_server.rs | 2 +- .../src/Mithril/Aggregator.hs | 18 +++++++++------ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22ee20d7891..c00b0ab3a9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,6 +92,14 @@ jobs: with: files: ./**/test-results.xml + - name: Publish libmithril + uses: actions/upload-artifact@v3 + with: + name: libmithril + path: | + mithril-core/target/release/libmithril.so + mithril-core/target/include/mithril.h + build-mithril-aggregator: if: github.event.pull_request.draft == false runs-on: ubuntu-latest @@ -148,6 +156,12 @@ jobs: command: test args: --release --manifest-path ./mithril-network/mithril-aggregator/Cargo.toml + - name: Publish aggregator + uses: actions/upload-artifact@v3 + with: + name: mithril-aggregator + path: mithril-network/mithril-aggregator/target/release/mithril-aggregator + build-mithril-node-poc: runs-on: ubuntu-latest steps: @@ -378,6 +392,7 @@ jobs: extra_nix_config: | trusted-public-keys = iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= substituters = https://cache.nixos.org https://hydra.iohk.io https://iohk.cachix.org + - name: Github cache ~/.cabal/packages, ~/.cabal/store and dist-newstyle uses: actions/cache@v2.1.5 with: @@ -392,6 +407,14 @@ jobs: run: | nix-build shell.nix + - name: Download aggregator + uses: actions/download-artifact@v3 + with: + name: mithril-aggregator + path: ~/.cabal/bin/ + + - run: chmod +x ~/.cabal/bin/mithril-aggregator + - name: Build run: nix-shell --run '.github/workflows/ci-build.sh' diff --git a/mithril-network/mithril-aggregator/src/http_server.rs b/mithril-network/mithril-aggregator/src/http_server.rs index 88b78e32355..03b009221d0 100644 --- a/mithril-network/mithril-aggregator/src/http_server.rs +++ b/mithril-network/mithril-aggregator/src/http_server.rs @@ -132,7 +132,7 @@ mod handlers { debug!("snapshots"); // Snapshots - let snapshots = fake_data::snapshots(10); + let snapshots = fake_data::snapshots(1); Ok(warp::reply::json(&snapshots)) } diff --git a/mithril-test-lab/mithril-end-to-end/src/Mithril/Aggregator.hs b/mithril-test-lab/mithril-end-to-end/src/Mithril/Aggregator.hs index ba57ca4e28d..c3e86081fe1 100644 --- a/mithril-test-lab/mithril-end-to-end/src/Mithril/Aggregator.hs +++ b/mithril-test-lab/mithril-end-to-end/src/Mithril/Aggregator.hs @@ -5,9 +5,11 @@ module Mithril.Aggregator where import Control.Tracer (Tracer, traceWith) import Hydra.Prelude +import qualified Paths_mithril_end_to_end as Pkg +import System.Directory (doesFileExist) import System.FilePath (()) import System.Process (CreateProcess (..), StdStream (UseHandle), proc, withCreateProcess) -import Test.Hydra.Prelude (checkProcessHasNotDied) +import Test.Hydra.Prelude (checkProcessHasNotDied, failure) import Test.Network.Ports (randomUnusedTCPPort) data Aggregator = Aggregator {aggregatorPort :: Int} @@ -18,13 +20,11 @@ data AggregatorLog deriving stock (Eq, Show, Generic) deriving anyclass (ToJSON, FromJSON) --- TODO: start an aggregator server on some default configuration that allocates random --- port and wait for 'action' to terminate before closing the server. withAggregator :: FilePath -> Tracer IO AggregatorLog -> (Aggregator -> IO a) -> IO a withAggregator workDir tracer action = do port <- randomUnusedTCPPort - let process = aggregatorProcess (Just workDir) port - logFile = workDir "aggregator.log" + process <- aggregatorProcess (Just workDir) port + let logFile = workDir "aggregator.log" traceWith tracer (StartingAggregator workDir) withFile logFile WriteMode $ \out -> withCreateProcess process {std_out = UseHandle out, std_err = UseHandle out} $ \_stdin _stdout _stderr processHandle -> @@ -35,5 +35,9 @@ withAggregator workDir tracer action = do Left _ -> error "should never happen" Right a -> pure a -aggregatorProcess :: Maybe FilePath -> Int -> CreateProcess -aggregatorProcess cwd port = (proc "mithril-aggregator" ["--server-port", show port]) {cwd} +aggregatorProcess :: Maybe FilePath -> Int -> IO CreateProcess +aggregatorProcess cwd port = do + binDir <- Pkg.getBinDir + let aggregator = binDir "mithril-aggregator" + unlessM (doesFileExist aggregator) $ failure $ "cannot find mithril-aggregator executable in expected location (" <> binDir <> ")" + pure $ (proc aggregator ["--server-port", show port]) {cwd}