Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github actions does not seem to use cached links #664

Closed
lsolesen opened this issue Nov 27, 2021 · 2 comments
Closed

Github actions does not seem to use cached links #664

lsolesen opened this issue Nov 27, 2021 · 2 comments
Labels

Comments

@lsolesen
Copy link

lsolesen commented Nov 27, 2021

I have a Github action which I tried setting up as specified in the docs. However, it seems that the check takes just as long time with htmlproofer with and without cache. I am wondering, if there is something specific which also needs to be done?

      - name: ⚡️ Cache HTMLProofer
        id: cache-htmlproofer
        uses: actions/cache@v2
        with:
          path: tmp/.htmlproofer
          key: ${{ runner.os }}-htmlproofer
      - name: 📉 Check HTML
        uses: chabad360/htmlproofer@master
        continue-on-error: true
        with:
          directory: "./_site"
          # The directory to scan
          arguments: --only-4xx --assume-extension --check-favicon --check-html --check_opengraph --http-status-ignore "400, 403, 409, 429" --allow-hash-href --empty_alt_ignore --timeframe "1w"
          # The arguments to pass to HTMLProofer

Full Github Action is here: https://github.com/motionsplan/motionsplan-dk-jekyll/blob/master/.github/workflows/deploy.yml

I have an older build here: https://github.com/motionsplan/motionsplan-dk-jekyll/runs/4337656916?check_suite_focus=true
And a recent one here showing almost the same number of links added to the cache: https://github.com/motionsplan/motionsplan-dk-jekyll/runs/4339790656?check_suite_focus=true#step:12:12

@riccardoporreca
Copy link
Collaborator

riccardoporreca commented Nov 27, 2021

@lsolesen, this has to do with the way actions/cache works

As you can see from the log:

  • The restored cache (step "Cache HTMLProofer") is only 22 Bytes, basically empty
    Received 22 of 22 (100.0%), 0.0 MBs/sec
    Cache Size: ~0 MB (22 B)
    
  • The cache is not re-saved after being populated in the current run ("Post Cache HTMLProofer")
    Cache hit occurred on the primary key Linux-htmlproofer, not saving cache.
    

Indeed, by definition, the cache is not saved for hits on the primary key, since the idea is that the primary key uniquely defines what is being cached. See also actions/cache#171, actions/cache#481, actions/cache#628

This is unfortunately not easy with HTMLProofer, unless it would expose the functionality to just return the links to be checked (and cached) without really checking them. This information could be used to compute a hash used in the primary key.

Now, for your specific case, you have two options

  • A) Change something in key to force a fresh key for caching, e.g. key: ${{ runner.os }}-html-proofer (note the extra -). Note however that this will not really solve the problem, since your new cache will not be updated after the first run, unless it is not accessed (i.e. no workflow run) for 7 days.

  • CB) Use an "aggressive" way of defining the primary key by including the commit SHA, see Add a parameter to ignore the existing cache but still store the cache at the end actions/cache#481 (comment), to make sure a new key is defined (and saved) for every commit. This approach is sensible if the cache is not too big compared to the 10GB usage limit, which is the case for the JSON cache of HTMLProofer. In this case, you should also include the "generic" key as restore-key, so the cache from the "last" run is restored as a starting point for new commits. Putting all together:

    key: ${{ runner.os }}-htmlproofer-${{ github.sha }}
    restore-keys: |
      ${{ runner.os }}-htmlproofer-

@gjtorikian
Copy link
Owner

gjtorikian commented Dec 31, 2021

will use #671 for tracking cache keys

Duplicate of #671

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants