Github actions/cache@v2: unrecognized option: posix in the post job

Viewed 788

I'm using Github Actions to implement a CI pipeline in my project. Currently, I'm trying to use actions/cache@v2 to cache yarn cache dir to improve the pipeline time. Unfortunately, always that the actions/cache@v2 runs I'm getting an error in the post-job saying: /bin/tar: unrecognized option: posix. The complete log is:

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

I'm following the example of the official action cache repository. Here a snippet of my 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-

Because of the above error, the cache is not created and the pipeline time is not improved. I've tried changing the hasFiles expression and the entire key, but no success.

My question is: Am I making some mistake in the use of Action Cache? Can anyone help me with this issue? Thanks.

1 Answers

Your problem is that you're running inside an Alpine Linux-based container. Alpine Linux is designed for small size, and as a result it replaces many of the standard GNU utilities with those from busybox, a multi-call binary. Your version of tar is one of those.

The actions/cache@v2 action uses tar --posix, which tells tar to create a standard pax-format archive. pax archives are a form of tar archive that can handle arbitrarily long filenames, huge file sizes, and other types of metadata that tar archives cannot. This format is specified by POSIX and is a better choice than GNU tar-style archives because it works across a variety of systems and isn't specified by what one implementation does, in addition to being more featureful.

However, the version of tar shipped as part of busybox doesn't support the --posix option, and as a result this command fails. If you want to use the actions/cache@v2 GitHub Action, then you need to provide a version of GNU or BSD (libarchive) tar earlier in your PATH before running it so that that command can be used instead of busybox's.

Related