diff --git a/kicker b/kicker index a9e0c5e..efc383e 100755 --- a/kicker +++ b/kicker @@ -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 )" @@ -486,6 +495,10 @@ 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 @@ -508,7 +521,8 @@ function manual_build() { --workdir /app/web3 \ --volume $srcdir:/app \ --volume $WORKSPACE/packages/.rustup:/root/.rustup \ - --env CARGO_HOME=$WORKSPACE/packages/.cargo \ + --volume $WORKSPACE/packages/.cargo:/app/web3/.cargo \ + --env CARGO_HOME=/app/web3/.cargo \ $DOCKER_MANUAL_BUILD_IMAGE cargo build --locked # Copy the built artifacts to `docker/manual-artifacts/gw-web3-indexer` @@ -518,7 +532,9 @@ function manual_build() { 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/target + 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)" fi @@ -534,29 +550,33 @@ 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=$WORKSPACE/packages/.cargo \ + erun docker run --rm \ + --workdir /app \ --volume $srcdir:/app \ --volume $WORKSPACE/packages/.rustup:/root/.rustup \ - --workdir /app \ - godwoken \ - cargo build --locked --release --features gw-config/no-builtin + --volume $WORKSPACE/packages/.cargo:/app/.cargo \ + --env CARGO_HOME=/app/.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 @@ -586,10 +606,12 @@ function manual_build() { 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 @@ -602,8 +624,7 @@ 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 @@ -611,7 +632,12 @@ function manual_build() { info "skip building Scripts" fi - docker rmi $DOCKER_MANUAL_BUILD_IMAGE + 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