Skip to content

Commit

Permalink
improve test plugins build script (rancher#10102)
Browse files Browse the repository at this point in the history
* improve test plugins build script to test extension build with newly built version of the shell package

* uncomment code

* uncomment code

* fix clone permissions issue + add missing registry variables

* revert changes

* revert changes

* address pr comments + delete unwanted code

---------

Co-authored-by: Alexandre Alves <[email protected]>
  • Loading branch information
aalves08 and Alexandre Alves authored Dec 6, 2023
1 parent e2149a4 commit 0abdbfa
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions shell/scripts/test-plugins-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ echo "Checking plugin build"
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
BASE_DIR="$( cd $SCRIPT_DIR && cd ../.. & pwd)"
SHELL_DIR=$BASE_DIR/shell/
SHELL_VERSION="99.99.99"
DEFAULT_YARN_REGISTRY="https://registry.npmjs.org"
VERDACCIO_YARN_REGISTRY="http://localhost:4873"

echo ${SCRIPT_DIR}

Expand Down Expand Up @@ -66,7 +69,7 @@ else
rm -rf ~/.config/verdaccio/storage/@rancher/*
fi

export YARN_REGISTRY=http://localhost:4873
export YARN_REGISTRY=$VERDACCIO_YARN_REGISTRY
export NUXT_TELEMETRY_DISABLED=1

# Remove test package from previous run, if present
Expand All @@ -75,12 +78,12 @@ rm -rf ${BASE_DIR}/pkg/test-pkg
# We need to patch the version number of the shell, otherwise if we are running
# with the currently published version, things will fail as those versions
# are already published and Verdaccio will check, since it is a read-through cache
sed -i.bak -e "s/\"version\": \"[0-9]*.[0-9]*.[0-9]*\",/\"version\": \"7.7.7\",/g" ${SHELL_DIR}/package.json
sed -i.bak -e "s/\"version\": \"[0-9]*.[0-9]*.[0-9]*\",/\"version\": \"${SHELL_VERSION}\",/g" ${SHELL_DIR}/package.json
rm ${SHELL_DIR}/package.json.bak

# Same as above for Rancher Components
# We might have bumped the version number but its not published yet, so this will fail
sed -i.bak -e "s/\"version\": \"[0-9]*.[0-9]*.[0-9]*\",/\"version\": \"7.7.7\",/g" ${BASE_DIR}/pkg/rancher-components/package.json
sed -i.bak -e "s/\"version\": \"[0-9]*.[0-9]*.[0-9]*\",/\"version\": \"${SHELL_VERSION}\",/g" ${BASE_DIR}/pkg/rancher-components/package.json

# Publish shell
echo "Publishing shell packages to local registry"
Expand Down Expand Up @@ -145,4 +148,59 @@ cp ${SHELL_DIR}/list/catalog.cattle.io.clusterrepo.vue ./pkg/test-pkg/list
FORCE_COLOR=true yarn build-pkg test-pkg | cat
rm -rf ./pkg/test-pkg

# function to clone repos and install dependencies (including the newly published shell version)
function clone_repo_test_extension_build() {
REPO_NAME=$1
PKG_NAME=$2

echo -e "\nSetting up $REPO_NAME repository locally\n"

# set registry to default (to install all of the other dependencies)
yarn config set registry ${DEFAULT_YARN_REGISTRY}

rm -rf ${BASE_DIR}/$REPO_NAME

# cloning repo
git clone https://github.com/rancher/$REPO_NAME.git
pushd ${BASE_DIR}/$REPO_NAME

echo -e "\nInstalling dependencies for $REPO_NAME\n"
yarn install

# set registry to local verdaccio (to install new shell)
yarn config set registry ${VERDACCIO_YARN_REGISTRY}

# update package.json to use a specific version of shell
sed -i.bak -e "s/\"\@rancher\/shell\": \"[0-9]*.[0-9]*.[0-9]*\",/\"\@rancher\/shell\": \"${SHELL_VERSION}\",/g" package.json
rm package.json.bak

# we need to remove yarn.lock, otherwise it would install a version that we don't want
rm yarn.lock

echo -e "\nInstalling newly built shell version\n"

# installing new version of shell
yarn add @rancher/shell@${SHELL_VERSION}

# test build-pkg
FORCE_COLOR=true yarn build-pkg $PKG_NAME | cat

# kubewarden has some unit tests and they should be quick to run... Let's check them as well
if [ "${REPO_NAME}" == "kubewarden-ui" ]; then
yarn test:ci
fi

# return back to the base path
popd

# delete folder
rm -rf ${BASE_DIR}/$REPO_NAME
yarn config set registry ${DEFAULT_YARN_REGISTRY}
}

# Here we just add the extension that we want to include as a check (all our official extensions should be included here)
# Don't forget to add the unit tests exception to clone_repo_test_extension_build function if a new extension has those
clone_repo_test_extension_build "kubewarden-ui" "kubewarden"
clone_repo_test_extension_build "elemental-ui" "elemental"

echo "All done"

0 comments on commit 0abdbfa

Please sign in to comment.