Commit b6a529fd authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Merge branch 'shellcheck' into 'main'

Add shellcheck via pre-commit

See merge request !27
parents e49e4cf0 ffb91e2b
Loading
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@ variables:
  PROJECT: nsd-app-wrap
  GIT_STRATEGY: clone
  IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}
  CENTOS7_IMG: "code.ornl.gov:4567/rse/images/centos:7"
  MINICONDA_IMG: "code.ornl.gov:4567/rse/images/miniconda3:latest"
  PKG_PATH: /var/www/html/distros/rhel/7/sns/RPMS/noarch

stages:
@@ -11,11 +13,20 @@ stages:
rpmlint:
  stage: static
  script:
    - docker login --username=$CI_REGISTRY_USER --password=$CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker run -v $PWD/nsd-app-wrap.spec:/tmp/nsd-app-wrap.spec code.ornl.gov:4567/rse/images/centos:7 /bin/bash -c "yum install -y git rpm-build rpmlint && rpmlint /tmp/nsd-app-wrap.spec"
    - docker login --username=${CI_REGISTRY_USER} --password=${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
    - docker run -v $PWD/nsd-app-wrap.spec:/tmp/nsd-app-wrap.spec "${CENTOS7_IMG}" /bin/bash -c "yum install -y git rpm-build rpmlint && rpmlint /tmp/nsd-app-wrap.spec"
  tags:
    - neutrons-multi-builder

precommit:
  stage: static
  script:
    - docker login --username=${CI_REGISTRY_USER} --password=${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
    - docker run -v $PWD:/tmp "${MINICONDA_IMG}" /bin/bash -c "cd /tmp && pip install pre-commit && pre-commit run --all-files"
  tags:
    - neutrons-multi-builder


build-deploy:
  stage: build-deploy
  environment: $CI_COMMIT_REF_SLUG
+10 −0
Original line number Diff line number Diff line
default_language_version:
  python: python3

repos:
- repo: https://github.com/shellcheck-py/shellcheck-py
  rev: v0.9.0.2
  hooks:
  - id: shellcheck
    # follow sources even when they aren't specified on the command line
    args: ['--external-sources']
+7 −2
Original line number Diff line number Diff line
@@ -6,9 +6,14 @@ For example, `refred` will load the appropriate conda environment then start the

Quality of generated scripts
----------------------------
All bash scripts are checked using [shellcheck](https://github.com/koalaman/shellcheck)
All bash scripts are checked using [shellcheck](https://github.com/koalaman/shellcheck) and in enforced using [pre-commit](https://pre-commit.com/).

The desktop files are validated using `desktop-file-validate`
Developers should install pre-commit and run
```sh
pre-commit install
```

The desktop files are validated using `desktop-file-validate` and have an error about the category being "Analysis" rather than "X-Analysis".

The spec file passes [rpmlint](https://linux.die.net/man/1/rpmlint) with one warning about the definition of the source (`invalid-url Source0`).

+9 −9
Original line number Diff line number Diff line
@@ -7,19 +7,19 @@ unset SESSION_MANAGER
# select the environment to use
CONDA_ENVIRON=addie
# If `dev` or `qa` version requested, default to `--mode=mantid`.
real_arg=""
if [ -n "$1" ]; then
mode_arg=""
if [ -z "$1" ]; then
  if [ "$1" == "--dev" ]; then
    CONDA_ENVIRON=addie-dev
    shift  # drop this argument
    if [ ! -n "$1" ]; then
        real_arg="${@}--mode=mantid"
    if [ -z "$1" ]; then
	mode_arg="--mode=mantid"
    fi
  elif [ "$1" == "--qa" ]; then
    CONDA_ENVIRON=addie-qa
    shift  # drop this argument
    if [ ! -n "$1" ]; then
        real_arg="${@}--mode=mantid"
    if [ -z "$1" ]; then
	mode_arg="--mode=mantid"
    fi
  fi
fi
@@ -28,10 +28,10 @@ fi
source "$(dirname "$(realpath "$0")")/nsd-app-wrap.sh"

# put together arguments - conda_env, application, argv
if [ "$real_arg" == "" ]; then
    args=("${CONDA_ENVIRON}" "addie" "${@}")
if [ -n "${mode_arg}" ]; then
    args=("${CONDA_ENVIRON}" "addie" "${mode_arg}" "${@}")
else
    args=("${CONDA_ENVIRON}" "addie" "$real_arg")
    args=("${CONDA_ENVIRON}" "addie" "${@}")
fi
# launch the tool
activate_and_launch "${args[@]}"
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ if [ -n "$1" ] && [ "$1" == "--classic" ]; then
fi

# import library to do the real work
source "$(dirname "$(realpath "$0")")/nsd-app-wrap.sh"
. "$(dirname "$(realpath "$0")")/nsd-app-wrap.sh"

# put together arguments - conda_env, application, argv
args=("${CONDA_ENVIRON}" "${STARTUP}" "$@")
Loading