Skip to content

Commit

Permalink
feat!: add cache-restored output
Browse files Browse the repository at this point in the history
BREAKING CHANGE: change the condition under which `cache-hit` is set to `true`
  • Loading branch information
teatimeguest committed Oct 18, 2023
1 parent 4fdfffe commit bddc916
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ Linux, Windows, and macOS are supported.
GitHub Actions beginning the [transition to Node.js v20][actions-node20],
the action has upgraded its default runtime to Node.js v20.

- Change the condition under which `cache-hit` is set to `true`.

To be more consistent with official actions
such as [`actions/cache`][cache-hits],
the `cache-hit` output is now set to `true` only if
a cache is found that exactly matches the specified version and packages.
To simply check if a cache was found, use `cache-restored` instead:

```yaml
- name: Setup TeX Live
id: setup
uses: teatimeguest/setup-texlive-action@v3

- if: fromJSON(steps.setup.outputs.cache-restored)
run: echo 'A cache has been found'
```
- Change the default installation prefix to `$RUNNER_TEMP/setup-texlive-action`.
- Change the environment variable for updating cache to
`SETUP_TEXLIVE_ACTION_FORCE_UPDATE_CACHE`.
Expand Down Expand Up @@ -191,10 +208,11 @@ All inputs are optional.

## Outputs

| Name | Type | Description |
| ----------- | ------ | ----------------------------------------------- |
| `cache-hit` | Bool | A boolean value to indicate if a cache was hit. |
| `version` | String | The installed TeX Live version. |
| Name | Type | Description |
| ---------------- | ------ | -------------------------------------------------------------- |
| `cache-hit` | Bool | A boolean value to indicate if an exact cache match was found. |
| `cache-restored` | Bool | A boolean value to indicate if a cache was found. |
| `version` | String | The installed TeX Live version. |

## Environment Variables

Expand Down Expand Up @@ -266,6 +284,7 @@ See the [releases page][releases].
[actions-node20]: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/
[cache-api]: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-github-actions-caches-for-a-repository-using-a-cache-key
[cache-limits]: https://github.com/actions/cache#cache-limits
[cache-hits]: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#cache-hits-and-misses
[ci-badge]: https://github.com/teatimeguest/setup-texlive-action/actions/workflows/ci.yml/badge.svg
[ci]: https://github.com/teatimeguest/setup-texlive-action/actions/workflows/ci.yml
[codecov-badge]: https://codecov.io/gh/teatimeguest/setup-texlive-action/branch/main/graph/badge.svg?token=97878QAWCF
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ inputs:
required: false
outputs:
cache-hit:
description: A boolean value to indicate if a cache was hit.
description: >-
A boolean value to indicate if an exact match cache was found.
cache-restored:
description: >-
A boolean value to indicate if a cache was found.
version:
description: The installed TeX Live version.
runs:
Expand Down
3 changes: 2 additions & 1 deletion src/action/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export abstract class CacheService extends CacheInfo implements Disposable {
}

[Symbol.dispose](): void {
setOutput('cache-hit', this.restored);
setOutput('cache-hit', this.hit);
setOutput('cache-restored', this.restored);
}
}

Expand Down
30 changes: 29 additions & 1 deletion tests/__tests__/action/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ describe('DefaultCacheService', () => {
expect(() => service[Symbol.dispose]()).not.toThrow();
expect(core.setOutput).toHaveBeenCalledWith('cache-hit', false);
});

it('sets `cache-restored` to `false`', () => {
expect(() => service[Symbol.dispose]()).not.toThrow();
expect(core.setOutput).toHaveBeenCalledWith('cache-restored', false);
});
});

describe('ActionsCacheService', () => {
Expand Down Expand Up @@ -239,10 +244,13 @@ describe('ActionsCacheService', () => {
'oldunique',
'primary',
'oldprimary',
]],
[false, [
'secondary',
'oldsecondary',
'none',
'fail',
]],
[false, ['none', 'fail']],
] as const,
)('sets `cache-hit` to `%p`', (value, types) => {
it.each(types)('%p', async (type) => {
Expand All @@ -251,6 +259,26 @@ describe('ActionsCacheService', () => {
expect(core.setOutput).toHaveBeenCalledWith('cache-hit', value);
});
});

describe.each(
[
[true, [
'unique',
'oldunique',
'primary',
'oldprimary',
'secondary',
'oldsecondary',
]],
[false, ['none', 'fail']],
] as const,
)('sets `cache-restored` to `%p`', (value, types) => {
it.each(types)('%p', async (type) => {
jest.mocked(cache.restoreCache).mockImplementationOnce(restore[type]);
await expect(run()).toResolve();
expect(core.setOutput).toHaveBeenCalledWith('cache-restored', value);
});
});
});
});

Expand Down

0 comments on commit bddc916

Please sign in to comment.