Git Product home page Git Product logo

cache-action's Introduction

coursier cache action

A GitHub action to save / restore the coursier / sbt / mill / Ammonite caches of your build.

Usage

Add a coursier/cache-action@v6 step to your YAML workflow, like

    steps:
      - uses: actions/checkout@v4
      - uses: coursier/cache-action@v6

Cached directories

Coursier cache

Always cached.

Add files to take into account in its cache key via extraFiles.

~/.sbt and ~/.ivy2/cache

Cached when sbt files are found (any of *.sbt, project/**.scala, project/**.sbt, project/build.properties).

Add files to take into account in its cache key via extraSbtFiles.

~/.cache/mill

Cached when mill files are found (any of .mill-version, ./mill).

Add files to take into account in its cache key via extraMillFiles.

~/.ammonite

Cached when Ammonite scripts are found (any of *.sc, */*.sc).

Add files to take into account in its cache key via ammoniteScripts.

Parameters

root

Optional Root directory containing build definition sources (build.sbt, build.sc, etc.)

If the sbt or mill build definition files are in a sub-directory, pass the path to this sub-directory here.

path

Optional Override for the path of the coursier cache.

By default, the coursier cache is assumed to be in the default OS-dependent location. Set this input to override that. Note that this action will also set the COURSIER_CACHE environment variable if an override is specified, so that you don't have to set it yourself.

extraFiles

Optional Extra files to take into account in the cache key.

By default, sbt build definition files (*.sbt, project/**.{scala,sbt}, project/build.properties) and mill build definition files (*.sc, ./mill) are hashed to uniquely identify the cached data. Upon cache restoration, if an exact match is found, the cache is not saved again at the end of the job. In case of no exact match, it is assumed new files may have been fetched; the previous cache for the current OS, if any, is restored, but a new cache is persisted with a new key at the end of the job.

To take into account extra files in the cache key, pass via extraFiles either

  • a single path as a string
  • multiple paths in a JSON array, encoded in a string

Blobs are accepted (processed by @actions/glob).

extraSbtFiles

Optional Extra sbt files to take into account in the sbt cache key. Same format as extraFiles.

extraMillFiles

Optional Extra mill files to take into account in the mill cache key. Same format as extraFiles.

ammoniteScripts

Optional Extra Ammonite scripts to take into account in the Ammonite cache key. Same format as extraFiles.

extraKey

Optional

Extra value to be appended to the coursier cache key.

See extraFiles for more details.

extraHashedContent

Optional

Extra content to take into account in the cache key.

See extraFiles for more details.

The content of extraHashedContent is taken into account in the hash for the coursier cache key.

ignoreJob

Optional

Default: false

Set true if you don't want to use a job id as part of cache key.

ignoreMatrix

Optional

Default: false

Set true if you don't want to use a matrix jobs as part of cache key.

Outputs

  • cache-hit-coursier - A boolean value to indicate a match was found for the coursier cache
  • cache-hit-sbt-ivy2-cache - A boolean value to indicate a match was found for the sbt-ivy2-cache cache
  • cache-hit-mill - A boolean value to indicate a match was found for the mill cache
  • cache-hit-ammonite - A boolean value to indicate a match was found for the ammonite cache

See Skipping steps based on cache-hit for info on using this output

Skipping steps based on cache-hit

Using the cache-hit-... outputs above, subsequent steps can be skipped when a cache hit occurs on a given key.

Example:

steps:
  - uses: actions/checkout@v3

  - uses: coursier/cache-action@v6
    id: coursier-cache

  - name: Fetch Dependencies
    if: steps.coursier-cache.outputs.cache-hit-coursier != 'true'
    run: sbt +update

Note: The id defined in coursier/cache-action must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit-coursier)

cache-action's People

Contributors

akiomik avatar alexarchambault avatar balmungsan avatar cptwunderlich avatar dependabot[bot] avatar exoego avatar github-actions[bot] avatar gvolpe avatar hugo-vrijswijk avatar idiosapps avatar ihostage avatar laughedelic avatar lolgab avatar mkurz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cache-action's Issues

Post run action takes too much time occasionally

Some runs of post run action for coursier/cache-action@v6 take minutes to finish. The behavior is flipping, other runs are done under one second. We're using proprietary runners.

Screenshot 2024-03-05 at 16 51 37

Could you please guess what might be the cause of this slow step?

Upgrade to node 16

Actions using Node 12 are considered deprecated and encouraged to upgrade to Node 16.
For reference: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/

I wonder if all that is needed is just changing this line.

runs:
-  using: 'node12'
+  using: 'node16'
  main: 'dist/restore/index.js'
  post: 'dist/save/index.js'
  post-if: 'success()'

And refreshing the package-lock.json using Node 16.

If so, I am more than happy to help.
But, if something else is required I would need assistance / guidance.

See also: coursier/setup-action#281

Consider moving major tags after releases

According to the GitHub Actions toolkit versioning recommendations (https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#recommendations), major version tags should be moved to point to the ref of the current release. This would allow anyone binding to v6 to get the latest fixes, while others could bind to something like 6.1 if they need a specific commit.
For this repo, this would also require what is currently v6 to be renamed to v6.0 so that v6 can move to the latest version.

sbt-ivy2-cache cache not found after upgrading to v4

It looks that after upgrading from coursier/cache-action@v3 to v4 there is some problem that makes cache restore failure.

With v4 lot of dependencies are always downloaded and sbt-ivy2-cache cache not found error is produced
coursier/cache-action@v4 output:

Run coursier/cache-action@v4
/bin/uname -s
Linux

Received 60583331 of 60583331 (100.0%), 122.4 MBs/sec
Cache Size: ~58 MB (60583331 B)
/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/1e9e417e-d565-433d-8aad-b175b1c3e3eb/cache.tzst -P -C /home/runner/work/project/project
coursier cache restored from key Linux-coursier-4de5856a70311a16d18c97754ced62ce52e589c7

sbt-ivy2-cache cache not found

...
[sbt logs shows here lot of dependecies downloads]
...

Post Run coursier/cache-action@v4

Post job cleanup.
Cache hit occurred on key Linux-coursier-4de5856a70311a16d18c97754ced62ce52e589c7, not saving coursier cache.

With v3 everything seems to work as expected
coursier/cache-action@v3 output:

Run coursier/cache-action@v3
/bin/uname -s
Linux

Received 60583331 of 60583331 (100.0%), 112.2 MBs/sec
Cache Size: ~58 MB (60583331 B)
/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/7fe01672-eac7-493a-8d58-cebd8850d80a/cache.tzst -P -C /home/runner/work/project/project
coursier cache restored from key Linux-coursier-4de5856a70311a16d18c97754ced62ce52e589c7

Received 54312530 of 54312530 (100.0%), 105.9 MBs/sec 
Cache Size: ~52 MB (54312530 B)
/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/e6d4c9de-0e6b-49e1-b4d3-7d26ab113c71/cache.tzst -P -C /home/runner/work/project/project
sbt cache restored from key Linux-sbt-4de5856a70311a16d18c97754ced62ce52e589c7

...
[sbt logs shows here no dependecies downloads]
...

Post Run coursier/cache-action@v3

Cache hit occurred on key Linux-sbt-4de5856a70311a16d18c97754ced62ce52e589c7, not saving sbt cache.
Post job cleanup.
Cache hit occurred on key Linux-coursier-4de5856a70311a16d18c97754ced62ce52e589c7, not saving coursier cache.
Cache hit occurred on key Linux-sbt-4de5856a70311a16d18c97754ced62ce52e589c7, not saving sbt cache.

Could it be key sbt key has changed and it's not found anymore or something related?

Suspicious warning 'reserveCache failed' in Post Cache

We're using coursier/cache-action@v5: https://github.com/zio/zio-telemetry/blob/master/.github/workflows/ci.yml#L46

In the Post Cache scala dependencies step, we're seeing suspicious warnings:

Post job cleanup.
Saving coursier cache
Warning:  reserveCache failed: Cache already exists. Scope: refs/heads/master, Key: Linux-coursier-3079bd8f16e7a25e57b7c35b9b13090eb7092b1f, Version: 1e08b80f3462916ac2d5654f6b399c900980cc0f9b928b367a6df70ad7ddd959
Saving sbt-ivy2-cache cache
Warning:  reserveCache failed: Cache already exists. Scope: refs/heads/master, Key: Linux-sbt-ivy2-cache-91f8e0fa8ca1f9c6c77811374a8bcb945b2387c8, Version: 9635c9698008b57d9157eed8e70fa13373c2bf90a51d9edde39fe4b528f54439

https://github.com/zio/zio-telemetry/runs/1797302607?check_suite_focus=true#step:9:3

Is this an expected behavior? The fact that it's a warning makes us not 100% sure that we're using coursier/cache-action correctly.

/cc @mijicd

Consider adding option to disable cache key fallback

The current behaviour of the cache is to fallback to a different cache key on cache miss. It would be good if this behaviour could be disabled, or if the user could define a cache key prefix which applies to all cache keys.

The main driver behind this is avoiding unnecessary downloads / uploads for repos that have multiple builds, with some having only a handful of dependencies or different scala versions

coursier cache keys:
  coursier-lint-scala-code-475cd933d4d254d8267377454164c8ad6db554de
  coursier-lint-scala-code-
  coursier-

< Cache download logs >

Cache restored successfully
coursier cache miss, fell back on coursier-build-b930455d2f9b4f12b182a5c0f86b8680b4479aed.
coursier cache will be saved in post run job.

I'm happy to contribute if you agree with adding this feature but don't have the capacity to work on it at the moment - might need a nudge in the right direction though

Get cache entry failed error

We have started to get this error:
Screen Shot 2020-10-26 at 9 37 17 AM

I am not sure what the source of it, but perhaps you can help us to troubleshoot.

Set `cache-hit-...` output

actions/cache does set the output cache-hit if the cache was hit. Have a look at the docs: https://github.com/actions/cache#skipping-steps-based-on-cache-hit

Can we have the same here?
Looking at the implementation of actions/cache that shouldn't be too hard:

We would need an output for each cache however:

  • cache-hit-coursier
  • cache-hit-sbt-ivy2-cache
  • cache-hit-mill
  • cache-hit-ammonite

Based on the referenced example, we could for example:

...
    if: steps.cache.outputs.cache-hit-coursier != 'true'
...

Transient errors in post-job cache action

scalameta/metals#2608 (comment)

Post job cleanup.
coursier cache key:
  coursier-unit-matrix-c72830702e1d2b18a132b9d6e3742571e19e9466-33aa363d8c15033b2a8ed0d8c299d77f17660736
Saving coursier cache
C:\windows\System32\tar.exe --posix -z -cf cache.tgz -P -C D:/a/metals/metals --files-from manifest.txt
Warning:  Cache service responded with 429 during upload chunk.
  
sbt-ivy2-cache cache key:
  sbt-ivy2-cache-unit-matrix-c72830702e1d2b18a132b9d6e3742571e19e9466-57ca911780629f6d13612b672c8a32e66547f7b0
Saving sbt-ivy2-cache cache

D:\a\_actions\coursier\cache-action\v6\dist\node_modules\@actions\cache\lib\internal\cacheHttpClient.js:177
                        autoClose: false
^
Error: Cache upload failed because file read failed with EBADF: bad file descriptor, read
    at ReadStream.<anonymous> (D:\a\_actions\coursier\cache-action\v6\dist\node_modules\@actions\cache\lib\internal\cacheHttpClient.js:177:1)
    at ReadStream.emit (events.js:210:5)
    at internal/fs/streams.js:167:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)

Migration to Node.js 20 wanted

Thanks for the great project! I'm using it for all my projects.

Currently, on the actions page GitHub shows the following warning:

Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: coursier/cache-action@v6. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.