diff --git a/build-scripts/bootstrap-tarballs b/build-scripts/bootstrap-tarballs index f9ba45f91..bb24fd9bd 100755 --- a/build-scripts/bootstrap-tarballs +++ b/build-scripts/bootstrap-tarballs @@ -1,106 +1,169 @@ -#!/bin/bash -x +#!/bin/bash + +# This script is supposed generate tarballs from the core & masterfiles +# repositories. We also use these tarballs later in the build process to make +# sure that they actually work. +# +# Currently this script also fetches pull request info and installs PHP and +# javascript dependencies. This core really does not belong here. Created a +# ticket move it (see ENT-13064). +# +# You will first need to run the autogen script. E.g.: +# PROJECT=community ./buildscripts/build-scripts/autogen +# Then you can run it like this: +# BUILD_TYPE=DEBUG ./buildscripts/build-scripts/bootstrap-tarballs +# +# The script expects the following repositories to be side by side: +# . +# ├── buildscripts +# ├── core +# ├── enterprise +# ├── nova +# ├── mission-portal +# ├── libntech +# └── masterfiles +# _dir=$(readlink -e "$(dirname "$0")") # refactored a few functions into single file scripts for easier development/debugging, see ENT-12741 and ENT-12595 # Easier to add a path to a script than source a file of functions. export PATH="$_dir"/bin:$PATH -. `dirname "$0"`/functions +. "$(dirname "$0")"/functions . detect-environment . compile-options . version -mkdir -p $BASEDIR/output/tarballs +mkdir -p "$BASEDIR"/output/tarballs # the first part of the script is not really critical set +e -# Get information about PRs among the used revisions. -# These PRs will have to be notified of build progress. +# Get information about PRs among the used revisions. These PRs will have to be +# notified of build progress. +# +# Variables such as MISSION_PORTAL_REV may be set by the CI (Jenkins) to build +# and test multiple PR's together. The variables typically hold a branch name +# or a pull request ID. PR IDs are preceded by 'pull' or 'origin/pull'. E.g.: +# - MISSION_PORTAL_REV=pull/1755 +# - MISSION_PORTAL_REV=origin/pull/1755 +# where the trailing number is the pull request ID. +# +# This loop fetches information about the PRs if the respective variable is set. +# for repo_spec in cfengine/buildscripts cfengine/core cfengine/masterfiles cfengine/enterprise cfengine/nova cfengine/mission-portal NorthernTechHQ/libntech; do # remove organization/ from start of repo_spec + # E.g. 'cfengine/mission-portal' -> 'mission-portal' repo="${repo_spec#*/}" - rev_param_name="$(echo $repo | tr '[:lower:]-' '[:upper:]_')_REV" - revision="$(echo ${!rev_param_name})" || continue # dereference + + # Convert to uppercase, swap hyphens with underscore and append '_REV' + # E.g. 'mission-portal' -> 'MISSION_PORTAL_REV' + rev_param_name="$(echo "$repo" | tr '[:lower:]-' '[:upper:]_')_REV" + + # Try to dereference the result from above and skip the rest of the loop + # unless the variable is defined. + revision="${!rev_param_name}" || continue # remove "origin/" (if any) revision="${revision##origin/}" + + # Check to see if the resolved variable starts with 'pull/' if expr "$revision" : "pull/" >/dev/null; then - pr_nr="$(echo $revision | cut -d/ -f2)" - get-github-pull-request-info "$repo_spec" "$pr_nr" >> $BASEDIR/output/PRs + # Extract the revision number. E.g. 'pull/1755' -> '1755' + pr_nr="$(echo "$revision" | cut -d/ -f2)" + + get-github-pull-request-info "$repo_spec" "$pr_nr" >> "$BASEDIR"/output/PRs fi done # now script failures should fail the script set -e -cd $BASEDIR/core -rm cfengine-3.*.tar.gz || true -git rev-parse HEAD > $BASEDIR/output/core-commitID +# Build tarball from core repository +cd "$BASEDIR"/core +rm -f cfengine-3.*.tar.gz +git rev-parse HEAD > "$BASEDIR"/output/core-commitID # Configure in order to run "make dist", deleted later. -./configure -C -make dist -mv cfengine-3.*.tar.gz $BASEDIR/output/tarballs/ -make distclean - -cd $BASEDIR/masterfiles -rm cfengine-masterfiles*.tar.gz || true -git rev-parse HEAD > $BASEDIR/output/masterfiles-commitID +echo "$(basename "$0"): Debug: Running configure on core repository..." +run_and_print_on_failure ./configure -C +echo "$(basename "$0"): Debug: Running make dist on core repository..." +run_and_print_on_failure make dist +mv cfengine-3.*.tar.gz "$BASEDIR"/output/tarballs/ +echo "$(basename "$0"): Debug: Running make distclean on core repository..." +run_and_print_on_failure make distclean + +# Build tarballs from masterfiles repository +cd "$BASEDIR"/masterfiles +rm -f cfengine-masterfiles*.tar.gz +git rev-parse HEAD > "$BASEDIR"/output/masterfiles-commitID # Configure in order to run "make dist", deleted later. -./configure -make dist # source tarball -make tar-package # package tarball -mv cfengine-masterfiles*.tar.gz $BASEDIR/output/tarballs/ -make distclean - -cd $BASEDIR/output/tarballs -sha256sum *.tar.gz > sha256sums.txt -CKSUM=`sum sha256sums.txt | cut -d ' ' -f 1` -mv sha256sums.txt sha256sums.$CKSUM.txt - +echo "$(basename "$0"): Debug: Running configure on masterfiles repository..." +run_and_print_on_failure ./configure +echo "$(basename "$0"): Debug: Running make dist on masterfiles repository..." +run_and_print_on_failure make dist # source tarball +echo "$(basename "$0"): Debug: Running make tar-package on masterfiles repository..." +run_and_print_on_failure make tar-package # package tarball (containing all + # files as if they were installed + # under "prefix".) +mv cfengine-masterfiles*.tar.gz "$BASEDIR"/output/tarballs/ +echo "$(basename "$0"): Debug: Running make distclean on masterfiles repository..." +run_and_print_on_failure make distclean + +# Compute a checksum list that can be used to verify the integrity of the +# tarballs +cd "$BASEDIR"/output/tarballs +sha256sum -- *.tar.gz > sha256sums.txt +# Add the BSD (16-bit) checksum of the checksum list to it's filename. This way +# you can verify the integrity of the checksum list itself. +CKSUM=$(sum sha256sums.txt | cut -d ' ' -f 1) +mv sha256sums.txt sha256sums."$CKSUM".txt + +echo "$(basename "$0"): Debug: Installing javascript dependencies..." ( -if test -f "$BASEDIR/mission-portal/public/scripts/package.json"; then - cd $BASEDIR/mission-portal/public/scripts +if test -f "$BASEDIR"/mission-portal/public/scripts/package.json; then + cd "$BASEDIR"/mission-portal/public/scripts # display node & npm versions npm --version node --version # install dependencies from npmjs - npm ci --prefix $BASEDIR/mission-portal/public/scripts/ + run_and_print_on_failure npm ci --prefix "$BASEDIR"/mission-portal/public/scripts/ # build react components - npm run build --prefix $BASEDIR/mission-portal/public/scripts/ + run_and_print_on_failure npm run build --prefix "$BASEDIR"/mission-portal/public/scripts/ # remove the packages specified in devDependencies - npm prune --omit=dev --prefix $BASEDIR/mission-portal/public/scripts/ - + run_and_print_on_failure npm prune --omit=dev --prefix "$BASEDIR"/mission-portal/public/scripts/ fi ) +echo "$(basename "$0"): Debug: Installing PHP dependencies from mission-portal repository..." ( -if test -f "$BASEDIR/mission-portal/composer.json"; then - cd $BASEDIR/mission-portal +if test -f "$BASEDIR"/mission-portal/composer.json; then + cd "$BASEDIR"/mission-portal # install PHP dependencies from composer - php /usr/bin/composer.phar install --no-dev + run_and_print_on_failure php /usr/bin/composer.phar install --no-dev fi ) +echo "$(basename "$0"): Debug: Installing PHP dependencies from nova repository..." ( -if test -f "$BASEDIR/nova/api/http/composer.json"; then - cd $BASEDIR/nova/api/http +if test -f "$BASEDIR"/nova/api/http/composer.json; then + cd "$BASEDIR"/nova/api/http # install PHP dependencies from composer - php /usr/bin/composer.phar install --no-dev --ignore-platform-reqs + run_and_print_on_failure php /usr/bin/composer.phar install --no-dev --ignore-platform-reqs fi ) +echo "$(basename "$0"): Debug: Compiling Mission Portal styles..." ( -if test -f "$BASEDIR/mission-portal/public/themes/default/bootstrap/cfengine_theme.less"; then - cd $BASEDIR/mission-portal/public/themes/default/bootstrap - npx -p less lessc --compress ./cfengine_theme.less ./compiled/css/cfengine.less.css +if test -f "$BASEDIR"/mission-portal/public/themes/default/bootstrap/cfengine_theme.less; then + cd "$BASEDIR"/mission-portal/public/themes/default/bootstrap + run_and_print_on_failure npx -p less lessc --compress ./cfengine_theme.less ./compiled/css/cfengine.less.css fi ) +echo "$(basename "$0"): Debug: Installing LDAP API dependencies..." ( -if test -f "$BASEDIR/mission-portal/ldap/composer.json"; then - cd $BASEDIR/mission-portal/ldap +if test -f "$BASEDIR"/mission-portal/ldap/composer.json; then + cd "$BASEDIR"/mission-portal/ldap # install PHP dependencies from composer - php /usr/bin/composer.phar install --no-dev + run_and_print_on_failure php /usr/bin/composer.phar install --no-dev fi ) -