diff --git a/.github/workflows/update-semver.yaml b/.github/workflows/update-semver.yaml new file mode 100644 index 0000000..08905b0 --- /dev/null +++ b/.github/workflows/update-semver.yaml @@ -0,0 +1,16 @@ +--- +name: Update Semver + +on: # yamllint disable-line rule:truthy + push: + branches-ignore: + - '**' + tags: + - 'v*.*.*' + +jobs: + update-semver: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rickstaa/action-update-semver@v1 diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..965c481 --- /dev/null +++ b/action.yaml @@ -0,0 +1,68 @@ +--- # allow running scwrypts in Github Actions +name: scwrypts +author: yage +description: check requird dependencies and run a scwrypt + +inputs: + scwrypt: + description: "args / identifiers for scwrypts CLI (e.g. '--name --group --type ')" + required: true + + args: + description: "arguments to pass to the scwrypt-to-be-run" + required: false + + version: + description: "scwrypts version; defaults to latest (minimum v3.7.0)" + required: false + + scwrypts-env: + description: "override value for SCWRYPTS_ENV" + required: false + default: "ci.github-actions" + +runs: + using: composite + steps: + - uses: actions/checkout@v4 + with: + repository: wrynegade/scwrypts + path: ./scwrypts + ref: ${{ inputs.version }} + + - name: check dependencies + shell: bash + env: + CI: true + SCWRYPTS_PLUGIN_ENABLED__ci: 1 + run: | + [ $CI_SCWRYPTS_READY ] && [[ $CI_SCWRYPTS_READY -eq 1 ]] && echo 'setup completed previously' && exit 0 + + echo "updating package dependencies" + { + sudo apt-get update + sudo apt-get install --yes zsh fzf ripgrep + + for D in $($GITHUB_WORKSPACE/scwrypts/scwrypts -n --name check-all-dependencies --group ci --type zsh) + do + echo "--- installing $D ---" + ( sudo apt-get install --yes $D; exit 0; ) + done + } > $HOME/.scwrypts.apt-get.log 2>&1 + + echo "updating virtual dependencies" + $GITHUB_WORKSPACE/scwrypts/scwrypts -n \ + --name scwrypts/virtualenv/update-all \ + --group scwrypts \ + --type zsh \ + > $HOME/.scwrypts.virtualenv.log 2>&1 + + echo "CI_SCWRYPTS_READY=1" >> $GITHUB_ENV + exit 0 + + - name: run scwrypt + shell: bash + env: + CI: true + SCWRYPTS_ENV: ${{ inputs.scwrypts-env }} + run: $GITHUB_WORKSPACE/scwrypts/scwrypts ${{inputs.scwrypt}} -- ${{inputs.args}} diff --git a/plugins/ci/.config/env.template b/plugins/ci/.config/env.template new file mode 100644 index 0000000..f7df9c2 --- /dev/null +++ b/plugins/ci/.config/env.template @@ -0,0 +1 @@ +#!/bin/zsh diff --git a/plugins/ci/.config/env.template.descriptions b/plugins/ci/.config/env.template.descriptions new file mode 100644 index 0000000..e69de29 diff --git a/plugins/ci/README.md b/plugins/ci/README.md new file mode 100644 index 0000000..8a40381 --- /dev/null +++ b/plugins/ci/README.md @@ -0,0 +1,10 @@ +# Kubernetes `kubectl` Helper Plugin + +Leverages a local `redis` application to quickly and easily set an alias `k` for `kubectl --context --namespace `. +Much like scwrypts environments, `k` aliases are *only* shared amongst session with the same `SCWRYPTS_ENV` to prevent accidental cross-contamination. + + +## Getting Started + +Enable the plugin in `~/.config/scwrypts/config.zsh` by adding `SCWRYPTS_PLUGIN_ENABLED__KUBECTL=1`. +Use `k` as your new `kubectl` and checkout `k --help` and `k meta --help`. diff --git a/plugins/ci/check-all-dependencies b/plugins/ci/check-all-dependencies new file mode 100755 index 0000000..c245ec9 --- /dev/null +++ b/plugins/ci/check-all-dependencies @@ -0,0 +1,40 @@ +#!/bin/zsh +##################################################################### +DEPENDENCIES+=() +REQUIRED_ENV+=() +##################################################################### + +MAIN() { + cd "$SCWRYPTS_ROOT__scwrypts/" + + DEPENDENCIES+=() + for group in ${SCWRYPTS_GROUPS[@]} + do + [[ $group =~ ^ci$ ]] && continue + + GROUP_HOME="$(eval 'echo $SCWRYPTS_ROOT__'$group)" + [ $GROUP_HOME ] && [ -d "$GROUP_HOME" ] || continue + + STATUS "checking dependencies for $group" + DEPENDENCIES+=($( + for file in $( + { + cd "$GROUP_HOME" + rg -l '^DEPENDENCIES\+=\($' + rg -l '^DEPENDENCIES\+=\([^)]\+\)' + } | grep -v '\.md$' | grep -v 'check-all-dependencies$') + do + sed -z 's/.*DEPENDENCIES+=(\([^)]*\)).*/\1\n/; s/#.*\n//g; s/\s\+/\n/g' "$GROUP_HOME/$file" + done + )) + done + + DEPENDENCIES=(zsh $(echo $DEPENDENCIES | sed 's/ /\n/g' | sort -u | grep '^[-_a-zA-Z]\+$')) + + STATUS "discovered dependencies: ($DEPENDENCIES)" + echo $DEPENDENCIES | sed 's/ /\n/g' + CHECK_ENVIRONMENT && SUCCESS "all dependencies satisfied" +} + +##################################################################### +MAIN $@ diff --git a/plugins/ci/ci.scwrypts.zsh b/plugins/ci/ci.scwrypts.zsh new file mode 100644 index 0000000..7530945 --- /dev/null +++ b/plugins/ci/ci.scwrypts.zsh @@ -0,0 +1,5 @@ +SCWRYPTS_GROUPS+=(ci) + +export SCWRYPTS_TYPE__ci=zsh +export SCWRYPTS_ROOT__ci="$SCWRYPTS_ROOT__scwrypts/plugins/ci" +export SCWRYPTS_COLOR__ci='\033[0m' diff --git a/zsh/helm/get-template b/zsh/helm/get-template new file mode 100755 index 0000000..1467734 --- /dev/null +++ b/zsh/helm/get-template @@ -0,0 +1,17 @@ +#!/bin/zsh +DEPENDENCIES+=() +REQUIRED_ENV+=() + +use helm +use scwrypts + +CHECK_ENVIRONMENT +##################################################################### + +MAIN() { + unset USAGE + HELM__TEMPLATE__GET $@ +} + +##################################################################### +MAIN $@ diff --git a/zsh/helm/update-dependencies b/zsh/helm/update-dependencies new file mode 100755 index 0000000..1aba64e --- /dev/null +++ b/zsh/helm/update-dependencies @@ -0,0 +1,17 @@ +#!/bin/zsh +DEPENDENCIES+=() +REQUIRED_ENV+=() + +use helm +use scwrypts + +CHECK_ENVIRONMENT +##################################################################### + +MAIN() { + unset USAGE + HELM__DEPENDENCY__UPDATE $@ +} + +##################################################################### +MAIN $@ diff --git a/zsh/lib/config.zsh b/zsh/lib/config.zsh index 46d39e1..d683a12 100644 --- a/zsh/lib/config.zsh +++ b/zsh/lib/config.zsh @@ -40,9 +40,12 @@ source "$SCWRYPTS_ROOT/zsh/lib/config.group.zsh" \ ##################################################################### -[[ $SCWRYPTS_PLUGIN_ENABLED__kubectl -eq 1 ]] && { - source "$SCWRYPTS_ROOT/plugins/kubectl/kubectl.scwrypts.zsh" -} +for plugin in $(ls $SCWRYPTS_ROOT__scwrypts/plugins) +do + [[ $(eval 'echo $SCWRYPTS_PLUGIN_ENABLED__'$plugin) -eq 1 ]] && { + source "$SCWRYPTS_ROOT/plugins/$plugin/$plugin.scwrypts.zsh" + } +done ##################################################################### [ $NO_EXPORT_CONFIG ] || __SCWRYPT=1 # arbitrary; indicates currently inside a scwrypt diff --git a/zsh/lib/helm/dependency.module.zsh b/zsh/lib/helm/dependency.module.zsh new file mode 100644 index 0000000..8ed11a0 --- /dev/null +++ b/zsh/lib/helm/dependency.module.zsh @@ -0,0 +1,42 @@ +##################################################################### + +DEPENDENCIES+=(helm kubeval) +REQUIRED_ENV+=() + +use helm/validate + +##################################################################### + +HELM__DEPENDENCY__UPDATE() { + [ ! $USAGE ] && local USAGE=" + usage: [...options...] + + options + -t, --template-filename path to a template/*.yaml file of a helm chart + + Auto-detect chart and build dependencies for any file within a helm chart. + " + local TEMPLATE_FILENAME CHART_ROOT VALUES_FILES=() + local COLORIZE=0 RAW=0 DEBUG=0 + + while [[ $# -gt 0 ]] + do + case $1 in + -t | --template-filename ) TEMPLATE_FILENAME="$(SCWRYPTS__GET_REALPATH "$2")"; shift 1 ;; + + * ) ERROR "unexpected argument '$1'" ;; + esac + shift 1 + done + + HELM__VALIDATE + CHECK_ERRORS || return 1 + + ########################################## + + STATUS "updating helm dependencies for '$CHART_ROOT'" \ + && cd $CHART_ROOT \ + && helm dependency update \ + && SUCCESS "helm chart dependencies updated" \ + || { ERROR "unable to update helm chart dependencies (see above)"; return 1; } +} diff --git a/zsh/lib/helm/helm.module.zsh b/zsh/lib/helm/helm.module.zsh new file mode 100644 index 0000000..1be8095 --- /dev/null +++ b/zsh/lib/helm/helm.module.zsh @@ -0,0 +1,9 @@ +##################################################################### + +DEPENDENCIES+=() +REQUIRED_ENV+=() + +use helm/dependency +use helm/template + +##################################################################### diff --git a/zsh/lib/helm/template.module.zsh b/zsh/lib/helm/template.module.zsh new file mode 100644 index 0000000..17dc29f --- /dev/null +++ b/zsh/lib/helm/template.module.zsh @@ -0,0 +1,104 @@ +##################################################################### + +DEPENDENCIES+=(helm kubeval) +REQUIRED_ENV+=() + +use helm/validate + +##################################################################### + +HELM__TEMPLATE__GET() { + [ ! $USAGE ] && local USAGE=" + usage: [...options...] (--) [...helm args...] + + options + -t, --template-filename path to a template/*.yaml file of a helm chart + + --colorize use 'bat' to colorize output + --raw remove scwrypts-added fluff and only output helm template details + + Smart helm-template generator which auto-detects the chart + and sample values for testing and developing helm charts. + " + local HELM_ARGS=() + local TEMPLATE_FILENAME TEMPLATE_NAME CHART_ROOT CHART_NAME VALUES_FILES=() + local COLORIZE=0 RAW=0 DEBUG=0 + + while [[ $# -gt 0 ]] + do + case $1 in + -t | --template-filename ) TEMPLATE_FILENAME="$(SCWRYPTS__GET_REALPATH "$2")"; shift 1 ;; + + --colorize ) + DEPENDENCIES=(bat) CHECK_ENVIRONMENT || return 1 + COLORIZE=1 + ;; + + --raw ) RAW=1 ;; + -- ) shift 1; break ;; + + * ) HELM_ARGS+=($1) ;; + esac + shift 1 + done + + while [[ $# -gt 0 ]]; do HELM_ARGS+=($1); shift 1; done + + HELM__VALIDATE + CHECK_ERRORS || return 1 + + ########################################## + + local EXIT_CODE=0 + local TEMPLATE_OUTPUT DEBUG_OUTPUT + [ $USE_CHART_ROOT ] && [[ $USE_CHART_ROOT -eq 1 ]] && { + CAPTURE TEMPLATE_OUTPUT DEBUG_OUTPUT helm template "$CHART_ROOT" ${HELM_ARGS[@]} --debug + true + } || { + CAPTURE TEMPLATE_OUTPUT DEBUG_OUTPUT helm template "$CHART_ROOT" ${HELM_ARGS[@]} --debug --show-only "$(echo $TEMPLATE_FILENAME | sed "s|^$CHART_ROOT/||")" + } + + [ ! $TEMPLATE_OUTPUT ] && EXIT_CODE=1 + + [[ $RAW -eq 1 ]] && { + [ $USE_CHART_ROOT ] && [[ $USE_CHART_ROOT -eq 1 ]] || HELM_ARGS+=(--show-only $(echo $TEMPLATE_FILENAME | sed "s|^$CHART_ROOT/||")) + [[ $COLORIZE -eq 1 ]] \ + && helm template "$CHART_ROOT" ${HELM_ARGS[@]} 2>&1 | bat --language yaml --color always \ + || helm template "$CHART_ROOT" ${HELM_ARGS[@]} | grep -v '^# Source:.*$' \ + ; + + return $EXIT_CODE + } + + [ $TEMPLATE_OUTPUT ] && { + KUBEVAL_RAW=$(echo $TEMPLATE_OUTPUT | kubeval --schema-location https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master) + true + } || { + TEMPLATE_OUTPUT="---\nerror: chart or '$(basename $(dirname $TEMPLATE_FILENAME))/$(basename $TEMPLATE_FILENAME)' invalid" + KUBEVAL_RAW="no template output; kubeval skipped" + + [ $USE_CHART_ROOT ] && [[ $USE_CHART_ROOT -eq 1 ]] || { + DEBUG_OUTPUT="$(helm template "$CHART_ROOT" ${HELM_ARGS[@]} --debug 2>&1 >/dev/null)" + } + } + + TEMPLATE_OUTPUT="$TEMPLATE_OUTPUT +--- +debug: | +$(echo $DEBUG_OUTPUT | sed 's/^/ /g') + +kubeval: | +$(echo $KUBEVAL_RAW | sed 's/^/ /g') + +lint: | +$(helm lint $CHART_ROOT ${HELM_ARGS[@]} 2>&1 | sed 's/^/ /g') +" + + [[ $COLORIZE -eq 1 ]] && { + echo $TEMPLATE_OUTPUT | bat --language yaml --color always + } || { + echo $TEMPLATE_OUTPUT + } + + return $EXIT_CODE +} diff --git a/zsh/lib/helm/validate.module.zsh b/zsh/lib/helm/validate.module.zsh new file mode 100644 index 0000000..e9fc661 --- /dev/null +++ b/zsh/lib/helm/validate.module.zsh @@ -0,0 +1,65 @@ +##################################################################### + +DEPENDENCIES+=(yq) +REQUIRED_ENV+=() + +##################################################################### + +HELM__VALIDATE() { + [ ! $USAGE ] && USAGE=" + usage: + + environment + TEMPLATE_FILENAME target template filename + + Smart helm-detection / validator which determines the helm + chart root and other details given a particular filename. + " + + [ $TEMPLATE_FILENAME ] && [ -f "$TEMPLATE_FILENAME" ] || { + ERROR 'must provide a template filename' + return 1 + } + + _HELM__GET_CHART_ROOT + [ $CHART_ROOT ] && [ -d "$CHART_ROOT" ] || { + ERROR 'unable to determine helm root; is this a helm template file?' + return 1 + } + + CHART_NAME=$(yq -r .name "$CHART_ROOT/Chart.yaml") + + [[ $TEMPLATE_FILENAME =~ values*.yaml$ ]] && { + HELM_ARGS+=(--values $TEMPLATE_FILENAME) + USE_CHART_ROOT=1 + } + + [[ $(dirname $TEMPLATE_FILENAME) =~ ^$CHART_ROOT$ ]] \ + && USE_CHART_ROOT=1 + + _HELM__GET_DEFAULT_VALUES_ARGS + + return 0 +} + +_HELM__GET_CHART_ROOT() { + local SEARCH_DIR=$(dirname "$TEMPLATE_FILENAME") + while [ ! $CHART_ROOT ] && [[ ! $SEARCH_DIR =~ ^/$ ]] + do + [ -f "$SEARCH_DIR/Chart.yaml" ] && CHART_ROOT="$SEARCH_DIR" && return 0 + SEARCH_DIR="$(dirname "$SEARCH_DIR")" + done + + return 1 +} + +_HELM__GET_DEFAULT_VALUES_ARGS() { + for F in \ + "$CHART_ROOT/values.yaml" \ + "$CHART_ROOT/values.test.yaml" \ + "$CHART_ROOT/tests/default.yaml" \ + ; + do + [ -f "$F" ] && HELM_ARGS+=(--values "$F") + done +} diff --git a/zsh/lib/office/latex.module.zsh b/zsh/lib/office/latex.module.zsh index d49f453..a13e4d1 100644 --- a/zsh/lib/office/latex.module.zsh +++ b/zsh/lib/office/latex.module.zsh @@ -10,7 +10,7 @@ REQUIRED_ENV+=() ##################################################################### LATEX__GET_MAIN_FILENAME() { - local FILENAME=$(SCWRYPTS__GET_PATH_TO_RELATIVE_ARGUMENT "$1") + local FILENAME=$(SCWRYPTS__GET_REALPATH "$1") local DIRNAME="$FILENAME" for _ in {1..3} diff --git a/zsh/lib/scwrypts/scwrypts.module.zsh b/zsh/lib/scwrypts/scwrypts.module.zsh index e69de29..2c407f9 100644 --- a/zsh/lib/scwrypts/scwrypts.module.zsh +++ b/zsh/lib/scwrypts/scwrypts.module.zsh @@ -0,0 +1,15 @@ +##################################################################### + +DEPENDENCIES+=() +REQUIRED_ENV+=() + +##################################################################### + +SCWRYPTS__GET_REALPATH() { + [[ ! $1 =~ ^[/~] ]] \ + && echo $(readlink -f "$EXECUTION_DIR/$1") \ + || echo "$1" \ + ; + + return 0 +} diff --git a/zsh/lib/scwrypts/virtualenv.module.zsh b/zsh/lib/scwrypts/virtualenv.module.zsh index 0519c84..3d8ac94 100644 --- a/zsh/lib/scwrypts/virtualenv.module.zsh +++ b/zsh/lib/scwrypts/virtualenv.module.zsh @@ -1,9 +1,6 @@ ##################################################################### -DEPENDENCIES+=( - virtualenv - nodeenv -) +DEPENDENCIES+=() REQUIRED_ENV+=() use utils @@ -15,14 +12,14 @@ AVAILABLE_VIRTUALENVS=(py zx) REFRESH_VIRTUALENV() { local GROUP="$1" local TYPE="$2" - [ ! $TYPE ] && { - ERROR 'no virtualenv type specified' - return 1 - } - STATUS "refreshing $GROUP/$TYPE virtual environment" + local VIRTUALENV_PATH="$(_VIRTUALENV__GET_PATH)" + + [ ! $TYPE ] && { ERROR 'no virtualenv type specified'; return 1; } + + STATUS "refreshing $GROUP/$TYPE virtualenv" DELETE_VIRTUALENV $GROUP $TYPE \ && UPDATE_VIRTUALENV $GROUP $TYPE \ - && SUCCESS 'successfully refreshed virtual environment' \ + && SUCCESS 'successfully refreshed virtualenv' \ || { ERROR 'something went wrong during refresh (see above)'; return 1; } \ ; } @@ -30,64 +27,50 @@ REFRESH_VIRTUALENV() { UPDATE_VIRTUALENV() { local GROUP="$1" local TYPE="$2" - [ ! $TYPE ] && { - ERROR 'no virtualenv type specified' - return 1 - } - - local VIRTUALENV_PATH=$(GET_VIRTUALENV_PATH $GROUP $TYPE) - - [ ! -d $VIRTUALENV_PATH ] && { - which CREATE_VIRTUALENV__${GROUP}__${TYPE} >/dev/null 2>&1 \ - && CREATE_VIRTUALENV__${GROUP}__${TYPE} $VIRTUALENV_PATH \ - || return 0 - } - - STATUS "updating $TYPE virtual environment" - - source $VIRTUALENV_PATH/bin/activate || { - ERROR 'failed to activate virtualenv; did create fail?' - return 1 - } - - cd $SCWRYPTS_ROOT - local UPDATE_CODE=0 - case $TYPE in - py ) cd py; pip install --no-cache-dir -r requirements.txt; UPDATE_CODE=$? ;; - zx ) cd zx; npm install ;; - esac - UPDATE_CODE=$? - [[ $UPDATE_CODE -eq 0 ]] \ - && SUCCESS "$TYPE virtual environment up-to-date" \ - || ERROR "failed to update $TYPE virtual environment (see errors above)" \ - ; - - deactivate_node >/dev/null 2>&1 - deactivate >/dev/null 2>&1 - return $UPDATE_CODE + local VIRTUALENV_PATH="$(_VIRTUALENV__GET_PATH)" + + [ ! $TYPE ] && { ERROR 'no virtualenv type specified'; return 1; } + + : \ + && which CREATE_VIRTUALENV__${GROUP}__${TYPE} >/dev/null 2>&1 \ + && which ACTIVATE_VIRTUALENV__${GROUP}__${TYPE} >/dev/null 2>&1 \ + && which UPDATE_VIRTUALENV__${GROUP}__${TYPE} >/dev/null 2>&1 \ + && which DEACTIVATE_VIRTUALENV__${GROUP}__${TYPE} >/dev/null 2>&1 \ + || { STATUS "no virtualenv available for $GROUP/$TYPE; skipping"; return 0; } + + STATUS "updating $GROUP/$TYPE virtualenv" \ + && CREATE_VIRTUALENV__${GROUP}__${TYPE} \ + && ACTIVATE_VIRTUALENV__${GROUP}__${TYPE} \ + && UPDATE_VIRTUALENV__${GROUP}__${TYPE} \ + && DEACTIVATE_VIRTUALENV__${GROUP}__${TYPE} \ + && SUCCESS "$GROUP/$TYPE virtualenv up-to-date" \ + || { ERROR "failed to update $GROUP/$TYPE virtualenv (see errors above)"; return 2; } } DELETE_VIRTUALENV() { + [ $CI ] && return 0 + local GROUP="$1" local TYPE="$2" - local VIRTUALENV_PATH="$(GET_VIRTUALENV_PATH $GROUP $TYPE)" + local VIRTUALENV_PATH="$(_VIRTUALENV__GET_PATH)" - STATUS "dropping $TYPE virtual environment artifacts" + [ ! $TYPE ] && { ERROR 'no virtualenv type specified'; return 1; } + + STATUS "dropping $GROUP/$TYPE virtualenv artifacts" [ ! -d $VIRTUALENV_PATH ] && { - SUCCESS "no $TYPE environment detected" + SUCCESS "no $GROUP/$TYPE environment detected" return 0 } rm -rf $VIRTUALENV_PATH \ - && SUCCESS "succesfully cleaned up $TYPE virtual environment" \ + && SUCCESS "succesfully cleaned up $GROUP/$TYPE virtualenv" \ || { ERROR "unabled to remove '$VIRTUALENV_PATH'"; return 1; } } -GET_VIRTUALENV_PATH() { - local GROUP="$1" - local TYPE="$2" +##################################################################### +_VIRTUALENV__GET_PATH() { local ENV_PATH="$(eval echo '$SCWRYPTS_VIRTUALENV_PATH__'$GROUP 2>/dev/null)" [ ! $ENV_PATH ] && ENV_PATH="$SCWRYPTS_VIRTUALENV_PATH__scwrypts" @@ -97,9 +80,14 @@ GET_VIRTUALENV_PATH() { ##################################################################### CREATE_VIRTUALENV__scwrypts__py() { + [ $CI ] && return 0 + [ -d $VIRTUALENV_PATH ] && return 0 + + DEPENDENCIES=(virtualenv) CHECK_ENVIRONMENT || return 1 + local VIRTUALENV_PATH="$1" - STATUS 'creating python virtual environment' + STATUS 'creating python virtualenv' local PY PYTHON for PY in $(echo $SCWRYPTS_PREFERRED_PYTHON_VERSIONS__scwrypts) do @@ -122,7 +110,37 @@ CREATE_VIRTUALENV__scwrypts__py() { } } +ACTIVATE_VIRTUALENV__scwrypts__py() { + [ $CI ] && return 0 + source $VIRTUALENV_PATH/bin/activate || { + ERROR "failed to activate virtualenv $GROUP/$TYPE; did create fail?" + return 1 + } +} + +UPDATE_VIRTUALENV__scwrypts__py() { + local PIP_INSTALL_ARGS=() + + PIP_INSTALL_ARGS+=(--no-cache-dir) + PIP_INSTALL_ARGS+=(-r requirements.txt) + + cd "$SCWRYPTS_ROOT/py" + pip install ${PIP_INSTALL_ARGS[@]} +} + +DEACTIVATE_VIRTUALENV__scwrypts__py() { + deactivate >/dev/null 2>&1 + return 0 +} + +########################################## + CREATE_VIRTUALENV__scwrypts__zx() { + [ $CI ] && return 0 + [ -d $VIRTUALENV_PATH ] && return 0 + + DEPENDENCIES=(nodeenv) CHECK_ENVIRONMENT || return 1 + local VIRTUALENV_PATH="$1" STATUS 'setting up nodeenv' @@ -133,3 +151,23 @@ CREATE_VIRTUALENV__scwrypts__zx() { return 2 } } + +ACTIVATE_VIRTUALENV__scwrypts__zx() { + [ $CI ] && return 0 + source $VIRTUALENV_PATH/bin/activate || { + ERROR "failed to activate virtualenv $GROUP/$TYPE; did create fail?" + return 1 + } +} + +UPDATE_VIRTUALENV__scwrypts__zx() { + local NPM_INSTALL_ARGS=() + + cd "$SCWRYPTS_ROOT/zx" + npm install ${NPM_INSTALL_ARGS[@]} +} + +DEACTIVATE_VIRTUALENV__scwrypts__zx() { + deactivate_node >/dev/null 2>&1 + return 0 +} diff --git a/zsh/lib/utils/io.zsh b/zsh/lib/utils/io.zsh index 10b74fd..d5aa19d 100644 --- a/zsh/lib/utils/io.zsh +++ b/zsh/lib/utils/io.zsh @@ -155,6 +155,18 @@ yN() { [[ $yN =~ [yY] ]] && return 0 || return 1 } +CAPTURE() { + [ ! $USAGE ] && USAGE=" + usage: stdout-varname stderr-varname [...cmd and args...] + + captures stdout and stderr on separate variables for a command + " + { + IFS=$'\n' read -r -d '' $2; + IFS=$'\n' read -r -d '' $1; + } < <((printf '\0%s\0' "$(${@:3})" 1>&2) 2>&1) +} + ##################################################################### GETSUDO() { diff --git a/zsh/lib/utils/utils.module.zsh b/zsh/lib/utils/utils.module.zsh index 86b1aa4..c383718 100644 --- a/zsh/lib/utils/utils.module.zsh +++ b/zsh/lib/utils/utils.module.zsh @@ -19,10 +19,16 @@ source ${0:a:h}/environment.zsh CHECK_ENVIRONMENT() { local OPTIONAL=0 - [[ $1 =~ --optional ]] && OPTIONAL=1 - [[ $OPTIONAL -eq 1 ]] \ - && E=WARNING || E=ERROR + while [[ $# -gt 0 ]] + do + case $1 in + --optional ) OPTIONAL=1 ;; + esac + shift 1 + done + + [[ $OPTIONAL -eq 1 ]] && E=WARNING || E=ERROR local ENVIRONMENT_STATUS=0 diff --git a/zsh/office/latex/cleanup b/zsh/office/latex/cleanup index df40aa2..f118eed 100755 --- a/zsh/office/latex/cleanup +++ b/zsh/office/latex/cleanup @@ -8,7 +8,7 @@ CHECK_ENVIRONMENT ##################################################################### CLEAN_LATEX_LOGFILES() { - local DIRECTORY=$(SCWRYPTS__GET_PATH_TO_RELATIVE_ARGUMENT ".") + local DIRECTORY=$(SCWRYPTS__GET_REALPATH ".") [ $1 ] && DIRECTORY="$(dirname "$(LATEX__GET_MAIN_FILENAME "$1")")" [ $DIRECTORY ] && [ -d $DIRECTORY ] \ || FAIL 1 'unable to parse valid directory' diff --git a/zsh/scwrypts/virtualenv/update-all b/zsh/scwrypts/virtualenv/update-all index c4d9363..d6f7c03 100755 --- a/zsh/scwrypts/virtualenv/update-all +++ b/zsh/scwrypts/virtualenv/update-all @@ -22,4 +22,4 @@ done [[ $FAILED_COUNT -eq 0 ]] \ && SUCCESS 'all environments up-to-date' \ - || FAIL $FAILED_COUNT 'failed to update one or more environments' + || FAIL $FAILED_COUNT "failed to update $FAILED_COUNT more environment(s)"