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

Bitbucket pipeline - error installing pre-commit ts-lint

我的管道中有一个步骤在 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

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

管道结果:

+ 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

pre-commit 利用 nodeenv 到 bootstrap 节点环境

它通过下载 node 的副本并配置环境(当 node 不可用时)来实现。几天前发布了节点 18.x 并且预构建的二进制文件需要 relatively-recent 版本的 glibc

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

1。 select node 使用 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

2。使用更新的基础图像

stretch 有点老了,也许试试用 3.7-slim-buster 代替?

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

    image: python:3.7-slim-buster

3。将 node 安装到您的映像中

这将默认跳过 pre-commit 的“下载节点”步骤(具体来说,当检测到合适的 node 时,它将默认为 language_version: system

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


免责声明:我创建了 pre-commit