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

CI: add MANUAL_BUILD tests #358

Merged
merged 9 commits into from
Oct 15, 2023
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
14 changes: 14 additions & 0 deletions .github/workflows/godwoken-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ on:

jobs:
godwoken-tests:
strategy:
fail-fast: false
matrix:
MANUAL_BUILD_GODWOKEN: ["true", "false"]
MANUAL_BUILD_WEB3: ["true", "false"]
MANUAL_BUILD_WEB3_INDEXER: ["true", "false"]
MANUAL_BUILD_POLYJUICE: ["true", "false"]
MANUAL_BUILD_SCRIPTS: ["true", "false"]

uses: godwokenrises/godwoken-tests/.github/workflows/reusable-integration-test-v1.yml@develop
with:
extra_github_env: |
GODWOKEN_KICKER_REPO=${{ github.repository }}
GODWOKEN_KICKER_REF=${{ github.ref }}
MANUAL_BUILD_GODWOKEN=${{ matrix.MANUAL_BUILD_GODWOKEN }}
MANUAL_BUILD_WEB3=${{ matrix.MANUAL_BUILD_WEB3 }}
MANUAL_BUILD_WEB3_INDEXER=${{ matrix.MANUAL_BUILD_WEB3_INDEXER }}
MANUAL_BUILD_POLYJUICE=${{ matrix.MANUAL_BUILD_POLYJUICE }}
MANUAL_BUILD_SCRIPTS=${{ matrix.MANUAL_BUILD_SCRIPTS }}
2 changes: 2 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
volumes:
- ./redis/data:/data

# TODO: update CKB version
ckb:
image: nervos/ckb:v0.103.0
user: root
Expand All @@ -31,6 +32,7 @@ services:
- ./layer1/ckb:/var/lib/ckb
command: [ "run", "-C", "/var/lib/ckb" ]

# TODO: update CKB version
ckb-miner:
init: true
image: nervos/ckb:v0.103.0
Expand Down
112 changes: 78 additions & 34 deletions kicker
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

set -o errexit

GITHUB_ACTIONS_CLEAN_MID_ARTIFACTS=false
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
if [ "$CI" = "true" ] && [ -n "$GITHUB_RUN_ID" ]; then
echo "This script is running in GitHub Actions. GITHUB_RUN_ID: $GITHUB_RUN_ID"

# Diskspace is limited in GitHub Actions, so we need to manually clean the middle artifacts
GITHUB_ACTIONS_CLEAN_MID_ARTIFACTS=true
fi

EXECUTABLE=$0
WORKSPACE="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

Expand Down Expand Up @@ -415,38 +424,53 @@ function withdraw_v0_to_v1() {
# GODWOKEN_GIT_CHECKOUT=develop \
# ./kicker manual-build
function manual_build() {
DOCKER_MANUAL_BUILD_IMAGE_NAME=${DOCKER_MANUAL_BUILD_IMAGE_NAME:-"retricsu/godwoken-manual-build"}
DOCKER_MANUAL_BUILD_IMAGE_TAG=${DOCKER_MANUAL_BUILD_IMAGE_TAG:-"node18"}
DOCKER_MANUAL_BUILD_IMAGE="${DOCKER_MANUAL_BUILD_IMAGE:-"$DOCKER_MANUAL_BUILD_IMAGE_NAME:$DOCKER_MANUAL_BUILD_IMAGE_TAG"}"

WEB3_GIT_URL=${WEB3_GIT_URL:-"https://github.com/godwokenrises/godwoken"}
WEB3_GIT_CHECKOUT=${WEB3_GIT_CHECKOUT:-"develop"}
echo "MANUAL_BUILD_WEB3 = \"$MANUAL_BUILD_WEB3\""
echo "WEB3_GIT_URL = \"$WEB3_GIT_URL\""
echo "WEB3_GIT_CHECKOUT = \"$WEB3_GIT_CHECKOUT\""
echo "MANUAL_BUILD_WEB3_INDEXER = \"$MANUAL_BUILD_WEB3_INDEXER\""

GODWOKEN_GIT_URL=${GODWOKEN_GIT_URL:-"https://github.com/godwokenrises/godwoken"}
GODWOKEN_GIT_CHECKOUT=${GODWOKEN_GIT_CHECKOUT:-"develop"}
echo "MANUAL_BUILD_GODWOKEN = \"$MANUAL_BUILD_GODWOKEN\""
echo "GODWOKEN_GIT_URL = \"$GODWOKEN_GIT_URL\""
echo "GODWOKEN_GIT_CHECKOUT = \"$GODWOKEN_GIT_CHECKOUT\""

SCRIPTS_GIT_URL=${SCRIPTS_GIT_URL:-"https://github.com/godwokenrises/godwoken"}
SCRIPTS_GIT_CHECKOUT=${SCRIPTS_GIT_CHECKOUT:-"develop"}
echo "MANUAL_BUILD_SCRIPTS = \"$MANUAL_BUILD_SCRIPTS\""
echo "SCRIPTS_GIT_URL = \"$SCRIPTS_GIT_URL\""
echo "SCRIPTS_GIT_CHECKOUT = \"$SCRIPTS_GIT_CHECKOUT\""

echo "OMNI_LOCK_GIT_URL = \"$OMNI_LOCK_GIT_URL\""
echo "OMNI_LOCK_GIT_CHECKOUT = \"$OMNI_LOCK_GIT_CHECKOUT\""

POLYJUICE_GIT_URL=${POLYJUICE_GIT_URL:-"https://github.com/godwokenrises/godwoken"}
POLYJUICE_GIT_CHECKOUT=${POLYJUICE_GIT_CHECKOUT:-"develop"}
echo "MANUAL_BUILD_POLYJUICE = \"$MANUAL_BUILD_POLYJUICE\""
echo "POLYJUICE_GIT_URL = \"$POLYJUICE_GIT_URL\""
echo "POLYJUICE_GIT_CHECKOUT = \"$POLYJUICE_GIT_CHECKOUT\""

DOCKER_MANUAL_BUILD_IMAGE_NAME=${DOCKER_MANUAL_BUILD_IMAGE_NAME:-"retricsu/godwoken-manual-build"}
DOCKER_MANUAL_BUILD_IMAGE_TAG=${DOCKER_MANUAL_BUILD_IMAGE_TAG:-"node18"}
DOCKER_MANUAL_BUILD_IMAGE="${DOCKER_MANUAL_BUILD_IMAGE:-"$DOCKER_MANUAL_BUILD_IMAGE_NAME:$DOCKER_MANUAL_BUILD_IMAGE_TAG"}"
echo "DOCKER_MANUAL_BUILD_IMAGE = \"$DOCKER_MANUAL_BUILD_IMAGE\""
echo

info "Start building..." | tee /tmp/kicker.log
du -hd6 $WORKSPACE | egrep G | tee --append /tmp/kicker.log

if [ "$MANUAL_BUILD_WEB3" = "true" ]; then
info "Start building godwoken-web3"

# godwoken-web3 is managed in the Godwoken monorepo.
# See https://github.com/godwokenrises/godwoken/tree/develop/web3
srcdir=$WORKSPACE/packages/godwoken-web3/web3
srcdir=$WORKSPACE/packages/godwoken/web3
dstdir=$WORKSPACE/docker/manual-artifacts/godwoken-web3

# Download repo
prepare_repo godwoken-web3 "$WEB3_GIT_URL" "$WEB3_GIT_CHECKOUT"
prepare_repo godwoken "$WEB3_GIT_URL" "$WEB3_GIT_CHECKOUT"

# Yarn install via docker (assumes the "web3" docker-compose service installed yarn)

Expand All @@ -471,41 +495,47 @@ function manual_build() {
$srcdir/node_modules \
$srcdir/yarn.lock \
$dstdir

if [[ "$GITHUB_ACTIONS_CLEAN_MID_ARTIFACTS" = "true" ]]; then
erun sudo rm -rf $srcdir/node_modules
fi
else
info "skip building godwoken-web3"
fi

if [ "$MANUAL_BUILD_WEB3_INDEXER" = "true" ]; then
info "Start building godwoken-web3-indexer"

srcdir=$WORKSPACE/packages/godwoken-web3
srcdir=$WORKSPACE/packages/godwoken
dstdir=$WORKSPACE/docker/manual-artifacts

# Download repo
prepare_repo godwoken-web3 "$WEB3_GIT_URL" "$WEB3_GIT_CHECKOUT"
prepare_repo godwoken "$WEB3_GIT_URL" "$WEB3_GIT_CHECKOUT"

# Cargo fetch Rust dependencies (in order to access network via
# host network). The docker image must have installed cargo, molecule
# and rustfmt.
erun "cd $srcdir/web3 && CARGO_HOME=$srcdir/web3/.cargo cargo fetch --locked && cd -"
erun docker run \
--rm \
--env CARGO_HOME=/app/.cargo \
erun "cd $srcdir/web3 && CARGO_HOME=$WORKSPACE/packages/.cargo cargo fetch --locked && cd -"

erun docker run --rm \
--workdir /app/web3 \
--volume $srcdir:/app \
--volume $WORKSPACE/packages/.rustup:/root/.rustup \
--workdir /app/web3 \
retricsu/godwoken-manual-build:ckb2021 cargo build --locked --release
--volume $WORKSPACE/packages/.cargo:/root/.cargo \
$DOCKER_MANUAL_BUILD_IMAGE cargo build --locked

# Copy the built artifacts to `docker/manual-artifacts/gw-web3-indexer`
#
# More: ./docker/manual-web3-indexer.compose.yml
erun mkdir -p $dstdir
erun cp $srcdir/web3/target/release/gw-web3-indexer $dstdir
erun cp $srcdir/web3/target/debug/gw-web3-indexer $dstdir

# Remove Rust target to avoid `out of disk` issue in CI
sudo rm -rf $srcdir/web3/target/release
if [[ "$GITHUB_ACTIONS_CLEAN_MID_ARTIFACTS" = "true" ]]; then
sudo rm -rf $srcdir/web3/target
fi
else
info "skip building godwoken-web3-indexer(gw-web3-indexer)"
info "skip building godwoken-web3-indexer (gw-web3-indexer)"
fi

if [ "$MANUAL_BUILD_GODWOKEN" = "true" ]; then
Expand All @@ -519,29 +549,32 @@ function manual_build() {

# Cargo fetch Rust dependencies (in order to access network via
# host network).
erun "cd $srcdir && CARGO_HOME=$WORKSPACE/packages/.cargo cargo fetch --locked && cd -"

# Note:
# 1. The docker image must have installed cargo and molecule
# 2. The builtin consensus config and binaries are not required on a
# Godwoken devnet, so `--features gw-config/no-builtin` is appended
# to `cargo build` arguments.
erun docker run \
--rm \
--env CARGO_HOME=/app/.cargo \
erun docker run --rm \
--workdir /app \
--volume $srcdir:/app \
--volume $WORKSPACE/packages/.rustup:/root/.rustup \
--workdir /app \
retricsu/godwoken-manual-build:ckb2021 \
cargo build --locked --release --features gw-config/no-builtin
--volume $WORKSPACE/packages/.cargo:/root/.cargo \
$DOCKER_MANUAL_BUILD_IMAGE \
cargo build --locked --features gw-config/no-builtin

# Copy the built artifacts to `docker/manual-artifacts/`
#
# More: ./docker/manual-godwoken.compose.yml
erun mkdir -p $dstdir
erun cp $srcdir/target/release/godwoken $dstdir
erun cp $srcdir/target/release/gw-tools $dstdir
erun cp $srcdir/target/debug/godwoken $dstdir
erun cp $srcdir/target/debug/gw-tools $dstdir

# Remove Rust target to avoid `out of disk` issue in CI
sudo rm -rf $srcdir/target/release
if [[ "$GITHUB_ACTIONS_CLEAN_MID_ARTIFACTS" = "true" ]]; then
sudo rm -rf $srcdir/target
fi
else
info "skip building Godwoken"
fi
Expand All @@ -551,7 +584,7 @@ function manual_build() {
dstdir=$WORKSPACE/docker/manual-artifacts/polyjuice/

# Download repo
prepare_repo godwoken-polyjuice "$POLYJUICE_GIT_URL" "$POLYJUICE_GIT_CHECKOUT"
prepare_repo godwoken "$POLYJUICE_GIT_URL" "$POLYJUICE_GIT_CHECKOUT"

cd $srcdir
erun make all-via-docker
Expand All @@ -568,13 +601,15 @@ function manual_build() {
dstdir=$WORKSPACE/docker/manual-artifacts/scripts/

# Download repo
prepare_repo godwoken-scripts "$SCRIPTS_GIT_URL" "$SCRIPTS_GIT_CHECKOUT"
prepare_repo godwoken "$SCRIPTS_GIT_URL" "$SCRIPTS_GIT_CHECKOUT"

# Install capsule
# TODO: use cpasule from godwoken-manual-build image
if [ -z "$(command -v capsule)" ]; then
erun cargo install ckb-capsule
fi
# Fixme: error: Incompatible capsule version 0.10.1, this project requires a version that's compatible with 0.7.0
CAPSULE_VERSION=0.7.0
export CARGO_HOME=$WORKSPACE/packages/.cargo
(which capsule && test "$(capsule --version)" = "Capsule $CAPSULE_VERSION") \
|| erun cargo install ckb-capsule --version $CAPSULE_VERSION --force
$WORKSPACE/packages/.cargo/bin/capsule --version

erun cd $srcdir/c \&\& erun make all-via-docker
erun cd $srcdir \&\& capsule build --release --debug-output
Expand All @@ -587,14 +622,23 @@ function manual_build() {

# Copy the prebuild omni-lock to `docker/manual-artifacts/`
erun $DOCKER_COMPOSE -f $WORKSPACE/docker/docker-compose.yml run \
--rm \
--no-deps \
--rm --no-deps \
--volume=$dstdir:/godwoken-scripts \
--entrypoint "\"bash -c 'cp /scripts/godwoken-scripts/omni_lock /godwoken-scripts/omni_lock'\"" \
godwoken
else
info "skip building Scripts"
fi

if [[ "$GITHUB_ACTIONS_CLEAN_MID_ARTIFACTS" = "true" ]]; then
docker images --format '{{.Repository}}:{{.Tag}}' \
| grep '$DOCKER_MANUAL_BUILD_IMAGE' | xargs docker rmi \
&& echo "Image removed." \
|| echo "Image does not exist."
fi

info "End building." | tee --append /tmp/kicker.log
du -hd6 $WORKSPACE | egrep G | tee --append /tmp/kicker.log
}

function prepare_repo() {
Expand Down
Loading