Skip to content

Fix fail-on-cache-miss not working#1327

Merged
bethanyj28 merged 3 commits into
actions:mainfrom
cdce8p:fix-fail-on-cache-miss
Mar 19, 2024
Merged

Fix fail-on-cache-miss not working#1327
bethanyj28 merged 3 commits into
actions:mainfrom
cdce8p:fix-fail-on-cache-miss

Conversation

@cdce8p

@cdce8p cdce8p commented Feb 15, 2024

Copy link
Copy Markdown
Contributor

Description

process.exit overwrites the exit code set by core.setFailed, e.g. the workflow would continue even though fail-on-cache-miss is set and no cache is found.

Originally introduced in

/CC @kgrzebien

Motivation and Context

Fixes #1265

How Has This Been Tested?

Created a workflow which should restore a non-existing cache. With v4.0.0 the workflow continues, with this PR it fails as expected (with fail-on-cache-miss set).

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (add or update README or docs)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@cdce8p cdce8p requested a review from a team as a code owner February 15, 2024 21:20
@cdce8p cdce8p changed the title Fixfail-on-cache-miss not working Fix fail-on-cache-miss not working Feb 15, 2024
@cdce8p

cdce8p commented Mar 1, 2024

Copy link
Copy Markdown
Contributor Author

/CC @bethanyj28 Would you mind taking a look at this one? It fixes a bug which was just recently introduced.

@bethanyj28

Copy link
Copy Markdown
Contributor

@cdce8p - thanks for the contribution! This seems reasonable to me. Could you add a test case in https://github.com/actions/cache/blob/main/__tests__/restoreImpl.test.ts to validate? Thank you!

@cdce8p

cdce8p commented Mar 1, 2024

Copy link
Copy Markdown
Contributor Author

This seems reasonable to me. Could you add a test case in https://github.com/actions/cache/blob/main/__tests__/restoreImpl.test.ts to validate? Thank you!

I thought about that but I'm not really sure how to do it. The only thing not tested is process.exit(1); however from what I've read online it's difficult to test that with jest. Tbh I wouldn't consider myself an expert in that area. If you've any pointers for me that would be appreciated.

I already looked at #1217 which first introduced the process.exit but AFAICT it didn't add any tests either.

@bethanyj28

Copy link
Copy Markdown
Contributor

👋🏻 @cdce8p - sorry for the delay! While the initial change might've not had tests, it would be really nice to validate in the future that we don't regress here. I believe mocking process.exit isn't too bad in jest. Could you do something like this?

test("restore failure with earlyExit should call process exit", async () => {
    // mock `process.exit`
    const processExitMock = jest.spyOn(process, "exit").mockImplementation();

    // simulate a failure
    testUtils.setInput(Inputs.Path, "node_modules");
    const failedMock = jest.spyOn(core, "setFailed");
    const restoreCacheMock = jest.spyOn(cache, "restoreCache");

    // set true for `earlyExit`
    await restoreImpl(new StateProvider(), true);
    expect(restoreCacheMock).toHaveBeenCalledTimes(0);
    expect(failedMock).toHaveBeenCalledWith(
        "Input required and not supplied: key"
    );

    // validate `process.exit` called
    expect(processExitMock).toHaveBeenCalledWith(1);
});

Thank you!

Co-authored-by: Bethany <bethanyj28@users.noreply.github.com>

@bethanyj28 bethanyj28 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@bethanyj28 bethanyj28 merged commit 0c45773 into actions:main Mar 19, 2024
@cdce8p cdce8p deleted the fix-fail-on-cache-miss branch March 19, 2024 13:32
@cdce8p

cdce8p commented Mar 19, 2024

Copy link
Copy Markdown
Contributor Author

@bethanyj28 Would you mind tagging the 4.0.2 release? It would be awesome if this bug would finally be fixed.
I already updated the version in package.json and the changelog in this PR.

@bethanyj28

Copy link
Copy Markdown
Contributor

Definitely! I appreciate you updating the version 🙏🏻

Bzomak added a commit to Bzomak/oolite-msys2 that referenced this pull request Mar 22, 2024
github-actions Bot pushed a commit to cirruslabs/cache that referenced this pull request Apr 8, 2024
@Emmanuelruina

Copy link
Copy Markdown

CACHING ACTION

jonathanperret added a commit to jonathanperret/ayab-desktop that referenced this pull request Jul 12, 2024
Mainly to fix the fact that fail-on-cache-miss doesn't work, see actions/cache#1327
jonathanperret added a commit to jonathanperret/ayab-desktop that referenced this pull request Jul 12, 2024
Mainly to fix the fact that fail-on-cache-miss doesn't work, see actions/cache#1327
jonathanperret added a commit to jonathanperret/ayab-desktop that referenced this pull request Sep 8, 2024
Mainly to fix the fact that fail-on-cache-miss doesn't work, see actions/cache#1327
jonathanperret added a commit to jonathanperret/ayab-desktop that referenced this pull request Sep 8, 2024
Fixes build slowness (AllYarnsAreBeautiful#702).

Also fixes fail-on-cache-miss having no effect, see
actions/cache#1327
dl1com pushed a commit to AllYarnsAreBeautiful/ayab-desktop that referenced this pull request Sep 9, 2024
Fixes build slowness (#702).

Also fixes fail-on-cache-miss having no effect, see
actions/cache#1327
fbidu added a commit to fbidu/cookie-py that referenced this pull request Jun 16, 2026
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [actions/cache](https://github.com/actions/cache) | major | `v4` → `v5.0.5` |

---

### Release Notes

<details>
<summary>actions/cache (actions/cache)</summary>

### [`v5.0.5`](https://github.com/actions/cache/releases/tag/v5.0.5)

[Compare Source](actions/cache@v5.0.4...v5.0.5)

#### What's Changed

- Update ts-http-runtime dependency by [@&#8203;yacaovsnc](https://github.com/yacaovsnc) in [#&#8203;1747](actions/cache#1747)

**Full Changelog**: <actions/cache@v5...v5.0.5>

### [`v5.0.4`](https://github.com/actions/cache/releases/tag/v5.0.4)

[Compare Source](actions/cache@v5.0.3...v5.0.4)

#### What's Changed

- Add release instructions and update maintainer docs by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1696](actions/cache#1696)
- Potential fix for code scanning alert no. 52: Workflow does not contain permissions by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1697](actions/cache#1697)
- Fix workflow permissions and cleanup workflow names / formatting by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1699](actions/cache#1699)
- docs: Update examples to use the latest version by [@&#8203;XZTDean](https://github.com/XZTDean) in [#&#8203;1690](actions/cache#1690)
- Fix proxy integration tests by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1701](actions/cache#1701)
- Fix cache key in examples.md for bun.lock by [@&#8203;RyPeck](https://github.com/RyPeck) in [#&#8203;1722](actions/cache#1722)
- Update dependencies & patch security vulnerabilities by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1738](actions/cache#1738)

#### New Contributors

- [@&#8203;XZTDean](https://github.com/XZTDean) made their first contribution in [#&#8203;1690](actions/cache#1690)
- [@&#8203;RyPeck](https://github.com/RyPeck) made their first contribution in [#&#8203;1722](actions/cache#1722)

**Full Changelog**: <actions/cache@v5...v5.0.4>

### [`v5.0.3`](https://github.com/actions/cache/releases/tag/v5.0.3)

[Compare Source](actions/cache@v5.0.2...v5.0.3)

#### What's Changed

- Bump `@actions/cache` to v5.0.5 (Resolves: <https://github.com/actions/cache/security/dependabot/33>)
- Bump `@actions/core` to v2.0.3

**Full Changelog**: <actions/cache@v5...v5.0.3>

### [`v5.0.2`](https://github.com/actions/cache/releases/tag/v5.0.2): v.5.0.2

[Compare Source](actions/cache@v5.0.1...v5.0.2)

### v5.0.2

#### What's Changed

When creating cache entries, 429s returned from the cache service will not be retried.

### [`v5.0.1`](https://github.com/actions/cache/releases/tag/v5.0.1)

[Compare Source](actions/cache@v5...v5.0.1)

> \[!IMPORTANT]
> **`actions/cache@v5` runs on the Node.js 24 runtime and requires a minimum Actions Runner version of `2.327.1`.**
>
> If you are using self-hosted runners, ensure they are updated before upgrading.

***

### v5.0.1

#### What's Changed

- fix: update [@&#8203;actions/cache](https://github.com/actions/cache) for Node.js 24 punycode deprecation by [@&#8203;salmanmkc](https://github.com/salmanmkc) in [#&#8203;1685](actions/cache#1685)
- prepare release v5.0.1 by [@&#8203;salmanmkc](https://github.com/salmanmkc) in [#&#8203;1686](actions/cache#1686)

### v5.0.0

#### What's Changed

- Upgrade to use node24 by [@&#8203;salmanmkc](https://github.com/salmanmkc) in [#&#8203;1630](actions/cache#1630)
- Prepare v5.0.0 release by [@&#8203;salmanmkc](https://github.com/salmanmkc) in [#&#8203;1684](actions/cache#1684)

**Full Changelog**: <actions/cache@v5...v5.0.1>

### [`v5.0.0`](https://github.com/actions/cache/releases/tag/v5.0.0)

[Compare Source](actions/cache@v5...v5)

> \[!IMPORTANT]
> **`actions/cache@v5` runs on the Node.js 24 runtime and requires a minimum Actions Runner version of `2.327.1`.**
>
> If you are using self-hosted runners, ensure they are updated before upgrading.

***

#### What's Changed

- Upgrade to use node24 by [@&#8203;salmanmkc](https://github.com/salmanmkc) in [#&#8203;1630](actions/cache#1630)
- Prepare v5.0.0 release by [@&#8203;salmanmkc](https://github.com/salmanmkc) in [#&#8203;1684](actions/cache#1684)

**Full Changelog**: <actions/cache@v4.3.0...v5.0.0>

### [`v5`](actions/cache@v4.3.0...v5)

[Compare Source](actions/cache@v4.3.0...v5)

### [`v4.3.0`](https://github.com/actions/cache/releases/tag/v4.3.0)

[Compare Source](actions/cache@v4.2.4...v4.3.0)

#### What's Changed

- Add note on runner versions by [@&#8203;GhadimiR](https://github.com/GhadimiR) in [#&#8203;1642](actions/cache#1642)
- Prepare `v4.3.0` release by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1655](actions/cache#1655)

#### New Contributors

- [@&#8203;GhadimiR](https://github.com/GhadimiR) made their first contribution in [#&#8203;1642](actions/cache#1642)

**Full Changelog**: <actions/cache@v4...v4.3.0>

### [`v4.2.4`](https://github.com/actions/cache/releases/tag/v4.2.4)

[Compare Source](actions/cache@v4.2.3...v4.2.4)

#### What's Changed

- Update README.md by [@&#8203;nebuk89](https://github.com/nebuk89) in [#&#8203;1620](actions/cache#1620)
- Upgrade `@actions/cache` to `4.0.5` and move `@protobuf-ts/plugin` to dev depdencies by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1634](actions/cache#1634)
- Prepare release `4.2.4` by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1636](actions/cache#1636)

#### New Contributors

- [@&#8203;nebuk89](https://github.com/nebuk89) made their first contribution in [#&#8203;1620](actions/cache#1620)

**Full Changelog**: <actions/cache@v4...v4.2.4>

### [`v4.2.3`](https://github.com/actions/cache/releases/tag/v4.2.3)

[Compare Source](actions/cache@v4.2.2...v4.2.3)

#### What's Changed

- Update to use [@&#8203;actions/cache](https://github.com/actions/cache) 4.0.3 package & prepare for new release by [@&#8203;salmanmkc](https://github.com/salmanmkc) in [#&#8203;1577](actions/cache#1577) (SAS tokens for cache entries are now masked in debug logs)

#### New Contributors

- [@&#8203;salmanmkc](https://github.com/salmanmkc) made their first contribution in [#&#8203;1577](actions/cache#1577)

**Full Changelog**: <actions/cache@v4.2.2...v4.2.3>

### [`v4.2.2`](https://github.com/actions/cache/releases/tag/v4.2.2)

[Compare Source](actions/cache@v4.2.1...v4.2.2)

#### What's Changed

> \[!IMPORTANT]
> As a reminder, there were important backend changes to release v4.2.0, see [those release notes](https://github.com/actions/cache/releases/tag/v4.2.0) and [the announcement](actions/cache#1510) for more details.

- Bump [@&#8203;actions/cache](https://github.com/actions/cache) to v4.0.2 by [@&#8203;robherley](https://github.com/robherley) in [#&#8203;1560](actions/cache#1560)

**Full Changelog**: <actions/cache@v4.2.1...v4.2.2>

### [`v4.2.1`](https://github.com/actions/cache/releases/tag/v4.2.1)

[Compare Source](actions/cache@v4.2.0...v4.2.1)

#### What's Changed

> \[!IMPORTANT]
> As a reminder, there were important backend changes to release v4.2.0, see [those release notes](https://github.com/actions/cache/releases/tag/v4.2.0) and [the announcement](actions/cache#1510) for more details.

- docs: GitHub is spelled incorrectly in caching-strategies.md by [@&#8203;janco-absa](https://github.com/janco-absa) in [#&#8203;1526](actions/cache#1526)
- docs: Make the "always save prime numbers" example more clear by [@&#8203;Tobbe](https://github.com/Tobbe) in [#&#8203;1525](actions/cache#1525)
- Update force deletion docs due a recent deprecation by [@&#8203;sebbalex](https://github.com/sebbalex) in [#&#8203;1500](actions/cache#1500)
- Bump [@&#8203;actions/cache](https://github.com/actions/cache) to v4.0.1 by [@&#8203;robherley](https://github.com/robherley) in [#&#8203;1554](actions/cache#1554)

#### New Contributors

- [@&#8203;janco-absa](https://github.com/janco-absa) made their first contribution in [#&#8203;1526](actions/cache#1526)
- [@&#8203;Tobbe](https://github.com/Tobbe) made their first contribution in [#&#8203;1525](actions/cache#1525)
- [@&#8203;sebbalex](https://github.com/sebbalex) made their first contribution in [#&#8203;1500](actions/cache#1500)

**Full Changelog**: <actions/cache@v4.2.0...v4.2.1>

### [`v4.2.0`](https://github.com/actions/cache/releases/tag/v4.2.0)

[Compare Source](actions/cache@v4.1.2...v4.2.0)

#### ⚠️ Important Changes

The cache backend service has been rewritten from the ground up for improved performance and reliability. [actions/cache](https://github.com/actions/cache) now integrates with the new cache service (v2) APIs.

The new service will gradually roll out as of **February 1st, 2025**. The legacy service will also be sunset on the same date. Changes in these release are **fully backward compatible**.

**We are deprecating some versions of this action**. We recommend upgrading to version `v4` or `v3` as soon as possible before **February 1st, 2025.** (Upgrade instructions below).

If you are using pinned SHAs, please use the SHAs of versions `v4.2.0` or `v3.4.0`

If you do not upgrade, all workflow runs using any of the deprecated [actions/cache](https://github.com/actions/cache) will fail.

Upgrading to the recommended versions will not break your workflows.

Read more about the change & access the migration guide: [reference to the announcement](actions/cache#1510).

##### Minor changes

Minor and patch version updates for these dependencies:

- [@&#8203;actions/core](https://github.com/actions/core): `1.11.1`
- [@&#8203;actions/io](https://github.com/actions/io): `1.1.3`
- [@&#8203;vercel/ncc](https://github.com/vercel/ncc): `0.38.3`

**Full Changelog**: <actions/cache@v4.1.2...v4.2.0>

### [`v4.1.2`](https://github.com/actions/cache/releases/tag/v4.1.2)

[Compare Source](actions/cache@v4.1.1...v4.1.2)

#### What's Changed

- Add Bun example by [@&#8203;idleberg](https://github.com/idleberg) in [#&#8203;1456](actions/cache#1456)
- Revise `isGhes` logic by [@&#8203;jww3](https://github.com/jww3) in [#&#8203;1474](actions/cache#1474)
- Bump braces from 3.0.2 to 3.0.3 by [@&#8203;dependabot](https://github.com/dependabot) in [#&#8203;1475](actions/cache#1475)
- Add dependabot.yml to enable automatic dependency upgrades by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1476](actions/cache#1476)
- Bump actions/checkout from 3 to 4 by [@&#8203;dependabot](https://github.com/dependabot) in [#&#8203;1478](actions/cache#1478)
- Bump actions/stale from 3 to 9 by [@&#8203;dependabot](https://github.com/dependabot) in [#&#8203;1479](actions/cache#1479)
- Bump github/codeql-action from 2 to 3 by [@&#8203;dependabot](https://github.com/dependabot) in [#&#8203;1483](actions/cache#1483)
- Bump actions/setup-node from 3 to 4 by [@&#8203;dependabot](https://github.com/dependabot) in [#&#8203;1481](actions/cache#1481)
- Prepare `4.1.2` release by [@&#8203;Link-](https://github.com/Link-) in [#&#8203;1477](actions/cache#1477)

#### New Contributors

- [@&#8203;idleberg](https://github.com/idleberg) made their first contribution in [#&#8203;1456](actions/cache#1456)
- [@&#8203;jww3](https://github.com/jww3) made their first contribution in [#&#8203;1474](actions/cache#1474)
- [@&#8203;Link-](https://github.com/Link-) made their first contribution in [#&#8203;1476](actions/cache#1476)

**Full Changelog**: <actions/cache@v4.1.1...v4.1.2>

### [`v4.1.1`](https://github.com/actions/cache/releases/tag/v4.1.1)

[Compare Source](actions/cache@v4.1.0...v4.1.1)

#### What's Changed

- Restore original behavior of `cache-hit` output by [@&#8203;joshmgross](https://github.com/joshmgross) in [#&#8203;1467](actions/cache#1467)

**Full Changelog**: <actions/cache@v4.1.0...v4.1.1>

### [`v4.1.0`](https://github.com/actions/cache/releases/tag/v4.1.0)

[Compare Source](actions/cache@v4.0.2...v4.1.0)

#### What's Changed

- Fix cache-hit output when cache missed by [@&#8203;fchimpan](https://github.com/fchimpan) in [#&#8203;1404](actions/cache#1404)
- Deprecate `save-always` input by [@&#8203;joshmgross](https://github.com/joshmgross) in [#&#8203;1452](actions/cache#1452)

#### New Contributors

- [@&#8203;ottlinger](https://github.com/ottlinger) made their first contribution in [#&#8203;1437](actions/cache#1437)
- [@&#8203;Olegt0rr](https://github.com/Olegt0rr) made their first contribution in [#&#8203;1377](actions/cache#1377)
- [@&#8203;fchimpan](https://github.com/fchimpan) made their first contribution in [#&#8203;1404](actions/cache#1404)
- [@&#8203;x612skm](https://github.com/x612skm) made their first contribution in [#&#8203;1434](actions/cache#1434)
- [@&#8203;todgru](https://github.com/todgru) made their first contribution in [#&#8203;1311](actions/cache#1311)
- [@&#8203;Jcambass](https://github.com/Jcambass) made their first contribution in [#&#8203;1463](actions/cache#1463)
- [@&#8203;mackey0225](https://github.com/mackey0225) made their first contribution in [#&#8203;1462](actions/cache#1462)
- [@&#8203;quatquatt](https://github.com/quatquatt) made their first contribution in [#&#8203;1445](actions/cache#1445)

**Full Changelog**: <actions/cache@v4.0.2...v4.1.0>

### [`v4.0.2`](https://github.com/actions/cache/releases/tag/v4.0.2)

[Compare Source](actions/cache@v4.0.1...v4.0.2)

#### What's Changed

- Fix `fail-on-cache-miss` not working by [@&#8203;cdce8p](https://github.com/cdce8p) in [#&#8203;1327](actions/cache#1327)

**Full Changelog**: <actions/cache@v4.0.1...v4.0.2>

### [`v4.0.1`](https://github.com/actions/cache/releases/tag/v4.0.1)

[Compare Source](actions/cache@v4...v4.0.1)

#### What's Changed

- Update README.md by [@&#8203;yacaovsnc](https://github.com/yacaovsnc) in [#&#8203;1304](actions/cache#1304)
- Update examples by [@&#8203;yacaovsnc](https://github.com/yacaovsnc) in [#&#8203;1305](actions/cache#1305)
- Update actions/cache publish flow by [@&#8203;bethanyj28](https://github.com/bethanyj28) in [#&#8203;1340](actions/cache#1340)
- Update [@&#8203;actions/cache](https://github.com/actions/cache) by [@&#8203;bethanyj28](https://github.com/bethanyj28) in [#&#8203;1341](actions/cache#1341)

#### New Contributors

- [@&#8203;yacaovsnc](https://github.com/yacaovsnc) made their first contribution in [#&#8203;1304](actions/cache#1304)

**Full Changelog**: <actions/cache@v4...v4.0.1>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yMTQuNCIsInVwZGF0ZWRJblZlciI6IjQzLjIxNC40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJ0ZW1wbGF0ZSJdfQ==-->

Reviewed-on: https://git.lx.e6a.app/tools/cookie-py/pulls/86
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 this pull request may close these issues.

fail-on-cache-miss for restore action not failing the workflow

4 participants