diff --git a/Dockerfile b/Dockerfile index 8fd7b15a9..ef70f11f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,21 @@ ARG MIX_ENV=prod # running TESTNET with release upgrade should ??? RUN apk add --no-cache --update \ - build-base bash gcc git npm python3 wget openssl libsodium-dev gmp-dev + build-base \ + bash \ + gcc \ + make \ + g++ \ + libexecinfo-dev \ + libexecinfo \ + git \ + npm \ + python3 \ + wget \ + openssl \ + libsodium-dev \ + gmp-dev + # Install hex and rebar RUN mix local.rebar --force \ @@ -51,7 +65,7 @@ RUN npm install -g sass # build Sass -> CSS RUN cd assets && \ - sass --no-source-map --style=compressed css/app.scss ../priv/static/css/app.css && cd - + sass --no-source-map --style=compressed css/app.scss ../priv/static/css/app.css && cd - # build release RUN mix do assets.deploy, distillery.release diff --git a/lib/archethic/governance/code.ex b/lib/archethic/governance/code.ex index e38a62d95..6f2f95cd0 100644 --- a/lib/archethic/governance/code.ex +++ b/lib/archethic/governance/code.ex @@ -153,28 +153,42 @@ defmodule Archethic.Governance.Code do """ @spec applicable_proposal?(Proposal.t()) :: boolean() def applicable_proposal?( - %Proposal{changes: changes, address: address}, + proposal, src_dir \\ @src_dir ) do - random = :crypto.strong_rand_bytes(4) |> Base.encode16() - prop_file = Path.join(System.tmp_dir!(), "prop_#{random}_#{Base.encode16(address)}") + res = apply_diff(proposal, src_dir, false) + match?({_, 0}, res) + end + + defp apply_diff( + %Proposal{changes: changes, address: address}, + src_dir, + persist? + ) do + prop_file = Path.join(System.tmp_dir!(), "prop_#{Base.encode16(address)}") File.write!(prop_file, changes) cmd_options = [stderr_to_stdout: true, cd: src_dir] git = fn args -> System.cmd("git", args, cmd_options) end + git_args = + if persist? do + ["apply", prop_file] + else + ["apply", "--check", prop_file] + end + res = case status() do {:clean, _} -> - git.(["apply", "--check", prop_file]) + git.(git_args) otherwise -> {:error, otherwise} end File.rm(prop_file) - - match?({_, 0}, res) + res end @doc """ diff --git a/lib/archethic/governance/code/cicd/docker/cicd.ex b/lib/archethic/governance/code/cicd/docker/cicd.ex index d4763f9a5..9b7bb33f2 100644 --- a/lib/archethic/governance/code/cicd/docker/cicd.ex +++ b/lib/archethic/governance/code/cicd/docker/cicd.ex @@ -56,8 +56,10 @@ defmodule Archethic.Governance.Code.CICD.Docker do end @impl CICD - def run_ci!(prop = %Proposal{}) do + def run_ci!(prop = %Proposal{changes: changes}) do + File.write!("./proposal.diff", changes) run!(prop, @ci_image, @ci_conductor, &do_run_docker_ci/1, "CI failed") + File.rm!("./proposal.diff") end @impl CICD @@ -127,10 +129,23 @@ defmodule Archethic.Governance.Code.CICD.Docker do @ci_script "/opt/code/scripts/governance/proposal_ci_job.sh" - defp do_run_docker_ci(%Proposal{address: address, changes: changes}) do + defp do_run_docker_ci(%Proposal{address: address, changes: changes, description: description}) do Logger.info("Verify proposal", address: Base.encode16(address)) name = container_name(address) - args = ["run", "--entrypoint", @ci_script, "-i", "--name", name, "archethic-ci", name] + + args = [ + "run", + "--entrypoint", + @ci_script, + "-i", + "--name", + name, + "archethic-ci", + name, + description, + address + ] + port = Port.open({:spawn_executable, System.find_executable("docker")}, [:binary, args: args]) # wait 250 ms or fail sooner diff --git a/mix.lock b/mix.lock index 113e89a7a..da9190414 100644 --- a/mix.lock +++ b/mix.lock @@ -22,7 +22,7 @@ "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, "dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"}, "digital_token": {:hex, :digital_token, "0.4.0", "2ad6894d4a40be8b2890aad286ecd5745fa473fa5699d80361a8c94428edcd1f", [:mix], [{:cldr_utils, "~> 2.17", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "a178edf61d1fee5bb3c34e14b0f4ee21809ee87cade8738f87337e59e5e66e26"}, - "distillery": {:git, "https://github.com/archethic-foundation/distillery.git", "67accaa239dcbe14fc312832c83b23eaaeed66ff", []}, + "distillery": {:git, "https://github.com/archethic-foundation/distillery.git", "e66841c9108a5e5e9a8722a8f737596193b7bc0d", []}, "earmark": {:hex, :earmark, "1.4.35", "e067aab15367c6e43230d6a7409c5230403a48b56f7dcefb3abdad75b498289e", [:mix], [{:earmark_parser, "~> 1.4.30", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "ab869cad78ebe64a62d45ee31addc52fb703c5d595868c9aa11ca38766ff9756"}, "earmark_parser": {:hex, :earmark_parser, "1.4.30", "0b938aa5b9bafd455056440cdaa2a79197ca5e693830b4a982beada840513c5f", [:mix], [], "hexpm", "3b5385c2d36b0473d0b206927b841343d25adb14f95f0110062506b300cd5a1b"}, "easy_ssl": {:hex, :easy_ssl, "1.3.0", "472256942d9dd37652a558a789a8d1cccc27e7f46352e32667d1ca46bb9e22e5", [:mix], [], "hexpm", "ce8fcb7661442713a94853282b56cee0b90c52b983a83aa6af24686d301808e1"}, diff --git a/scripts/governance/mk-code-proposal.sh b/scripts/governance/mk-code-proposal.sh deleted file mode 100755 index 0858bea3d..000000000 --- a/scripts/governance/mk-code-proposal.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# Assuming that the current branch is a feature branch and the most recent -# version of the source code is on the master branch, this script creates -# code-proposal.patch file. - -status=$(git status --porcelain) - -if [ -n "$status" ]; then - echo "Commit your changes or stash them before running this script" - exit 1 -fi - -feature_branch=$(git rev-parse --abbrev-ref HEAD) -feature_log=$(git log --format=" * %B" master..) -summary="📦 ${feature_branch}\n\n${feature_log}" - -cleanup() { git checkout $feature_branch; } - -trap cleanup ERR - -set -e - -git checkout master - -git merge --squash $feature_branch - -if (echo -e "$summary" |\ - git commit --author="archethic " --no-gpg-sign --edit -F-) -then - git format-patch --stdout master^ > code-proposal.patch - git reset --hard master^ -fi - -git checkout $feature_branch diff --git a/scripts/governance/proposal_ci_job.sh b/scripts/governance/proposal_ci_job.sh index f8f6b752f..99795d207 100755 --- a/scripts/governance/proposal_ci_job.sh +++ b/scripts/governance/proposal_ci_job.sh @@ -3,7 +3,8 @@ set -e PROPOSAL_ADDRESS=$1 -PROPOSAL_FILENAME=/tmp/proposal +PROPOSAL_DESCRIPTION=$2 +PROPOSAL_FILENAME=./proposal.diff echo "=== Test proposal ${PROPOSAL_ADDRESS}" tee ${PROPOSAL_FILENAME} @@ -12,7 +13,13 @@ echo "=== Create branch ${PROPOSAL_ADDRESS}" git checkout -b "prop_${PROPOSAL_ADDRESS}" echo "=== Apply patch ${PROPOSAL_FILENAME}" -git am ${PROPOSAL_FILENAME} --committer-date-is-author-date --no-gpg-sign +git apply ${PROPOSAL_FILENAME} + +echo "=== git add files" +git add --all + +echo "=== git commit " +git commit -m "${PROPOSAL_DESCRIPTION}" echo "=== Run CI" mix git_hooks.run pre_push