Github 操作/cache@v2:无法识别的选项:发布作业中的 posix



我正在使用Github操作在我的项目中实现CI管道。目前,我正在尝试使用操作/cache@v2来缓存yarn cache dir以缩短管道时间。不幸的是,总是运行操作/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

我正在遵循官方操作缓存存储库的示例。这是我的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-

由于上述错误,不会创建缓存,也不会缩短管道时间。我尝试更改hasFiles表达式和整个键,但没有成功。

我的问题是:我在使用操作缓存时是否犯了一些错误?任何人都可以帮助我解决这个问题吗?谢谢。

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

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

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

最新更新