From 603c5410ecfa91dcfff963be6dc1d85e1db21cde Mon Sep 17 00:00:00 2001 From: Neylix Date: Mon, 9 May 2022 17:49:47 +0200 Subject: [PATCH] Improve GitHub actions duration (#309) * Improve Github actions duration * Set empty name in start_link() to avoid test error * Correct syntaxe error * Add cache for _build * Add hashFiles function --- .github/workflows/ci.yml | 29 +++++++++++++++++-- .gitignore | 3 ++ mix.exs | 11 ++++++- test/archethic/beacon_chain_test.exs | 2 +- test/archethic/bootstrap/sync_test.exs | 2 +- .../archethic/oracle_chain/scheduler_test.exs | 16 +++++----- .../sync/beacon_summary_handler_test.exs | 2 +- .../node_renewal_scheduler_test.exs | 2 +- 8 files changed, 51 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae2fd307c..125efd357 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ master, develop, testnet ] +env: + MIX_ENV: test + jobs: build: @@ -24,7 +27,8 @@ jobs: elixir-version: '1.12.3' # Define the elixir version [required] otp-version: '24.1' # Define the OTP version [required] - name: Restore dependencies cache - uses: actions/cache@v2 + uses: actions/cache@v3 + id: mix-cache with: path: deps key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} @@ -32,14 +36,33 @@ jobs: - name: Make Clean run: mix clean - name: Install dependencies + if: steps.mix-cache.outputs.cache-hit != 'true' run: mix deps.get - name: Set Formatting run: mix format --check-formatted + - name: Restore build cache + uses: actions/cache@v3 + with: + path: _build + key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-build- - name: Compile the codebase run: mix compile --warnings-as-errors - name: Set credo run: mix credo - name: Run tests run: mix test --trace - - name: Run Dialyzer - run: mix dialyzer + - name: Retrieve PLT Cache + uses: actions/cache@v3 + id: plt-cache + with: + path: priv/plts + key: ${{ runner.os }}-plts-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-plts- + - name: Create PLTs + if: steps.plt-cache.outputs.cache-hit != 'true' + run: | + mkdir -p priv/plts + mix dialyzer --plt + - name: Run dialyzer + run: mix dialyzer --no-check diff --git a/.gitignore b/.gitignore index e0aa10a3a..310c4b9f2 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,9 @@ erl_crash.dump # Self signed cert are used for local and dev purposes /priv/cert +# Dialyzer +/priv/plts + /assets/node_modules log_* diff --git a/mix.exs b/mix.exs index ee9d6600c..cac260750 100644 --- a/mix.exs +++ b/mix.exs @@ -16,7 +16,7 @@ defmodule Archethic.MixProject do compilers: [:elixir_make, :phoenix] ++ Mix.compilers(), elixirc_paths: elixirc_paths(Mix.env()), elixirc_options: [warnings_as_errors: true], - dialyzer: [plt_add_apps: [:mix]] + dialyzer: dialyzer() ] end @@ -31,6 +31,15 @@ defmodule Archethic.MixProject do defp elixirc_paths(:test), do: ["lib", "test/support"] defp elixirc_paths(_), do: ["lib"] + # Specify dialyzer path + defp dialyzer do + [ + plt_add_apps: [:mix, :ex_unit], + plt_core_path: "priv/plts", + plt_file: {:no_warn, "priv/plts/dialyzer.plt"} + ] + end + # Run "mix help deps" to learn about dependencies. defp deps do [ diff --git a/test/archethic/beacon_chain_test.exs b/test/archethic/beacon_chain_test.exs index 4f5d4de06..d565398a0 100644 --- a/test/archethic/beacon_chain_test.exs +++ b/test/archethic/beacon_chain_test.exs @@ -59,7 +59,7 @@ defmodule Archethic.BeaconChainTest do describe "load_transaction/1 for beacon transaction" do test "should fetch the transaction chain from the beacon involved nodes" do - SummaryTimer.start_link(interval: "0 0 * * * *") + SummaryTimer.start_link([interval: "0 0 * * * *"], []) P2P.add_and_connect_node(%Node{ ip: {127, 0, 0, 1}, diff --git a/test/archethic/bootstrap/sync_test.exs b/test/archethic/bootstrap/sync_test.exs index b278c84e0..c1c721f04 100644 --- a/test/archethic/bootstrap/sync_test.exs +++ b/test/archethic/bootstrap/sync_test.exs @@ -353,7 +353,7 @@ defmodule Archethic.Bootstrap.SyncTest do end test "publish_end_of_sync/0 should notify the network the node have finished its synchronization" do - BeaconSlotTimer.start_link(interval: "0 * * * * *") + BeaconSlotTimer.start_link([interval: "0 * * * * *"], []) P2P.add_and_connect_node(%Node{ ip: {127, 0, 0, 1}, diff --git a/test/archethic/oracle_chain/scheduler_test.exs b/test/archethic/oracle_chain/scheduler_test.exs index f4a51b807..f16af7d5a 100644 --- a/test/archethic/oracle_chain/scheduler_test.exs +++ b/test/archethic/oracle_chain/scheduler_test.exs @@ -21,14 +21,14 @@ defmodule Archethic.OracleChain.SchedulerTest do import Mox setup do - SelfRepairScheduler.start_link(interval: "0 0 * * *") + SelfRepairScheduler.start_link([interval: "0 0 * * *"], []) :ok end describe "start_link/1" do test "should start the process with idle state and initialize the polling date" do {:ok, pid} = - Scheduler.start_link(polling_interval: "0 * * * *", summary_interval: "0 0 0 * *") + Scheduler.start_link([polling_interval: "0 * * * *", summary_interval: "0 0 0 * *"], []) polling_date = "0 * * * *" @@ -81,7 +81,7 @@ defmodule Archethic.OracleChain.SchedulerTest do test "if not trigger node, it should skip the polling" do {:ok, pid} = - Scheduler.start_link(polling_interval: "0 * * * *", summary_interval: "0 0 0 * *") + Scheduler.start_link([polling_interval: "0 * * * *", summary_interval: "0 0 0 * *"], []) P2P.add_and_connect_node(%Node{ ip: {127, 0, 0, 1}, @@ -100,7 +100,7 @@ defmodule Archethic.OracleChain.SchedulerTest do test "if trigger node, it should fetch new data and create a new transaction" do {:ok, pid} = - Scheduler.start_link(polling_interval: "0 * * * *", summary_interval: "0 0 0 * *") + Scheduler.start_link([polling_interval: "0 * * * *", summary_interval: "0 0 0 * *"], []) P2P.add_and_connect_node(%Node{ ip: {127, 0, 0, 1}, @@ -147,7 +147,7 @@ defmodule Archethic.OracleChain.SchedulerTest do test "should not send a new transaction when the fetched data is the same" do {:ok, pid} = - Scheduler.start_link(polling_interval: "0 * * * *", summary_interval: "0 0 0 * *") + Scheduler.start_link([polling_interval: "0 * * * *", summary_interval: "0 0 0 * *"], []) P2P.add_and_connect_node(%Node{ ip: {127, 0, 0, 1}, @@ -186,7 +186,7 @@ defmodule Archethic.OracleChain.SchedulerTest do test "if the date is the summary date, it should generate summary transaction, followed by an polling oracle transaction" do {:ok, pid} = - Scheduler.start_link(polling_interval: "0 0 0 * *", summary_interval: "0 0 0 * *") + Scheduler.start_link([polling_interval: "0 0 0 * *", summary_interval: "0 0 0 * *"], []) P2P.add_and_connect_node(%Node{ ip: {127, 0, 0, 1}, @@ -277,7 +277,7 @@ defmodule Archethic.OracleChain.SchedulerTest do property "dates and address stay in sync over pollings" do {:ok, pid} = - Scheduler.start_link(polling_interval: "0 * * * *", summary_interval: "0 0 0 * *") + Scheduler.start_link([polling_interval: "0 * * * *", summary_interval: "0 0 0 * *"], []) P2P.add_and_connect_node(%Node{ ip: {127, 0, 0, 1}, @@ -349,7 +349,7 @@ defmodule Archethic.OracleChain.SchedulerTest do property "dates and address are in sync over the summaries" do {:ok, pid} = - Scheduler.start_link(polling_interval: "0 * * * *", summary_interval: "0 0 * * *") + Scheduler.start_link([polling_interval: "0 * * * *", summary_interval: "0 0 * * *"], []) P2P.add_and_connect_node(%Node{ ip: {127, 0, 0, 1}, diff --git a/test/archethic/self_repair/sync/beacon_summary_handler_test.exs b/test/archethic/self_repair/sync/beacon_summary_handler_test.exs index dbd3a9d0e..320950eba 100644 --- a/test/archethic/self_repair/sync/beacon_summary_handler_test.exs +++ b/test/archethic/self_repair/sync/beacon_summary_handler_test.exs @@ -49,7 +49,7 @@ defmodule Archethic.SelfRepair.Sync.BeaconSummaryHandlerTest do |> elem(0) |> NetworkLookup.set_daily_nonce_public_key(DateTime.utc_now() |> DateTime.add(-10)) - Archethic.SelfRepair.Scheduler.start_link(interval: "0 0 0 * * *") + Archethic.SelfRepair.Scheduler.start_link([interval: "0 0 0 * * *"], []) :ok end diff --git a/test/archethic/shared_secrets/node_renewal_scheduler_test.exs b/test/archethic/shared_secrets/node_renewal_scheduler_test.exs index 54f89bf1f..303b883b5 100644 --- a/test/archethic/shared_secrets/node_renewal_scheduler_test.exs +++ b/test/archethic/shared_secrets/node_renewal_scheduler_test.exs @@ -19,7 +19,7 @@ defmodule Archethic.SharedSecrets.NodeRenewalSchedulerTest do import Mox setup do - SelfRepairScheduler.start_link(interval: "0 0 0 * *") + SelfRepairScheduler.start_link([interval: "0 0 0 * *"], []) start_supervised!({BeaconSlotTimer, interval: "0 * * * * *"}) Enum.each(BeaconChain.list_subsets(), &Registry.register(SubsetRegistry, &1, [])) :ok