Skip to content

A line ending invariant alternative to hashFiles #498

Open

Description

@mzabaluev

Describe the enhancement
Sometimes cached data is sufficiently cross-platform to be reused across runners on Windows and the Unix OSes. A problem arises if the cache key needs to be computed by hash-summing text files, which produces differing hash sums on the same file if it was e.g. checked out by git in text mode applying auto-conversion to the line endings.

This workflow run failed to hit the cache in the Windows test job, even though the preceding update-deps job on Linux had stored it.

Code Snippet
It would be nice if a hashTextFiles function was available that would canonicalize line endings for the hash input:

  test:
    needs: update-deps
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - id: cargo-registry
        name: Restore cargo registry
        uses: actions/cache@v1
        with:
          path: ~/.cargo/registry
          key: cargo-registry-${{ hashTextFiles('**/Cargo.lock') }}

Activity

  1. added
    enhancement
    on May 21, 2020
  2. changed the title [-]A line ending adaptive variant of hashFiles[/-] [+]A line ending invariant alternative to hashFiles[/+] on May 22, 2020
  3. ericsciple commented on May 26, 2020

    @ericsciple
    Collaborator

    Also consider using a .gitattributes file to control the line endings on windows

  4. mzabaluev commented on May 26, 2020

    @mzabaluev
    Author

    Also consider using a .gitattributes file to control the line endings on windows

    I'm not sure cargo would honor it when writing an updated lock file. More generally, forcing Unix-style endings on a file would inconvenience many developers just so a CI workflow can run correctly, which I think is not a good tradeoff.

  5. bryanmacfarlane commented on Jun 1, 2020

    @bryanmacfarlane
    Contributor

    For it to be a problem in CI, developers in different OSes would need to be committing lock file changes (and other files) with different line endings. That seems like it could be problematic outside of CI. I don't think you also need to force unix style endings - you just need consistency which seems like a good practice as other tools will have issues (which is why git has options).

  6. bryanmacfarlane commented on Jun 1, 2020

    @bryanmacfarlane
    Contributor

    ... however, I do agree that having an option that was line ending agnostic (filters out line endings to generate the contents to create the hash) would be a good enhancement

  7. mzabaluev commented on Jun 1, 2020

    @mzabaluev
    Author

    For it to be a problem in CI, developers in different OSes would need to be committing lock file changes (and other files) with different line endings.

    Not only that: it's common to check in the package-lock.json or the Cargo.lock for an application project to ensure reproducible builds, even though these files are managed by the build tools. Git checks out text files with the OS line ending format unless overridden, and it's good in general, because developers may also want to view these files or use some other tools on them, which might be problematic on Windows with the non-conformant line endings (though there are fewer tools that don't work with either format these days).

  8. added
    Runner Feature
    and removed
    enhancement
    on Jun 8, 2020
  9. kriegaex commented on Aug 1, 2021

    @kriegaex

    A real-world use case for this is caching a local Maven repository, calculating the cache key from ${{ hashFiles('**/pom.xml') }}, which is a frequent use case in many projects. This yields one set of cache files for Linux and MacOS, but another one one Windows. As was discussed above, using .gitattributes and influence all users just so as to fix caching on CI is not an adequate solution, way too invasive.

    See also:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Runner Feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions