Chris Stewart
Chris Stewart

Reputation: 1689

github actions not discovering artifacts uploaded between runs

I have a set of static binaries that I am currently re-downloading every CI run. I need these binaries to test against. I would like to cache these OS specific binaries on github actions so i don't need to re-download them everytime.

A key consideration here is the binaries do not change between jobs, they are 3rd party binaries that I do not want to re-download from the 3rd party site every time a PR is submitted to github. These binaries are used to test against, and the 3rd party publishes a release once every 6 months

I have attempted to do this with the upload-artifact and download-artifact flow with github actions.

I first created an action to upload the artifacts. These are static binaries I would like to cache repository wide and re-use everytime a PR is opened.

Here is the commit that did that:

https://github.com/bitcoin-s/bitcoin-s/runs/2841148806

I pushed a subsequent commit and added logic to download-artifact on the same CI job. When it runs, it claims that there is no artifact with that name despite the prior commit on the same job uploading it

https://github.com/bitcoin-s/bitcoin-s/pull/3281/checks?check_run_id=2841381241#step:4:11

What am i doing wrong?

Next

Upvotes: 1

Views: 824

Answers (1)

Veerle
Veerle

Reputation: 91

Artifacts and cache achieve the same thing, but should be used for different use cases. From the GitHub docs:

Artifacts and caching are similar because they provide the ability to store files on GitHub, but each feature offers different use cases and cannot be used interchangeably.

  • Use caching when you want to reuse files that don't change often between jobs or workflow runs.
  • Use artifacts when you want to save files produced by a job to view after a workflow has ended.

In your case you could use caching and set up a cache action. You will need a key and a path, and it will look something like this:

    - name: Cache dmg
      uses: actions/cache@v2
      with:
        key: "bitcoin-s-dmg-${{steps.previoustag.outputs.tag}}-${{github.sha}}"
        path: ${{ env.pkg-name }}-${{steps.previoustag.outputs.tag}}.dmg

When there's a cache hit (your key is found), the action restores the cached files to your specified path.

When there's a cache miss (your key is not found), a new cache is created.

By using contexts you can update your key and observe changes in files or directories. E.g. to update the cache whenever your package-lock.json file changes you can use ${{ hashFiles('**/package-lock.json') }}.

Upvotes: 1

Related Questions