Unverified Commit c17f4bf4 authored by Sankalp Kotewar's avatar Sankalp Kotewar Committed by GitHub
Browse files

GA for granular cache (#1035)

* Add example for Haskell Stack

* Revert "Add example for Haskell Stack"

* Basic implementation

* Updated variable name

* Adding wrapper class

* Changed logs to warnings

* added debug logs

* experimenting

* Test

* test

* new try

* test

* Impl separated

* Reverted wrapper changes

* Added test cases

* Some cleanup

* Formatted document

* Fixed test cases issues

* Slight modification for test cases check

* Updated new actions' input descriptions

* Reverted custom asks implemented and added wrapper

* refactor into a generic outputter

* Readme draft for new actions

* Generated dist

* Fixed breaking test case

* Removed return type in promise

* Removed commented lines

* Calling methods from same file

* dist

* update save as well

* fix merge

* Changes for beta release

* Update dist folder

* Fixed formatting

* dist

* Add support for gzip fallback for restore of old cache on windows

* Fixed test cases

* Fixed test cases

* Added restore only and save only test cases

* Updated new actions dist files

* Removed comments

* Fixed inputs

* Renamed variables and added tests

* Fixed breaking test case

* Fixed review comments and tests

* added stateprovider changes

* Deleted stateprovider tests until added

* Added stateprovider test cases

* Fixed breaking test case

* Updated outputs of restore action

* Changes for beta release

* Update dist folder

* Add support for gzip fallback for restore of old cache on windows

* update for new beta release

* Update save/action.yml

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Update restore/action.yml

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Update restore/action.yml

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Update restore/action.yml

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Update restore/action.yml

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Added more assertions as values can't be checked

* Removed unused code

* Merged beta branch and resolved conflicts

* Added save readme

* Updates to save readme

* Renamed output

* Added cache hit info in readme

* Update restore/README.md

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Update restore/README.md

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Update restore/README.md

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Update save/README.md

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Update save/README.md

Co-authored-by: default avatarBishal Prasad <[email protected]>

* Removed verbose statements

* Repositioned new actions introduction

* Added test case for restore state

* Addressed review comments

* nit

* nit: added language to code blocks

* Updated beta version to 3.2.0-beta.1

* Added stateprovider mock implementations

* Linting errors fixed

* Save-only warning added

* Updated return ID to -2

* Removed -2 error code

* Removed comment

* Updated cache npm lib version

* Updated license version

* Updated releases.md

* Updated readme with the new actions in what's new

Co-authored-by: default avatarMalo Bourgon <[email protected]>
Co-authored-by: default avatarVipul <[email protected]>
Co-authored-by: default avatarBishal Prasad <[email protected]>
Co-authored-by: default avatarTanuj Kumar Mishra <[email protected]>
Co-authored-by: default avatarSampark Sharma <[email protected]>
parent ac25611c
Loading
Loading
Loading
Loading
+14
Changes for .devcontainer/devcontainer.json: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
{
	"name": "Node.js & TypeScript",
	"image": "mcr.microsoft.com/devcontainers/typescript-node:16-bullseye",
	// Features to add to the dev container. More info: https://containers.dev/implementors/features.
	// "features": {},
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],
	// Use 'postCreateCommand' to run commands after the container is created.
	"postCreateCommand": "npm install"
	// Configure tool-specific properties.
	// "customizations": {},
	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "root"
}

File changed.

Preview suppressed by a .gitattributes entry or the file's encoding is unsupported.

+8
Changes for README.md: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,12 +2,19 @@

This action allows caching dependencies and build outputs to improve workflow execution time.

In addition to this `cache` action, other two actions are also available

[Restore action](./restore/README.md)

[Save action](./save/README.md)

[![Tests](https://github.com/actions/cache/actions/workflows/workflow.yml/badge.svg)](https://github.com/actions/cache/actions/workflows/workflow.yml)

## Documentation

See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows).


## What's New
### v3
* Added support for caching from GHES 3.5.
@@ -20,6 +27,7 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
* Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
* Fix zstd not working for windows on gnu tar in issues.
* Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 60 minutes.
* Two new actions available for granular control over caches - [restore](restore/action.yml) and [save](save/action.yml)

Refer [here](https://github.com/actions/cache/blob/v2/README.md) for previous versions

+15
Changes for RELEASES.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -40,3 +40,18 @@
### 3.0.11
- Update toolkit version to 3.0.5 to include `@actions/core@^1.10.0`
- Update `@actions/cache` to use updated `saveState` and `setOutput` functions from `@actions/core@^1.10.0`

### 3.1.0-beta.1
- Update `@actions/cache` on windows to use gnu tar and zstd by default and fallback to bsdtar and zstd if gnu tar is not available. ([issue](https://github.com/actions/cache/issues/984))

### 3.1.0-beta.2
- Added support for fallback to gzip to restore old caches on windows.

### 3.1.0-beta.3
- Bug fixes for bsdtar fallback if gnutar not available and gzip fallback if cache saved using old cache action on windows.

### 3.2.0-beta.1
- Added two new actions - [restore](restore/action.yml) and [save](save/action.yml) for granular control on cache.

### 3.2.0
- Released the two new actions - [restore](restore/action.yml) and [save](save/action.yml) for granular control on cache
 No newline at end of file
+1 −78
Changes for __tests__/actionUtils.test.ts: 1 added line, 78 removed lines.
Original line number Diff line number Diff line
import * as cache from "@actions/cache";
import * as core from "@actions/core";

import { Events, Outputs, RefKey, State } from "../src/constants";
import { Events, RefKey } from "../src/constants";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";

@@ -79,83 +79,6 @@ test("isExactKeyMatch with same key and different casing returns true", () => {
    expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true);
});

test("setOutputAndState with undefined entry to set cache-hit output", () => {
    const key = "linux-rust";
    const cacheKey = undefined;

    const setOutputMock = jest.spyOn(core, "setOutput");
    const saveStateMock = jest.spyOn(core, "saveState");

    actionUtils.setOutputAndState(key, cacheKey);

    expect(setOutputMock).toHaveBeenCalledWith(Outputs.CacheHit, "false");
    expect(setOutputMock).toHaveBeenCalledTimes(1);

    expect(saveStateMock).toHaveBeenCalledTimes(0);
});

test("setOutputAndState with exact match to set cache-hit output and state", () => {
    const key = "linux-rust";
    const cacheKey = "linux-rust";

    const setOutputMock = jest.spyOn(core, "setOutput");
    const saveStateMock = jest.spyOn(core, "saveState");

    actionUtils.setOutputAndState(key, cacheKey);

    expect(setOutputMock).toHaveBeenCalledWith(Outputs.CacheHit, "true");
    expect(setOutputMock).toHaveBeenCalledTimes(1);

    expect(saveStateMock).toHaveBeenCalledWith(State.CacheMatchedKey, cacheKey);
    expect(saveStateMock).toHaveBeenCalledTimes(1);
});

test("setOutputAndState with no exact match to set cache-hit output and state", () => {
    const key = "linux-rust";
    const cacheKey = "linux-rust-bb828da54c148048dd17899ba9fda624811cfb43";

    const setOutputMock = jest.spyOn(core, "setOutput");
    const saveStateMock = jest.spyOn(core, "saveState");

    actionUtils.setOutputAndState(key, cacheKey);

    expect(setOutputMock).toHaveBeenCalledWith(Outputs.CacheHit, "false");
    expect(setOutputMock).toHaveBeenCalledTimes(1);

    expect(saveStateMock).toHaveBeenCalledWith(State.CacheMatchedKey, cacheKey);
    expect(saveStateMock).toHaveBeenCalledTimes(1);
});

test("getCacheState with no state returns undefined", () => {
    const getStateMock = jest.spyOn(core, "getState");
    getStateMock.mockImplementation(() => {
        return "";
    });

    const state = actionUtils.getCacheState();

    expect(state).toBe(undefined);

    expect(getStateMock).toHaveBeenCalledWith(State.CacheMatchedKey);
    expect(getStateMock).toHaveBeenCalledTimes(1);
});

test("getCacheState with valid state", () => {
    const cacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";

    const getStateMock = jest.spyOn(core, "getState");
    getStateMock.mockImplementation(() => {
        return cacheKey;
    });

    const state = actionUtils.getCacheState();

    expect(state).toEqual(cacheKey);

    expect(getStateMock).toHaveBeenCalledWith(State.CacheMatchedKey);
    expect(getStateMock).toHaveBeenCalledTimes(1);
});

test("logWarning logs a message with a warning prefix", () => {
    const message = "A warning occurred.";

Loading