From aa508028036ea01683b07cb9fc2812dc35bc9b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Fri, 7 Sep 2018 17:18:29 +0200 Subject: Add fake laminar execution possibility --- fakelaminar | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ job.common | 22 ++++++++++++++++++++ jobs/alpine-amd64.run | 3 +-- scripts/common | 23 --------------------- templates/turris3x.run | 3 +-- templates/turris4x.run | 3 +-- 6 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 fakelaminar create mode 100644 job.common delete mode 100644 scripts/common diff --git a/fakelaminar b/fakelaminar new file mode 100644 index 0000000..4401960 --- /dev/null +++ b/fakelaminar @@ -0,0 +1,55 @@ +# vim: ft=sh +# Fake laminar environment to be able to do test run on any host + +# Make sure that we are running this script with absolute path +echo "$0" | grep -q '^/' || exec "$(pwd)/$0" + +# Add path to scripts +export PATH="$(dirname "$(readlink -f "$0")")/../scripts:$PATH" + +# Note: Changing home variable relly changes home directory to local laminar-fake. +# This does not work for all commands and specially for ssh it does not but we +# require this because thanks to that we don't have to setup ssh configuration +# copy. +export HOME="$PWD/laminar-fake" +mkdir -p "$HOME" + +# Create link to configuration directory +rm -f "$HOME/cfg" +ln -s "$(dirname $(readlink -f "$0"))/.." "$HOME/cfg" + +# Get name of the job from script name +export JOB="$(basename "$0" | sed 's/\.run$//')" + +JOBDIR="$HOME/run/$JOB" +mkdir -p "$JOBDIR" + +# Set run number +export RUN="$(ls "$JOBDIR" | sed -n '/^[0-9]\+$/p' | sort --numeric-sort | tail -1)" +RUN="${RUN:-0}" +RUN="$(expr "$RUN" + 1)" +# Create directory for this run +mkdir -p "$JOBDIR/$RUN" +cd "$JOBDIR/$RUN" + +# Set workspace +export WORKSPACE="$JOBDIR/workspace" +mkdir -p "$WORKSPACE" + +# Set archive +export ARCHIVE="$HOME/archive/$JOB/$RUN" +mkdir -p "$ARCHIVE" + +# TODO missing variables: RESULT, LAST_RESULT + +# Drop JOBDIR variable +JOBDIR= + + +# Fake laminarc command +laminarc() { + # TODO this is currently not supported but we should implement it in future. + false +} + +echo "========== Laminar environment is faked ==========" diff --git a/job.common b/job.common new file mode 100644 index 0000000..ebe6ab1 --- /dev/null +++ b/job.common @@ -0,0 +1,22 @@ +# vim: ft=sh +set -e +if [ -z "$WORKSPACE" ]; then + . "$(dirname "$(readlink -f "$0")")/../fakelaminar" +fi + +# Subprocess inclusion guard +[ -z "$LAMINAR_COMMON" ] +export LAMINAR_COMMON=y + +# Job and template id +export JOBID="$(basename "$0" | sed 's/\.run$//')" +export TEMPLATEID="$(basename "$(readlink -f "$0")" | sed 's/\.run$//')" + +# Template workspace +export TWORKSPACE="$HOME/workspace/$TEMPLATEID" +if [ "$JOBID" = "$TEMPLATEID" ]; then + TWORKSPACE="$HOME/workspace/notemplate" +fi + +# Include utils +. utils diff --git a/jobs/alpine-amd64.run b/jobs/alpine-amd64.run index 80e8644..f9cfbbc 100755 --- a/jobs/alpine-amd64.run +++ b/jobs/alpine-amd64.run @@ -1,7 +1,6 @@ #!/bin/sh # vim: ft=sh -set -e -. common +. "$(dirname "$(readlink -f "$0")")/../job.common" if [ -n "$CLEAN" ]; then echo_stage "Remove root" diff --git a/scripts/common b/scripts/common deleted file mode 100644 index 7514ea9..0000000 --- a/scripts/common +++ /dev/null @@ -1,23 +0,0 @@ -# vim: ft=sh -# Laminar guard -if [ -z "$WORKSPACE" ]; then - echo "This script can be run only from laminar build environment!" >&2 - exit 1 -fi - -# Subprocess inclusion guard -[ -z "$LAMINAR_COMMON" ] -export LAMINAR_COMMON=y - -# Job and template id -export JOBID="$(basename "$0" | sed 's/\.run$//')" -export TEMPLATEID="$(basename "$(readlink -f "$0")" | sed 's/\.run$//')" - -# Template workspace -export TWORKSPACE="$HOME/workspace/$TEMPLATEID" -if [ "$JOBID" = "$TEMPLATEID" ]; then - TWORKSPACE="$HOME/workspace/notemplate" -fi - -# Include utils -. utils diff --git a/templates/turris3x.run b/templates/turris3x.run index 1327e24..49640cc 100755 --- a/templates/turris3x.run +++ b/templates/turris3x.run @@ -1,7 +1,6 @@ #!/bin/sh # vim: ft=sh -set -e -. common +. "$(dirname "$(readlink -f "$0")")/../job.common" echo_stage "Get packages" git_clone "git@cynerd.cz:openwrt-personal-pkgs" pkgs turris3x diff --git a/templates/turris4x.run b/templates/turris4x.run index a5405b5..5c39008 100755 --- a/templates/turris4x.run +++ b/templates/turris4x.run @@ -1,7 +1,6 @@ #!/bin/sh # vim: ft=sh -set -e -. common +. "$(dirname "$(readlink -f "$0")")/../job.common" if [ "$V" -ge 1 ]; then MAKE="make -j1 IS_TTY=1 BUILD_LOG=1 V=99" -- cgit v1.2.3