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

Fixing ci scripts and linking between reaching minimal amount of approvals and CI #924

Merged
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: 16 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand Down
26 changes: 20 additions & 6 deletions lib/archethic/governance/code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
21 changes: 18 additions & 3 deletions lib/archethic/governance/code/cicd/docker/cicd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
35 changes: 0 additions & 35 deletions scripts/governance/mk-code-proposal.sh

This file was deleted.

11 changes: 9 additions & 2 deletions scripts/governance/proposal_ci_job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down