Bitbucket 管道 - 安装预提交 ts-lint 时出错

Rod*_*rez 3 bitbucket pre-commit pre-commit-hook bitbucket-pipelines pre-commit.com

我的管道中有一个步骤在 Bitbucket 上运行我们配置的预提交:

...
- step:
    name: Passing linters
    image: python:3.7-slim-stretch
    script:
      - pip3 install "pre-commit==2.17.0"
      - apt-get update && apt-get --assume-yes install git
      - pre-commit run --all-files

Run Code Online (Sandbox Code Playgroud)

没有进行任何更改,但它突然停止工作。

管道结果:

+ pre-commit run --all-files
[INFO] Initializing environment for https://github.com/psf/black.
[INFO] Initializing environment for https://github.com/psf/black:click==8.0.4.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/maximevast/pre-commit-tslint/.
[INFO] Initializing environment for https://github.com/maximevast/pre-commit-tslint/:tslint-react@4.1.0,tslint@5.20.1,typescript@4.0.2.
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/maximevast/pre-commit-tslint/.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/root/.cache/pre-commit/repo1234/node_env-default/bin/node', '/root/.cache/pre-commit/repo1234/node_env-default/bin/npm', 'install', '--dev', '--prod', '--ignore-prepublish', '--no-progress', '--no-save')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    /root/.cache/pre-commit/repo1234/node_env-default/bin/node: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.27' not found (required by /root/.cache/pre-commit/repo1234/node_env-default/bin/node)
    /root/.cache/pre-commit/repo1234/node_env-default/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /root/.cache/pre-commit/repo1234/node_env-default/bin/node)
    /root/.cache/pre-commit/repo1234/node_env-default/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /root/.cache/pre-commit/repo1234/node_env-default/bin/node)
    
Check the log at /root/.cache/pre-commit/pre-commit.log
Run Code Online (Sandbox Code Playgroud)

Ant*_*ile 6

pre-commit用于nodeenv引导节点环境

它通过下载环境的副本node并配置环境(当node不可用时)来实现此目的。几天前,node 18.x 发布了,预构建的二进制文件需要相对最新版本的 glibc

有几种方法可以解决这个问题:

node1.使用language_version/选择特定版本default_language_version

# using default_language_version
default_language_version:
    node: 16.14.2

# on the hook itself
repos:
-   repo: https://github.com/maximevast/pre-commit-tslint
    rev: ...
    hooks:
    -   id: tslint
        language_version: 16.14.2
Run Code Online (Sandbox Code Playgroud)

2.使用较新的基础镜像

stretch有点旧了,也许可以尝试一下3.7-slim-buster

这将为您提供更现代版本的 glibc

    image: python:3.7-slim-buster
Run Code Online (Sandbox Code Playgroud)

3.安装node到你的镜像中

默认情况下,这将跳过预提交的“下载节点”步骤(具体来说,它将默认为检测到language_version: system合适的节点)node

这将根据您的图像设置而有所不同


免责声明:我创建了预提交