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

Should configure ccache before restore cache #17

Closed
zhongfly opened this issue Dec 22, 2023 · 9 comments
Closed

Should configure ccache before restore cache #17

zhongfly opened this issue Dec 22, 2023 · 9 comments

Comments

@zhongfly
Copy link

If set cache_dir to another place,it will make restore cache never success.
Example:

- name: Set up ccache
  uses: Chocobo1/setup-ccache-action@v1
  with:
    ccache_options: |
      cache_dir=${{ env.workspace }}/.ccache

So I think it should configure ccache before restore cache.

@zhongfly
Copy link
Author

One thing more, don't run updatePackgerIndex if install_ccache is false.

@Chocobo1
Copy link
Owner

If set cache_dir to another place,it will make restore cache never success.

I resolved it in 64fc5fd.
Thanks for reporting!

@zhongfly
Copy link
Author

zhongfly commented Dec 31, 2023

Still have problem with env:
example:cache_dir=$GITHUB_WORKSPACE/.ccache
This action will save cache in path /__w/my-repo-name/my-repo-name/.ccache(run job in a docker image) or /home/runner/work/my-repo-name/my-repo-name/.ccache, but restore cache using $GITHUB_WORKSPACE/.ccache.
So restore will always fail.
You can find $GITHUB_WORKSPACE in https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

@Chocobo1 my pr can fix this, but 64fc5fd can't.
In my opinion, #19 simply solves the problem and avoids the bugs that restore cache and save cache use different paths

@Chocobo1
Copy link
Owner

example:cache_dir=$GITHUB_WORKSPACE/.ccache

Strictly speaking it is invalid to use environment variables here. Use cache_dir=${{ github.workspace }}/.ccache instead.
Here we are not invoking ccache via shell but from "github actions" context so environment variables aren't resolved (at least github actions chooses not to).
However, I do agree that this is a bit unexpected for the common users. I'll ponder on it.

In my opinion, #19 simply solves the problem and avoids the bugs that restore cache and save cache use different paths

I'm concerned that if the ccache config resides within the cache path and after cache restore it will overwritten the configuration. I don't consider it correct.

@Chocobo1
Copy link
Owner

Strictly speaking it is invalid to use environment variables here. Use cache_dir=${{ github.workspace }}/.ccache instead.
Here we are not invoking ccache via shell but from "github actions" context so environment variables aren't resolved (at least github actions chooses not to).

I think this is the relevant documentation:
https://docs.github.com/en/actions/learn-github-actions/variables#using-the-env-context-to-access-environment-variable-values

The run steps in a workflow, or in a referenced action, are processed by a runner. As a result, you can use runner environment variables here, using the appropriate syntax for the shell you are using on the runner - for example, $NAME for the bash shell on a Linux runner, or $env:NAME for PowerShell on a Windows runner. In most cases you can also use contexts, with the syntax ${{ CONTEXT.PROPERTY }}, to access the same value. The difference is that the context will be interpolated and replaced by a string before the job is sent to a runner.

However, you cannot use runner environment variables in parts of a workflow that are processed by GitHub Actions and are not sent to the runner. Instead, you must use contexts.

And as I mentioned, setup-ccache-action is processed by GitHub Actions not via a runner/shell.

https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

However, most of the default variables have a corresponding, and similarly named, context property. For example, the value of the GITHUB_REF variable can be read during workflow processing using the ${{ github.ref }} context property.

Also it seems to me that github have already known this (downside) and decided to provide both context properties and runner env variables.

@zhongfly
Copy link
Author

zhongfly commented Dec 31, 2023

Strictly speaking it is invalid to use environment variables here. Use cache_dir=${{ github.workspace }}/.ccache instead.

In most cases you can also use contexts, with the syntax ${{ CONTEXT.PROPERTY }}, to access the same value.

Yes, but $GITHUB_WORKSPACE and ${{ github.workspace}} are different for job running in a container.
see this actions/checkout#785 and actions/runner#2058

Example:

name: archlinux

on: workflow_dispatch

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: archlinux/archlinux:base-devel
    steps:
      - run: echo "${{ github.workspace }}" ; echo "$GITHUB_WORKSPACE"

${{ github.workspace }} is /home/runner/work/..., but $GITHUB_WORKSPACE is /__w/...

Github action does have some weirdness to it.

@zhongfly
Copy link
Author

zhongfly commented Dec 31, 2023

I think the main problem is that the paths to save cache and restore cache have to be exactly the same in terms of characters.
Either both prioritize the value of ccache_options or both prioritize the value in the config file. Instead of using different values as it is now

const paths = [Path.normalize(await Utils.getCachePath())];

return [Path.normalize(userDefinedDir ?? await Utils.getCachePath())];

@Chocobo1
Copy link
Owner

${{ github.workspace }} is /home/runner/work/..., but $GITHUB_WORKSPACE is /__w/...

Github action does have some weirdness to it.

True and they still haven't address it yet...

Not sure if you are still looking for a workaround but just in case, perhaps the following will work:

  # export variable
  - run: echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE" >> $GITHUB_ENV
  # use variable
  - name: Set up ccache
    uses: Chocobo1/setup-ccache-action@v1
    with:
      ccache_options: |
        cache_dir=${{ env.GITHUB_WORKSPACE }}/.ccache

@zhongfly
Copy link
Author

Earlier you talked about the possibility of overwriting the config file when restoring cache, so set the option after restoring.So maybe we can set the option cache_dir both before and after restore

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

Successfully merging a pull request may close this issue.

2 participants