Skip to content

Caching requirements works only first time #25

Closed
@Lipen

Description

@Lipen

I have the following setup:

- uses: typst-community/setup-typst@v4
  with:
    cache-dependency-path: requirements.typ

- run: typst compile ...

The requirements.typ looks as follows:

#import "@preview/numbly:0.1.0"
#import "@preview/cetz:0.3.2"
// and more

The cache of dependencies does not include the packages which I add to requirements.typ incrementally. This can be observed when running typst compile in the consequent workflow steps after a "successful cache hit".
For example, I have added wrap-it to requirements.typ, but still can see it being downloaded each time I compile:

> typst compile ...
downloading @preview/wrap-it:0.1.0
...

As far as I understand, the "problem" is in the following lines: https://github.com/typst-community/setup-typst/blob/main/src/main.ts#L92-L98
You are using typst-packages-${hash} as a primary key, and ["typst-packages-", "typst-"] as additional restore keys. When I add something to requirements.typ, its hash changes, and the cache lookup misses on the primary key. However, it hits on the restore key "typst-packages-", restoring the previous cache, lacking the newly added packages. After that, cacheKey != undefined, and the action interprets is as OK situation, without trying to refine the deps and re-upload the cache. But I would expect the cache to be updated each time I add something to requirements.typ.

I would be nice to distinguish between "hit on primary key, no need to update cache" vs "hit on restore key, probably need to update the cache". However I do not see such functionality in actions/cache -- it either returns the key on any hit, or undefined on a miss -- so probably you will have to do two separate restoreCache queries.

Actually, when we miss on the primary cache (with hash), we do not even need to try to restore the previous one: it is probably better to simply re-download all deps from skratch using the updated requirements.typ, since some deps could be removed and do not need to be cached anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions