From e693d5497c69b7384ba28b6a55775419be493026 Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Wed, 26 Feb 2020 14:49:56 -0500 Subject: [PATCH] Add possibility to run .cicd scripts from different environments ### With FORCE_LINUX=true, you can run the Docker version in `build.sh` an `package.sh` scripts When running the scripts from Mac OS X, it was always picking up the Darwin conditional paths in the script. `FORCE_LINUX=true` can be used on a Mac OS X environment to run the scripts. ### Fix shell expansion in `package.sh` In the packaging script, there is a Docker pre command that add executable bit permission on *.sh scripts in the `build/packages` folder. However, without the escaping, the shell expansion was performed in the `package.sh` script execution directly instead of being delayed so that the expansion is performed inside the `docker run` call! I suspect this worked in your CI system because execution of `package.sh` in performed in such way that filesystem layout of `package.sh` and filesystem layout of `docker run` were the same and as such, the expanded `chmod 755 file1.sh file2.sh` command was correctly working inside the container. The shell expansion via the `*` is now escaped which correctly delays the expansion until it's in the `docker run` execution environment. ### Conditional buildkite-agent upload Now, the upload task is performed only if BUILDKITE env is set to `true`, so it's possible to run the script without having to upload the actual package. --- .cicd/build.sh | 4 +++- .cicd/helpers/file-hash.sh | 2 +- .cicd/package.sh | 12 ++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.cicd/build.sh b/.cicd/build.sh index a8c645fd9..db21d424a 100755 --- a/.cicd/build.sh +++ b/.cicd/build.sh @@ -3,7 +3,7 @@ set -eo pipefail . ./.cicd/helpers/general.sh mkdir -p $BUILD_DIR CMAKE_EXTRAS="-DCMAKE_BUILD_TYPE='Release' -DENABLE_MULTIVERSION_PROTOCOL_TEST=true -DBUILD_MONGO_DB_PLUGIN=true" -if [[ "$(uname)" == 'Darwin' ]]; then +if [[ "$(uname)" == 'Darwin' && $FORCE_LINUX != true ]]; then # You can't use chained commands in execute if [[ "$GITHUB_ACTIONS" == 'true' ]]; then export PINNED=false @@ -39,6 +39,8 @@ else # Linux elif [[ "$GITHUB_ACTIONS" == 'true' ]]; then ARGS="$ARGS -e JOBS" COMMANDS="$BUILD_COMMANDS" + else + COMMANDS="$BUILD_COMMANDS" fi . $HELPERS_DIR/file-hash.sh $CICD_DIR/platforms/$PLATFORM_TYPE/$IMAGE_TAG.dockerfile COMMANDS="$PRE_COMMANDS && $COMMANDS" diff --git a/.cicd/helpers/file-hash.sh b/.cicd/helpers/file-hash.sh index 6297ea920..de6d81b10 100755 --- a/.cicd/helpers/file-hash.sh +++ b/.cicd/helpers/file-hash.sh @@ -4,4 +4,4 @@ set -eo pipefail FILE_NAME=$(basename $1 | awk '{split($0,a,/\.(d|s)/); print a[1] }') export DETERMINED_HASH=$(sha1sum $1 | awk '{ print $1 }') export HASHED_IMAGE_TAG="eos-${FILE_NAME}-${DETERMINED_HASH}" -export FULL_TAG="eosio/ci:$HASHED_IMAGE_TAG" \ No newline at end of file +export FULL_TAG="${IMAGE_NAME:-"eosio/ci"}:$HASHED_IMAGE_TAG" diff --git a/.cicd/package.sh b/.cicd/package.sh index 7376744e5..9e4afd2f9 100755 --- a/.cicd/package.sh +++ b/.cicd/package.sh @@ -2,12 +2,14 @@ set -eo pipefail . ./.cicd/helpers/general.sh mkdir -p $BUILD_DIR -if [[ $(uname) == 'Darwin' ]]; then +if [[ $(uname) == 'Darwin' && $FORCE_LINUX != true ]]; then bash -c "cd build/packages && chmod 755 ./*.sh && ./generate_package.sh brew" ARTIFACT='*.rb;*.tar.gz' cd build/packages [[ -d x86_64 ]] && cd 'x86_64' # backwards-compatibility with release/1.6.x - buildkite-agent artifact upload "./$ARTIFACT" --agent-access-token $BUILDKITE_AGENT_ACCESS_TOKEN + if [[ "$BUILDKITE" == 'true' ]]; then + buildkite-agent artifact upload "./$ARTIFACT" --agent-access-token $BUILDKITE_AGENT_ACCESS_TOKEN + fi for A in $(echo $ARTIFACT | tr ';' ' '); do if [[ $(ls $A | grep -c '') == 0 ]]; then echo "+++ :no_entry: ERROR: Expected artifact \"$A\" not found!" @@ -19,7 +21,7 @@ if [[ $(uname) == 'Darwin' ]]; then else # Linux ARGS=${ARGS:-"--rm --init -v $(pwd):$MOUNTED_DIR"} . $HELPERS_DIR/file-hash.sh $CICD_DIR/platforms/$PLATFORM_TYPE/$IMAGE_TAG.dockerfile - PRE_COMMANDS="cd $MOUNTED_DIR/build/packages && chmod 755 ./*.sh" + PRE_COMMANDS="cd $MOUNTED_DIR/build/packages && chmod 755 \"./*.sh\"" if [[ "$IMAGE_TAG" =~ "ubuntu" ]]; then ARTIFACT='*.deb' PACKAGE_TYPE='deb' @@ -34,7 +36,9 @@ else # Linux eval docker run $ARGS $(buildkite-intrinsics) $FULL_TAG bash -c \"$COMMANDS\" cd build/packages [[ -d x86_64 ]] && cd 'x86_64' # backwards-compatibility with release/1.6.x - buildkite-agent artifact upload "./$ARTIFACT" --agent-access-token $BUILDKITE_AGENT_ACCESS_TOKEN + if [[ "$BUILDKITE" == 'true' ]]; then + buildkite-agent artifact upload "./$ARTIFACT" --agent-access-token $BUILDKITE_AGENT_ACCESS_TOKEN + fi for A in $(echo $ARTIFACT | tr ';' ' '); do if [[ $(ls $A | grep -c '') == 0 ]]; then echo "+++ :no_entry: ERROR: Expected artifact \"$A\" not found!"