Skip to content

@actions/cache fails on Windows when GNU tar from MSYS2 is in PATH #632

@eregon

Description

@eregon

Describe the bug

When C:\msys64\usr\bin is in the path on Windows, and using @actions/cache, I noticed that cache saving always fails:
ruby/setup-ruby#102

https://github.com/ruby/setup-ruby/runs/1370892940?check_suite_focus=true

  Saving cache
  C:\msys64\usr\bin\tar.exe --posix --use-compress-program "zstd -T0" -cf cache.tzst -P -C D:/a/setup-ruby/setup-ruby --files-from manifest.txt --force-local
  /usr/bin/tar: vendor\bundle: Cannot stat: No such file or directory
  /usr/bin/tar: Exiting with failure status due to previous errors
  Warning: Tar failed with error: The process 'C:\msys64\usr\bin\tar.exe' failed with exit code 2

The problem seems to be that the cache paths written to manifest.txt use \\ and not /, which I would think GNU tar expects.
On https://github.com/eregon/setup-ruby/runs/1392737782?check_suite_focus=true#step:3:100 we can see the cache paths written to manifest.txt is ["vendor\\bundle"] but it should most likely uses / as separator for GNU tar.

To Reproduce

Minimal repro using actions/cache:

name: Test
on: [push]
jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os: [ ubuntu, macos, windows ]
    runs-on: ${{ matrix.os }}-latest
    steps:
      - run: echo "C:\msys64\usr\bin" >> $GITHUB_PATH
        shell: bash

      - uses: actions/cache@v2
        with:
          path: top/foo
          key: ${{ runner.os }}-debug-cache1

      - run: ls -l
        shell: bash

      - name: Generate files
        run: |
          mkdir -p top/foo
          echo hello > top/foo/bar.txt
        shell: bash

https://github.com/eregon/setup-ruby-test/runs/1392827825?check_suite_focus=true#step:10:3

C:\msys64\usr\bin\tar.exe --posix --use-compress-program "zstd -T0" -cf cache.tzst -P -C D:/a/setup-ruby-test/setup-ruby-test --files-from manifest.txt --force-local
/usr/bin/tar: top\foo: Cannot stat: No such file or directory
/usr/bin/tar: Exiting with failure status due to previous errors
Warning: Tar failed with error: The process 'C:\msys64\usr\bin\tar.exe' failed with exit code 2

Full repro using the @actions/cache package:

    - runs-on: windows-latest
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 2.7
        bundler-cache: true

Expand the bundle install group of ruby/setup-ruby@v1.

Expected behavior
It should save the cache successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions