Github actions/cache@v2:无法识别的选项:post 作业中的 posix

Bru*_*res 4 github github-actions

我正在使用 Github Actions 在我的项目中实现 CI 管道。目前,我正在尝试使用 actions/cache@v2 进行缓存yarn cache dir以改善管道时间。不幸的是,总是在 actions/cache@v2 运行时我在后期作业中收到错误消息:/bin/tar: unrecognized option: posix。完整的日志是:

Post job cleanup.
/usr/bin/docker exec  4decc52e7744d9ab2e81bb24c99a830acc848912515ef1e86fbb9b8d5049c9cf sh -c "cat /etc/*release | grep ^ID"
/bin/tar --posix -z -cf cache.tgz -P -C /__w/open-tuna-api/open-tuna-api --files-from manifest.txt
/bin/tar: unrecognized option: posix
BusyBox v1.31.1 () multi-call binary.

Usage: tar c|x|t [-ZzJjahmvokO] [-f TARFILE] [-C DIR] [-T FILE] [-X FILE] [--exclude PATTERN]... [FILE]...

Create, extract, or list files from a tar file

    c   Create
    x   Extract
    t   List
    -f FILE Name of TARFILE ('-' for stdin/out)
    -C DIR  Change to DIR before operation
    -v  Verbose
    -O  Extract to stdout
    -m  Don't restore mtime
    -o  Don't restore user:group
    -k  Don't replace existing files
    -Z  (De)compress using compress
    -z  (De)compress using gzip
    -J  (De)compress using xz
    -j  (De)compress using bzip2
    -a  (De)compress using lzma
    -h  Follow symlinks
    -T FILE File with names to include
    -X FILE File with glob patterns to exclude
    --exclude PATTERN   Glob pattern to exclude
Warning: Tar failed with error: The process '/bin/tar' failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

我正在遵循官方操作缓存存储库的示例。这是我的 CI.yml 的片段

  # Configure cache
  - name: Get yarn cache directory path
    id: yarn-cache-dir-path
    run: echo "::set-output name=dir::$(yarn cache dir)"

  - uses: actions/cache@v2
    id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
    with:
      path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
      key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
      restore-keys: |
        ${{ runner.os }}-yarn-
Run Code Online (Sandbox Code Playgroud)

由于上述错误,未创建缓存并且管道时间未得到改善。我尝试过更改hasFiles表达式和整个键,但没有成功。

我的问题是:我在使用 Action Cache 时犯了一些错误吗?谁能帮我解决这个问题吗?谢谢。

bk2*_*204 6

您的问题是您正在基于 Alpine Linux 的容器内运行。Alpine Linux 专为小尺寸而设计,因此它用多调用二进制文件 busybox 中的实用程序取代了许多标准 GNU 实用程序。您的版本tar就是其中之一。

actions/cache@v2操作使用tar --posix,它告诉您tar创建一个标准的 pax 格式存档。pax 存档是 tar 存档的一种形式,可以处理任意长的文件名、巨大的文件大小以及 tar 存档无法处理的其他类型的元数据。这种格式由 POSIX 指定,是比 GNU tar 样式存档更好的选择,因为它除了功能更强大之外,还可以跨各种系统工作,并且不受某个实现的功能所指定。

但是,作为 busybox 一部分提供的版本tar不支持该--posix选项,因此该命令失败。如果您想使用GitHub Action,那么您需要在运行之前actions/cache@v2提供 GNU 或 BSD (libarchive) 的版本,以便可以使用该命令而不是 busybox 的命令。tarPATH