Compare commits
	
		
			18 Commits
		
	
	
		
			tanuj077/c
			...
			phantsure/
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					d48d03435b | ||
| 
						 | 
					593e91a38b | ||
| 
						 | 
					e4c2242eff | ||
| 
						 | 
					fb86cbf360 | ||
| 
						 | 
					a57932faba | ||
| 
						 | 
					04b13caea4 | ||
| 
						 | 
					941bc71a24 | ||
| 
						 | 
					08d8639046 | ||
| 
						 | 
					a2f324eeb7 | ||
| 
						 | 
					35f4702f6c | ||
| 
						 | 
					e050ebdd63 | ||
| 
						 | 
					0d47d164e9 | ||
| 
						 | 
					e2d614414f | ||
| 
						 | 
					532752012e | ||
| 
						 | 
					b26da1fc31 | ||
| 
						 | 
					ce61cc4d24 | ||
| 
						 | 
					268ae08cbc | ||
| 
						 | 
					7920f570b8 | 
@@ -1,14 +0,0 @@
 | 
				
			|||||||
{
 | 
					 | 
				
			||||||
	"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 && npm run build"
 | 
					 | 
				
			||||||
	// Configure tool-specific properties.
 | 
					 | 
				
			||||||
	// "customizations": {},
 | 
					 | 
				
			||||||
	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
 | 
					 | 
				
			||||||
	// "remoteUser": "root"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										1
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							@@ -27,6 +27,7 @@ jobs:
 | 
				
			|||||||
        uses: actions/setup-node@v3
 | 
					        uses: actions/setup-node@v3
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          node-version: 16.x
 | 
					          node-version: 16.x
 | 
				
			||||||
 | 
					          cache: npm
 | 
				
			||||||
      - name: Install dependencies
 | 
					      - name: Install dependencies
 | 
				
			||||||
        run: npm ci
 | 
					        run: npm ci
 | 
				
			||||||
      - name: Rebuild the dist/ directory
 | 
					      - name: Rebuild the dist/ directory
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								.github/workflows/workflow.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								.github/workflows/workflow.yml
									
									
									
									
										vendored
									
									
								
							@@ -25,17 +25,7 @@ jobs:
 | 
				
			|||||||
      uses: actions/setup-node@v3
 | 
					      uses: actions/setup-node@v3
 | 
				
			||||||
      with:
 | 
					      with:
 | 
				
			||||||
        node-version: 16.x
 | 
					        node-version: 16.x
 | 
				
			||||||
    - name: Determine npm cache directory
 | 
					        cache: npm
 | 
				
			||||||
      id: npm-cache
 | 
					 | 
				
			||||||
      run: |
 | 
					 | 
				
			||||||
        echo "::set-output name=dir::$(npm config get cache)"
 | 
					 | 
				
			||||||
    - name: Restore npm cache
 | 
					 | 
				
			||||||
      uses: actions/cache@v3
 | 
					 | 
				
			||||||
      with:
 | 
					 | 
				
			||||||
        path: ${{ steps.npm-cache.outputs.dir }}
 | 
					 | 
				
			||||||
        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
 | 
					 | 
				
			||||||
        restore-keys: |
 | 
					 | 
				
			||||||
          ${{ runner.os }}-node-
 | 
					 | 
				
			||||||
    - run: npm ci
 | 
					    - run: npm ci
 | 
				
			||||||
    - name: Prettier Format Check
 | 
					    - name: Prettier Format Check
 | 
				
			||||||
      run: npm run format-check
 | 
					      run: npm run format-check
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,3 +40,9 @@
 | 
				
			|||||||
### 3.0.11
 | 
					### 3.0.11
 | 
				
			||||||
- Update toolkit version to 3.0.5 to include `@actions/core@^1.10.0`
 | 
					- 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`
 | 
					- 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.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -324,113 +324,3 @@ test("restore with cache found for restore key", async () => {
 | 
				
			|||||||
    );
 | 
					    );
 | 
				
			||||||
    expect(failedMock).toHaveBeenCalledTimes(0);
 | 
					    expect(failedMock).toHaveBeenCalledTimes(0);
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					 | 
				
			||||||
test("restore with enabling save on any failure feature", async () => {
 | 
					 | 
				
			||||||
    const path = "node_modules";
 | 
					 | 
				
			||||||
    const key = "node-test";
 | 
					 | 
				
			||||||
    const restoreKey = "node-";
 | 
					 | 
				
			||||||
    testUtils.setInputs({
 | 
					 | 
				
			||||||
        path: path,
 | 
					 | 
				
			||||||
        key,
 | 
					 | 
				
			||||||
        restoreKeys: [restoreKey],
 | 
					 | 
				
			||||||
        saveOnAnyFailure: true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const debugMock = jest.spyOn(core, "debug");
 | 
					 | 
				
			||||||
    const infoMock = jest.spyOn(core, "info");
 | 
					 | 
				
			||||||
    const failedMock = jest.spyOn(core, "setFailed");
 | 
					 | 
				
			||||||
    const stateMock = jest.spyOn(core, "saveState");
 | 
					 | 
				
			||||||
    const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
 | 
					 | 
				
			||||||
    const restoreCacheMock = jest
 | 
					 | 
				
			||||||
        .spyOn(cache, "restoreCache")
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return Promise.resolve(restoreKey);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await run();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
    expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
 | 
					 | 
				
			||||||
    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
    expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(debugMock).toHaveBeenCalledWith(
 | 
					 | 
				
			||||||
        `Exporting environment variable SAVE_CACHE_ON_ANY_FAILURE`
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(infoMock).toHaveBeenCalledWith(
 | 
					 | 
				
			||||||
        `Input Variable SAVE_CACHE_ON_ANY_FAILURE is set to true, the cache will be saved despite of any failure in the build.`
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    expect(failedMock).toHaveBeenCalledTimes(0);
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
test("Fail restore when fail on cache miss is enabled and primary key not found", async () => {
 | 
					 | 
				
			||||||
    const path = "node_modules";
 | 
					 | 
				
			||||||
    const key = "node-test";
 | 
					 | 
				
			||||||
    const restoreKey = "node-";
 | 
					 | 
				
			||||||
    testUtils.setInputs({
 | 
					 | 
				
			||||||
        path: path,
 | 
					 | 
				
			||||||
        key,
 | 
					 | 
				
			||||||
        restoreKeys: [restoreKey],
 | 
					 | 
				
			||||||
        failOnCacheMiss: true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const failedMock = jest.spyOn(core, "setFailed");
 | 
					 | 
				
			||||||
    const stateMock = jest.spyOn(core, "saveState");
 | 
					 | 
				
			||||||
    const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
 | 
					 | 
				
			||||||
    const restoreCacheMock = jest
 | 
					 | 
				
			||||||
        .spyOn(cache, "restoreCache")
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return Promise.resolve(undefined);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await run();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
    expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
 | 
					 | 
				
			||||||
    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(failedMock).toHaveBeenCalledWith(
 | 
					 | 
				
			||||||
        `Cache with the given input key ${key} is not found, hence exiting the workflow as the fail-on-cache-miss requirement is not met.`
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    expect(failedMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
test("Fail restore when fail on cache miss is enabled and primary key doesn't match restored key", async () => {
 | 
					 | 
				
			||||||
    const path = "node_modules";
 | 
					 | 
				
			||||||
    const key = "node-test";
 | 
					 | 
				
			||||||
    const restoreKey = "node-";
 | 
					 | 
				
			||||||
    testUtils.setInputs({
 | 
					 | 
				
			||||||
        path: path,
 | 
					 | 
				
			||||||
        key,
 | 
					 | 
				
			||||||
        restoreKeys: [restoreKey],
 | 
					 | 
				
			||||||
        failOnCacheMiss: true
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const failedMock = jest.spyOn(core, "setFailed");
 | 
					 | 
				
			||||||
    const stateMock = jest.spyOn(core, "saveState");
 | 
					 | 
				
			||||||
    const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
 | 
					 | 
				
			||||||
    const restoreCacheMock = jest
 | 
					 | 
				
			||||||
        .spyOn(cache, "restoreCache")
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return Promise.resolve(restoreKey);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await run();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
    expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
 | 
					 | 
				
			||||||
    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
    expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(failedMock).toHaveBeenCalledWith(
 | 
					 | 
				
			||||||
        `Restored cache key doesn't match the given input key ${key}, hence exiting the workflow as the fail-on-cache-miss requirement is not met.`
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    expect(failedMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,165 +0,0 @@
 | 
				
			|||||||
import * as cache from "@actions/cache";
 | 
					 | 
				
			||||||
import * as core from "@actions/core";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import { Events, Inputs, RefKey } from "../src/constants";
 | 
					 | 
				
			||||||
import run from "../src/save-only";
 | 
					 | 
				
			||||||
import * as actionUtils from "../src/utils/actionUtils";
 | 
					 | 
				
			||||||
import * as testUtils from "../src/utils/testUtils";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
jest.mock("@actions/core");
 | 
					 | 
				
			||||||
jest.mock("@actions/cache");
 | 
					 | 
				
			||||||
jest.mock("../src/utils/actionUtils");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
beforeAll(() => {
 | 
					 | 
				
			||||||
    jest.spyOn(core, "getInput").mockImplementation((name, options) => {
 | 
					 | 
				
			||||||
        return jest.requireActual("@actions/core").getInput(name, options);
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    jest.spyOn(actionUtils, "getCacheState").mockImplementation(() => {
 | 
					 | 
				
			||||||
        return jest.requireActual("../src/utils/actionUtils").getCacheState();
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
 | 
					 | 
				
			||||||
        (name, options) => {
 | 
					 | 
				
			||||||
            return jest
 | 
					 | 
				
			||||||
                .requireActual("../src/utils/actionUtils")
 | 
					 | 
				
			||||||
                .getInputAsArray(name, options);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    jest.spyOn(actionUtils, "getInputAsInt").mockImplementation(
 | 
					 | 
				
			||||||
        (name, options) => {
 | 
					 | 
				
			||||||
            return jest
 | 
					 | 
				
			||||||
                .requireActual("../src/utils/actionUtils")
 | 
					 | 
				
			||||||
                .getInputAsInt(name, options);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
 | 
					 | 
				
			||||||
        (key, cacheResult) => {
 | 
					 | 
				
			||||||
            return jest
 | 
					 | 
				
			||||||
                .requireActual("../src/utils/actionUtils")
 | 
					 | 
				
			||||||
                .isExactKeyMatch(key, cacheResult);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
 | 
					 | 
				
			||||||
        const actualUtils = jest.requireActual("../src/utils/actionUtils");
 | 
					 | 
				
			||||||
        return actualUtils.isValidEvent();
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
beforeEach(() => {
 | 
					 | 
				
			||||||
    process.env[Events.Key] = Events.Push;
 | 
					 | 
				
			||||||
    process.env[RefKey] = "refs/heads/feature-branch";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
 | 
					 | 
				
			||||||
    jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
 | 
					 | 
				
			||||||
        () => true
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
afterEach(() => {
 | 
					 | 
				
			||||||
    testUtils.clearInputs();
 | 
					 | 
				
			||||||
    delete process.env[Events.Key];
 | 
					 | 
				
			||||||
    delete process.env[RefKey];
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
test("save cache when save-only is required", async () => {
 | 
					 | 
				
			||||||
    const failedMock = jest.spyOn(core, "setFailed");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
 | 
					 | 
				
			||||||
    const savedCacheKey = "Linux-node-";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    jest.spyOn(core, "getInput")
 | 
					 | 
				
			||||||
        // Cache Entry State
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return savedCacheKey;
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
        // Cache Key
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return primaryKey;
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const inputPath = "node_modules";
 | 
					 | 
				
			||||||
    testUtils.setInput(Inputs.Path, inputPath);
 | 
					 | 
				
			||||||
    testUtils.setInput(Inputs.UploadChunkSize, "4000000");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const cacheId = 4;
 | 
					 | 
				
			||||||
    const saveCacheMock = jest
 | 
					 | 
				
			||||||
        .spyOn(cache, "saveCache")
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return Promise.resolve(cacheId);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await run();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(saveCacheMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
    expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, {
 | 
					 | 
				
			||||||
        uploadChunkSize: 4000000
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(failedMock).toHaveBeenCalledTimes(0);
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
test("save when save on any failure is true", async () => {
 | 
					 | 
				
			||||||
    const logWarningMock = jest.spyOn(actionUtils, "logWarning");
 | 
					 | 
				
			||||||
    const failedMock = jest.spyOn(core, "setFailed");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const savedCacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
 | 
					 | 
				
			||||||
    const primaryKey = "Linux-node-";
 | 
					 | 
				
			||||||
    const inputPath = "node_modules";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    jest.spyOn(core, "getInput")
 | 
					 | 
				
			||||||
        // Cache Entry State
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return savedCacheKey;
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
        // Cache Key
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return primaryKey;
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    testUtils.setInput(Inputs.Path, inputPath);
 | 
					 | 
				
			||||||
    testUtils.setInput(Inputs.UploadChunkSize, "4000000");
 | 
					 | 
				
			||||||
    testUtils.setInput(Inputs.SaveOnAnyFailure, "true");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const cacheId = 4;
 | 
					 | 
				
			||||||
    const saveCacheMock = jest
 | 
					 | 
				
			||||||
        .spyOn(cache, "saveCache")
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return Promise.resolve(cacheId);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await run();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(saveCacheMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
    expect(logWarningMock).toHaveBeenCalledTimes(0);
 | 
					 | 
				
			||||||
    expect(failedMock).toHaveBeenCalledTimes(0);
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
test("save with no primary key in input outputs warning", async () => {
 | 
					 | 
				
			||||||
    const logWarningMock = jest.spyOn(actionUtils, "logWarning");
 | 
					 | 
				
			||||||
    const failedMock = jest.spyOn(core, "setFailed");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const savedCacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
 | 
					 | 
				
			||||||
    jest.spyOn(core, "getState")
 | 
					 | 
				
			||||||
        // Cache Entry State
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return savedCacheKey;
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
        // Cache Key
 | 
					 | 
				
			||||||
        .mockImplementationOnce(() => {
 | 
					 | 
				
			||||||
            return "";
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    const saveCacheMock = jest.spyOn(cache, "saveCache");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await run();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(saveCacheMock).toHaveBeenCalledTimes(0);
 | 
					 | 
				
			||||||
    expect(logWarningMock).toHaveBeenCalledWith(
 | 
					 | 
				
			||||||
        `Error retrieving key from inputs.`
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    expect(logWarningMock).toHaveBeenCalledTimes(1);
 | 
					 | 
				
			||||||
    expect(failedMock).toHaveBeenCalledTimes(0);
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
							
								
								
									
										10
									
								
								action.yml
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								action.yml
									
									
									
									
									
								
							@@ -14,14 +14,6 @@ inputs:
 | 
				
			|||||||
  upload-chunk-size:
 | 
					  upload-chunk-size:
 | 
				
			||||||
    description: 'The chunk size used to split up large files during upload, in bytes'
 | 
					    description: 'The chunk size used to split up large files during upload, in bytes'
 | 
				
			||||||
    required: false
 | 
					    required: false
 | 
				
			||||||
  exit-on-cache-miss:
 | 
					 | 
				
			||||||
    description: 'Fail the workflow if the cache is not found for the primary key'
 | 
					 | 
				
			||||||
    required: false
 | 
					 | 
				
			||||||
    default: false
 | 
					 | 
				
			||||||
  save-on-any-failure:
 | 
					 | 
				
			||||||
    description: 'Save cache (on cache miss) despite of any failure during the workflow run'
 | 
					 | 
				
			||||||
    required: false
 | 
					 | 
				
			||||||
    default: false
 | 
					 | 
				
			||||||
outputs:
 | 
					outputs:
 | 
				
			||||||
  cache-hit:
 | 
					  cache-hit:
 | 
				
			||||||
    description: 'A boolean value to indicate an exact match was found for the primary key'
 | 
					    description: 'A boolean value to indicate an exact match was found for the primary key'
 | 
				
			||||||
@@ -29,7 +21,7 @@ runs:
 | 
				
			|||||||
  using: 'node16'
 | 
					  using: 'node16'
 | 
				
			||||||
  main: 'dist/restore/index.js'
 | 
					  main: 'dist/restore/index.js'
 | 
				
			||||||
  post: 'dist/save/index.js'
 | 
					  post: 'dist/save/index.js'
 | 
				
			||||||
  post-if: (success() || (env.SAVE_CACHE_ON_ANY_FAILURE == 'yes'))
 | 
					  post-if: 'success()'
 | 
				
			||||||
branding:
 | 
					branding:
 | 
				
			||||||
  icon: 'archive'
 | 
					  icon: 'archive'
 | 
				
			||||||
  color: 'gray-dark'
 | 
					  color: 'gray-dark'
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										727
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										727
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										61367
									
								
								dist/save-only/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										61367
									
								
								dist/save-only/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										781
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										781
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										21
									
								
								examples.md
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								examples.md
									
									
									
									
									
								
							@@ -309,14 +309,29 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
 | 
				
			|||||||
For npm, cache files are stored in `~/.npm` on Posix, or `~\AppData\npm-cache` on Windows, but it's possible to use `npm config get cache` to find the path on any platform. See [the npm docs](https://docs.npmjs.com/cli/cache#cache) for more details.
 | 
					For npm, cache files are stored in `~/.npm` on Posix, or `~\AppData\npm-cache` on Windows, but it's possible to use `npm config get cache` to find the path on any platform. See [the npm docs](https://docs.npmjs.com/cli/cache#cache) for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
If using `npm config` to retrieve the cache directory, ensure you run [actions/setup-node](https://github.com/actions/setup-node) first to ensure your `npm` version is correct.
 | 
					If using `npm config` to retrieve the cache directory, ensure you run [actions/setup-node](https://github.com/actions/setup-node) first to ensure your `npm` version is correct.
 | 
				
			||||||
 | 
					After [deprecation](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/) of save-state and set-output commands, the correct way to set output is using `${GITHUB_OUTPUT}`. For linux, we can use `${GITHUB_OUTPUT}` whereas for windows we need to use `${env:GITHUB_OUTPUT}` due to two different default shells in these two different OS ie `bash` and `pwsh` respectively.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
>Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci`
 | 
					>Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### **Get npm cache directory using same shell**
 | 
				
			||||||
 | 
					### Bash shell
 | 
				
			||||||
```yaml
 | 
					```yaml
 | 
				
			||||||
- name: Get npm cache directory
 | 
					- name: Get npm cache directory
 | 
				
			||||||
  id: npm-cache-dir
 | 
					  id: npm-cache
 | 
				
			||||||
  run: |
 | 
					  shell: bash
 | 
				
			||||||
    echo "::set-output name=dir::$(npm config get cache)"
 | 
					  run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### PWSH shell
 | 
				
			||||||
 | 
					```yaml
 | 
				
			||||||
 | 
					- name: Get npm cache directory
 | 
				
			||||||
 | 
					  id: npm-cache
 | 
				
			||||||
 | 
					  shell: pwsh
 | 
				
			||||||
 | 
					  run: echo "dir=$(npm config get cache)" >> ${env:GITHUB_OUTPUT}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					`Get npm cache directory` step can then be used with `actions/cache` as shown below
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```yaml
 | 
				
			||||||
- uses: actions/cache@v3
 | 
					- uses: actions/cache@v3
 | 
				
			||||||
  id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
 | 
					  id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
 | 
				
			||||||
  with:
 | 
					  with:
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6519
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6519
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										30
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								package.json
									
									
									
									
									
								
							@@ -1,11 +1,11 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "cache",
 | 
					  "name": "cache",
 | 
				
			||||||
  "version": "3.0.11",
 | 
					  "version": "3.1.0-beta.2",
 | 
				
			||||||
  "private": true,
 | 
					  "private": true,
 | 
				
			||||||
  "description": "Cache dependencies and build outputs",
 | 
					  "description": "Cache dependencies and build outputs",
 | 
				
			||||||
  "main": "dist/restore/index.js",
 | 
					  "main": "dist/restore/index.js",
 | 
				
			||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
    "build": "tsc && ncc build -o dist/restore src/restore.ts && ncc build -o dist/save src/save.ts && ncc build -o dist/save-only src/save-only.ts",
 | 
					    "build": "tsc && ncc build -o dist/restore src/restore.ts && ncc build -o dist/save src/save.ts",
 | 
				
			||||||
    "test": "tsc --noEmit && jest --coverage",
 | 
					    "test": "tsc --noEmit && jest --coverage",
 | 
				
			||||||
    "lint": "eslint **/*.ts --cache",
 | 
					    "lint": "eslint **/*.ts --cache",
 | 
				
			||||||
    "format": "prettier --write **/*.ts",
 | 
					    "format": "prettier --write **/*.ts",
 | 
				
			||||||
@@ -23,29 +23,29 @@
 | 
				
			|||||||
  "author": "GitHub",
 | 
					  "author": "GitHub",
 | 
				
			||||||
  "license": "MIT",
 | 
					  "license": "MIT",
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "@actions/cache": "^3.0.5",
 | 
					    "@actions/cache": "3.1.0-beta.2",
 | 
				
			||||||
    "@actions/core": "^1.10.0",
 | 
					    "@actions/core": "^1.10.0",
 | 
				
			||||||
    "@actions/exec": "^1.1.1",
 | 
					    "@actions/exec": "^1.1.1",
 | 
				
			||||||
    "@actions/io": "^1.1.2"
 | 
					    "@actions/io": "^1.1.2"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@types/jest": "^27.5.0",
 | 
					    "@types/jest": "^27.5.2",
 | 
				
			||||||
    "@types/nock": "^11.1.0",
 | 
					    "@types/nock": "^11.1.0",
 | 
				
			||||||
    "@types/node": "^16.11.33",
 | 
					    "@types/node": "^16.18.3",
 | 
				
			||||||
    "@typescript-eslint/eslint-plugin": "^5.22.0",
 | 
					    "@typescript-eslint/eslint-plugin": "^5.45.0",
 | 
				
			||||||
    "@typescript-eslint/parser": "^5.22.0",
 | 
					    "@typescript-eslint/parser": "^5.45.0",
 | 
				
			||||||
    "@zeit/ncc": "^0.20.5",
 | 
					    "@zeit/ncc": "^0.20.5",
 | 
				
			||||||
    "eslint": "^8.14.0",
 | 
					    "eslint": "^8.28.0",
 | 
				
			||||||
    "eslint-config-prettier": "^8.5.0",
 | 
					    "eslint-config-prettier": "^8.5.0",
 | 
				
			||||||
    "eslint-plugin-import": "^2.26.0",
 | 
					    "eslint-plugin-import": "^2.26.0",
 | 
				
			||||||
    "eslint-plugin-jest": "^26.1.5",
 | 
					    "eslint-plugin-jest": "^26.9.0",
 | 
				
			||||||
    "eslint-plugin-prettier": "^4.0.0",
 | 
					    "eslint-plugin-prettier": "^4.2.1",
 | 
				
			||||||
    "eslint-plugin-simple-import-sort": "^7.0.0",
 | 
					    "eslint-plugin-simple-import-sort": "^7.0.0",
 | 
				
			||||||
    "jest": "^28.0.3",
 | 
					    "jest": "^28.1.3",
 | 
				
			||||||
    "jest-circus": "^27.5.1",
 | 
					    "jest-circus": "^27.5.1",
 | 
				
			||||||
    "nock": "^13.2.4",
 | 
					    "nock": "^13.2.9",
 | 
				
			||||||
    "prettier": "^2.6.2",
 | 
					    "prettier": "^2.8.0",
 | 
				
			||||||
    "ts-jest": "^28.0.2",
 | 
					    "ts-jest": "^28.0.8",
 | 
				
			||||||
    "typescript": "^4.6.4"
 | 
					    "typescript": "^4.9.3"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,27 +0,0 @@
 | 
				
			|||||||
name: 'Restore Cache'
 | 
					 | 
				
			||||||
description: 'Restore Cache artifacts like dependencies and build outputs to improve workflow execution time'
 | 
					 | 
				
			||||||
author: 'GitHub'
 | 
					 | 
				
			||||||
inputs:
 | 
					 | 
				
			||||||
  path:
 | 
					 | 
				
			||||||
    description: 'A list of files, directories, and wildcard patterns to cache and restore'
 | 
					 | 
				
			||||||
    required: true
 | 
					 | 
				
			||||||
  key:
 | 
					 | 
				
			||||||
    description: 'An explicit key for restoring and saving the cache'
 | 
					 | 
				
			||||||
    required: true
 | 
					 | 
				
			||||||
  restore-keys:
 | 
					 | 
				
			||||||
    description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.'
 | 
					 | 
				
			||||||
    required: false
 | 
					 | 
				
			||||||
  exit-on-cache-miss:
 | 
					 | 
				
			||||||
    description: 'Fail the workflow if the cache is not found for the primary key'
 | 
					 | 
				
			||||||
    required: false
 | 
					 | 
				
			||||||
    default: false
 | 
					 | 
				
			||||||
outputs:
 | 
					 | 
				
			||||||
  cache-hit:
 | 
					 | 
				
			||||||
    description: 'A boolean value to indicate an exact match was found for the primary key'
 | 
					 | 
				
			||||||
runs:
 | 
					 | 
				
			||||||
  using: 'node16'
 | 
					 | 
				
			||||||
  main: '../dist/restore/index.js'
 | 
					 | 
				
			||||||
branding:
 | 
					 | 
				
			||||||
  icon: 'archive'
 | 
					 | 
				
			||||||
  color: 'gray-dark'
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
@@ -1,19 +0,0 @@
 | 
				
			|||||||
name: 'Save Cache'
 | 
					 | 
				
			||||||
description: 'Save Cache artifacts like dependencies and build outputs to improve workflow execution time'
 | 
					 | 
				
			||||||
author: 'GitHub'
 | 
					 | 
				
			||||||
inputs:
 | 
					 | 
				
			||||||
  path:
 | 
					 | 
				
			||||||
    description: 'A list of files, directories, and wildcard patterns to cache and restore'
 | 
					 | 
				
			||||||
    required: true
 | 
					 | 
				
			||||||
  key:
 | 
					 | 
				
			||||||
    description: 'An explicit key for restoring and saving the cache'
 | 
					 | 
				
			||||||
    required: true
 | 
					 | 
				
			||||||
  upload-chunk-size:
 | 
					 | 
				
			||||||
    description: 'The chunk size used to split up large files during upload, in bytes'
 | 
					 | 
				
			||||||
    required: false
 | 
					 | 
				
			||||||
runs:
 | 
					 | 
				
			||||||
  using: 'node16'
 | 
					 | 
				
			||||||
  main: '../dist/save/index.js'
 | 
					 | 
				
			||||||
branding:
 | 
					 | 
				
			||||||
  icon: 'archive'
 | 
					 | 
				
			||||||
  color: 'gray-dark'
 | 
					 | 
				
			||||||
@@ -2,9 +2,7 @@ export enum Inputs {
 | 
				
			|||||||
    Key = "key",
 | 
					    Key = "key",
 | 
				
			||||||
    Path = "path",
 | 
					    Path = "path",
 | 
				
			||||||
    RestoreKeys = "restore-keys",
 | 
					    RestoreKeys = "restore-keys",
 | 
				
			||||||
    UploadChunkSize = "upload-chunk-size",
 | 
					    UploadChunkSize = "upload-chunk-size"
 | 
				
			||||||
    FailOnCacheMiss = "fail-on-cache-miss",
 | 
					 | 
				
			||||||
    SaveOnAnyFailure = "save-on-any-failure"
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export enum Outputs {
 | 
					export enum Outputs {
 | 
				
			||||||
@@ -22,8 +20,4 @@ export enum Events {
 | 
				
			|||||||
    PullRequest = "pull_request"
 | 
					    PullRequest = "pull_request"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export enum Variables {
 | 
					 | 
				
			||||||
    SaveCacheOnAnyFailure = "SAVE_CACHE_ON_ANY_FAILURE"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export const RefKey = "GITHUB_REF";
 | 
					export const RefKey = "GITHUB_REF";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
import * as cache from "@actions/cache";
 | 
					import * as cache from "@actions/cache";
 | 
				
			||||||
import * as core from "@actions/core";
 | 
					import * as core from "@actions/core";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Events, Inputs, State, Variables } from "./constants";
 | 
					import { Events, Inputs, State } from "./constants";
 | 
				
			||||||
import * as utils from "./utils/actionUtils";
 | 
					import * as utils from "./utils/actionUtils";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function run(): Promise<void> {
 | 
					async function run(): Promise<void> {
 | 
				
			||||||
@@ -35,46 +35,22 @@ async function run(): Promise<void> {
 | 
				
			|||||||
            restoreKeys
 | 
					            restoreKeys
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Check if user wants to save cache despite of failure in any previous job
 | 
					 | 
				
			||||||
        const saveCache = core.getBooleanInput(Inputs.SaveOnAnyFailure);
 | 
					 | 
				
			||||||
        if (saveCache == true) {
 | 
					 | 
				
			||||||
            core.debug(
 | 
					 | 
				
			||||||
                `Exporting environment variable ${Variables.SaveCacheOnAnyFailure}`
 | 
					 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
            core.exportVariable(Variables.SaveCacheOnAnyFailure, saveCache);
 | 
					 | 
				
			||||||
            core.info(
 | 
					 | 
				
			||||||
                `Input Variable ${Variables.SaveCacheOnAnyFailure} is set to true, the cache will be saved despite of any failure in the build.`
 | 
					 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!cacheKey) {
 | 
					        if (!cacheKey) {
 | 
				
			||||||
            if (core.getBooleanInput(Inputs.FailOnCacheMiss) == true) {
 | 
					 | 
				
			||||||
                throw new Error(
 | 
					 | 
				
			||||||
                    `Cache with the given input key ${primaryKey} is not found, hence exiting the workflow as the fail-on-cache-miss requirement is not met.`
 | 
					 | 
				
			||||||
                );
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            core.info(
 | 
					            core.info(
 | 
				
			||||||
                `Cache not found for input keys: ${[
 | 
					                `Cache not found for input keys: ${[
 | 
				
			||||||
                    primaryKey,
 | 
					                    primaryKey,
 | 
				
			||||||
                    ...restoreKeys
 | 
					                    ...restoreKeys
 | 
				
			||||||
                ].join(", ")}`
 | 
					                ].join(", ")}`
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Store the matched cache key
 | 
					        // Store the matched cache key
 | 
				
			||||||
        utils.setCacheState(cacheKey);
 | 
					        utils.setCacheState(cacheKey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
 | 
					        const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
 | 
				
			||||||
        utils.setCacheHitOutput(isExactKeyMatch);
 | 
					        utils.setCacheHitOutput(isExactKeyMatch);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (
 | 
					 | 
				
			||||||
            !isExactKeyMatch &&
 | 
					 | 
				
			||||||
            core.getBooleanInput(Inputs.FailOnCacheMiss) == true
 | 
					 | 
				
			||||||
        ) {
 | 
					 | 
				
			||||||
            throw new Error(
 | 
					 | 
				
			||||||
                `Restored cache key doesn't match the given input key ${primaryKey}, hence exiting the workflow as the fail-on-cache-miss requirement is not met.`
 | 
					 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        core.info(`Cache restored from key: ${cacheKey}`);
 | 
					        core.info(`Cache restored from key: ${cacheKey}`);
 | 
				
			||||||
    } catch (error: unknown) {
 | 
					    } catch (error: unknown) {
 | 
				
			||||||
        core.setFailed((error as Error).message);
 | 
					        core.setFailed((error as Error).message);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,20 +0,0 @@
 | 
				
			|||||||
import * as core from "@actions/core";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import { Inputs } from "./constants";
 | 
					 | 
				
			||||||
import save from "./save";
 | 
					 | 
				
			||||||
import * as utils from "./utils/actionUtils";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
async function runSaveAction(): Promise<void> {
 | 
					 | 
				
			||||||
    if (!core.getInput(Inputs.Key)) {
 | 
					 | 
				
			||||||
        utils.logWarning(`Error retrieving key from inputs.`);
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    saveOnly = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await save();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
runSaveAction();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export default runSaveAction;
 | 
					 | 
				
			||||||
export let saveOnly: boolean;
 | 
					 | 
				
			||||||
@@ -2,7 +2,6 @@ import * as cache from "@actions/cache";
 | 
				
			|||||||
import * as core from "@actions/core";
 | 
					import * as core from "@actions/core";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Events, Inputs, State } from "./constants";
 | 
					import { Events, Inputs, State } from "./constants";
 | 
				
			||||||
import { saveOnly } from "./save-only";
 | 
					 | 
				
			||||||
import * as utils from "./utils/actionUtils";
 | 
					import * as utils from "./utils/actionUtils";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Catch and log any unhandled exceptions.  These exceptions can leak out of the uploadChunk method in
 | 
					// Catch and log any unhandled exceptions.  These exceptions can leak out of the uploadChunk method in
 | 
				
			||||||
@@ -28,11 +27,7 @@ async function run(): Promise<void> {
 | 
				
			|||||||
        const state = utils.getCacheState();
 | 
					        const state = utils.getCacheState();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Inputs are re-evaluted before the post action, so we want the original key used for restore
 | 
					        // Inputs are re-evaluted before the post action, so we want the original key used for restore
 | 
				
			||||||
        const primaryKey =
 | 
					        const primaryKey = core.getState(State.CachePrimaryKey);
 | 
				
			||||||
            saveOnly === true
 | 
					 | 
				
			||||||
                ? core.getInput(Inputs.Key)
 | 
					 | 
				
			||||||
                : core.getState(State.CachePrimaryKey);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!primaryKey) {
 | 
					        if (!primaryKey) {
 | 
				
			||||||
            utils.logWarning(`Error retrieving key from state.`);
 | 
					            utils.logWarning(`Error retrieving key from state.`);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@@ -61,4 +56,6 @@ async function run(): Promise<void> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default run;
 | 
					export default run;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,19 +77,20 @@ export function getInputAsInt(
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function isCacheFeatureAvailable(): boolean {
 | 
					export function isCacheFeatureAvailable(): boolean {
 | 
				
			||||||
    if (!cache.isFeatureAvailable()) {
 | 
					    if (cache.isFeatureAvailable()) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (isGhes()) {
 | 
					    if (isGhes()) {
 | 
				
			||||||
        logWarning(
 | 
					        logWarning(
 | 
				
			||||||
            `Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.
 | 
					            `Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.
 | 
				
			||||||
Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/enterprise-server@3.5/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)`
 | 
					Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/enterprise-server@3.5/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)`
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            logWarning(
 | 
					 | 
				
			||||||
                "An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."
 | 
					 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return true;
 | 
					    logWarning(
 | 
				
			||||||
 | 
					        "An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,28 +13,18 @@ interface CacheInput {
 | 
				
			|||||||
    path: string;
 | 
					    path: string;
 | 
				
			||||||
    key: string;
 | 
					    key: string;
 | 
				
			||||||
    restoreKeys?: string[];
 | 
					    restoreKeys?: string[];
 | 
				
			||||||
    failOnCacheMiss?: boolean;
 | 
					 | 
				
			||||||
    saveOnAnyFailure?: boolean;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function setInputs(input: CacheInput): void {
 | 
					export function setInputs(input: CacheInput): void {
 | 
				
			||||||
    setInput(Inputs.Path, input.path);
 | 
					    setInput(Inputs.Path, input.path);
 | 
				
			||||||
    setInput(Inputs.Key, input.key);
 | 
					    setInput(Inputs.Key, input.key);
 | 
				
			||||||
    setInput(Inputs.SaveOnAnyFailure, "false");
 | 
					 | 
				
			||||||
    setInput(Inputs.FailOnCacheMiss, "false");
 | 
					 | 
				
			||||||
    input.restoreKeys &&
 | 
					    input.restoreKeys &&
 | 
				
			||||||
        setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
 | 
					        setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
 | 
				
			||||||
    input.failOnCacheMiss &&
 | 
					 | 
				
			||||||
        setInput(Inputs.FailOnCacheMiss, String(input.failOnCacheMiss));
 | 
					 | 
				
			||||||
    input.saveOnAnyFailure &&
 | 
					 | 
				
			||||||
        setInput(Inputs.SaveOnAnyFailure, String(input.saveOnAnyFailure));
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function clearInputs(): void {
 | 
					export function clearInputs(): void {
 | 
				
			||||||
    delete process.env[getInputName(Inputs.Path)];
 | 
					    delete process.env[getInputName(Inputs.Path)];
 | 
				
			||||||
    delete process.env[getInputName(Inputs.Key)];
 | 
					    delete process.env[getInputName(Inputs.Key)];
 | 
				
			||||||
    delete process.env[getInputName(Inputs.RestoreKeys)];
 | 
					    delete process.env[getInputName(Inputs.RestoreKeys)];
 | 
				
			||||||
    delete process.env[getInputName(Inputs.FailOnCacheMiss)];
 | 
					 | 
				
			||||||
    delete process.env[getInputName(Inputs.SaveOnAnyFailure)];
 | 
					 | 
				
			||||||
    delete process.env[getInputName(Inputs.UploadChunkSize)];
 | 
					    delete process.env[getInputName(Inputs.UploadChunkSize)];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user