sh 运行静态检查并在githooks上构建。带有进度显示的Bash脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 运行静态检查并在githooks上构建。带有进度显示的Bash脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash

######################################
## Utilities
######################################
success () {
  printf "\r\033[2K  [ \033[00;32mOK\033[0m ] $1\n"
}

info () {
  printf "  [\033[00;34mINFO\033[0m] $1\n"
}

fail () {
  printf "\r\033[2K  [\033[0;31mFAIL\033[0m] $1\n"
  echo ''
  exit 1
}

safe_run () {
    set +e
    local log="&>/dev/null &"

    eval "$1 $log"
    pid=$! # Process Id of the previous running command

    # Show progress bar
    spin[0]="-"
    spin[1]="\\"
    spin[2]="|"
    spin[3]="/"

    echo -n "  ${spin[0]}"
    while kill -0 $pid 2>/dev/random; do
        for i in "${spin[@]}"; do
            echo -ne "\b$i"
            sleep 0.1
        done
    done

    # read the status of background process
    wait $pid
    # Handle the error
    if [[ $? -ne 0 ]]; then
        if [[ -n "${2+x}" ]]; then
            fail "$2"
        else
            fail "$1 failed"
        fi
        set -e
        exit 1
    fi
}

######################################
## Checks
######################################

# Try to build the app
info "Building the app"
cd app
safe_run "npm run build -s", "Build Failed"
success "Build Done"

# Linter
info "Linting"
safe_run "npm run lint -s", "Lint failed"
success "Lint Successful"

# Unittests
info "Runnin Unittests"
safe_run "npm test -s", "Unitests have failed"
success "Unittests Passed"

# Do checks on client
info "Linting"
safe_run "npm run lint -s", "Client ESLint Failed"
success "Lint Successful"

以上是关于sh 运行静态检查并在githooks上构建。带有进度显示的Bash脚本的主要内容,如果未能解决你的问题,请参考以下文章

sh 检查Pulseway服务并在未运行时重新启动它。登录到/var/log/pulseway.log

构建一个嵌入 Qt 的最小系统并在 Qemu for x86 上运行

Cppcheck 忽略 -i 并在干净构建后检查所有文件

带有自定义共享库的 Qt 项目交叉编译 Qt

11.5K Star!有了这个 Python 开发利器,Bug 会减少很多!

在 Windows 上运行的 Eclipse 上静态链接 OpenCV