1

我们有多个团队。 前端后端。所有前端开发人员都node在计算机上,但后端开发人员没有。

Husky ( https://typicode.github.io/husky/#/ ) 安装 commit-Hooks。对于后端开发人员,我们收到错误消息Can't find Husky, skipping pre-commit hook 。(因为node他们的电脑上没有)。

我不希望他们被迫安装节点,因为我们在 Docker-Container 内完成所有这些工作。

.git/hooks看起来像这样:

if [ -f "$scriptPath" ]; then
  # if [ -t 1 ]; then
  #   exec < /dev/tty
  # fi
  if [ -f ~/.huskyrc ]; then
    debug "source ~/.huskyrc"
    source ~/.huskyrc
  fi
  node_modules/run-node/run-node "$scriptPath" $hookName "$gitParams"

或者在以后的版本中:

#!/bin/sh
if [ -z "$husky_skip_init" ]; then
  debug () {
    [ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
  }

  readonly hook_name="$(basename "$0")"
  debug "starting $hook_name..."

  if [ "$HUSKY" = "0" ]; then
    debug "HUSKY env variable is set to 0, skipping hook"
    exit 0
  fi

  if [ -f ~/.huskyrc ]; then
    debug "sourcing ~/.huskyrc"
    . ~/.huskyrc
  fi

  export readonly husky_skip_init=1
  sh -e "$0" "$@"
  exitCode="$?"

  if [ $exitCode != 0 ]; then
    echo "husky - $hook_name hook exited with code $exitCode (error)"
    exit $exitCode
  fi

  exit 0
fi

我可以以某种方式将 husky 配置为启动脚本执行docker-compose run app ....吗?我想在容器内运行实际的脚本,但我没有让 husky 本身在容器中执行。

4

1 回答 1

0

如果我理解正确,我分两步解决了这个问题:

  1. 通过与来宾共享主机的 git
# at docker-compose.yaml
version: '3'
services:
    app:
        build:
        ...
        volumes:
            - /usr/bin/git:/usr/bin/git
            # installing dependencies missing at guest (in my case, guest debian, host ubuntu)
            - /lib/x86_64-linux-gnu/libpcre2-8.so.0:/lib/x86_64-linux-gnu/libpcre2-8.so.0

2. 通过在容器内运行 hook 命令,例如:

# at .husky/pre-commit

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# instead of only npx lint-staged
docker exec great-app npx lint-staged 

于 2021-06-14T21:17:58.287 回答