Skip to content

Commit

Permalink
fix(cache): Not throw err if no cache folders
Browse files Browse the repository at this point in the history
  • Loading branch information
e-korolevskii committed Sep 8, 2022
1 parent be45b27 commit 5547b9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
22 changes: 8 additions & 14 deletions __tests__/setup-go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ describe('setup-go', () => {
logSpy = jest.spyOn(core, 'info');
dbgSpy = jest.spyOn(core, 'debug');
getSpy.mockImplementation(() => <im.IGoVersion[] | null>goJsonData);
cnSpy.mockImplementation(line => {
cnSpy.mockImplementation((line) => {
// uncomment to debug
// process.stderr.write('write:' + line + '\n');
});
logSpy.mockImplementation(line => {
logSpy.mockImplementation((line) => {
// uncomment to debug
//process.stderr.write('log:' + line + '\n');
});
dbgSpy.mockImplementation(msg => {
dbgSpy.mockImplementation((line) => {
// uncomment to see debug output
// process.stderr.write(msg + '\n');
});
Expand Down Expand Up @@ -295,7 +295,6 @@ describe('setup-go', () => {
findSpy.mockImplementation(() => toolPath);
await main.run();

let expPath = path.join(toolPath, 'bin');
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
});

Expand Down Expand Up @@ -462,9 +461,6 @@ describe('setup-go', () => {
inputs['go-version'] = versionSpec;
inputs['token'] = 'faketoken';

let expectedUrl =
'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-linux-x64.tar.gz';

// ... but not in the local cache
findSpy.mockImplementation(() => '');

Expand Down Expand Up @@ -526,7 +522,7 @@ describe('setup-go', () => {
});

mkdirpSpy.mockImplementation(async () => {});
existsSpy.mockImplementation(path => {
existsSpy.mockImplementation(() => {
return false;
});

Expand Down Expand Up @@ -707,8 +703,6 @@ describe('setup-go', () => {
const toolPath = path.normalize('/cache/go/1.17.5/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
const expectedUrl =
'https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz';

await main.run();

Expand Down Expand Up @@ -834,7 +828,7 @@ exclude example.com/thismodule v1.3.0

it('reads version from go.mod', async () => {
inputs['go-version-file'] = 'go.mod';
existsSpy.mockImplementation(path => true);
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() => Buffer.from(goModContents));

await main.run();
Expand All @@ -846,7 +840,7 @@ exclude example.com/thismodule v1.3.0

it('reads version from .go-version', async () => {
inputs['go-version-file'] = '.go-version';
existsSpy.mockImplementation(path => true);
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`));

await main.run();
Expand All @@ -859,7 +853,7 @@ exclude example.com/thismodule v1.3.0
it('is overwritten by go-version', async () => {
inputs['go-version'] = '1.13.1';
inputs['go-version-file'] = 'go.mod';
existsSpy.mockImplementation(path => true);
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() => Buffer.from(goModContents));

await main.run();
Expand All @@ -871,7 +865,7 @@ exclude example.com/thismodule v1.3.0

it('reports a read failure', async () => {
inputs['go-version-file'] = 'go.mod';
existsSpy.mockImplementation(path => false);
existsSpy.mockImplementation(() => false);

await main.run();

Expand Down
13 changes: 9 additions & 4 deletions src/cache-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ export async function run() {
try {
await cachePackages();
} catch (error) {
core.setFailed(error.message);
let message = 'Unknown error!';
if (error instanceof Error) {
message = error.message;
}
if (typeof error === 'string') {
message = error;
}
core.setFailed(message);
}
}

Expand All @@ -41,9 +48,7 @@ const cachePackages = async () => {

if (nonExistingPaths.length === cachePaths.length) {
core.warning(`There are no cache folders on the disk`);
logWarning(`There are no cache folders on the disk`)
return;
throw new Error(`There are no cache folders on the disk`);
}

if (nonExistingPaths.length) {
Expand All @@ -68,7 +73,7 @@ const cachePackages = async () => {
core.info(`Cache saved with the key: ${primaryKey}`);
};

export function logWarning(message: string): void {
function logWarning(message: string): void {
const warningPrefix = '[warning]';
core.info(`${warningPrefix}${message}`);
}
Expand Down

0 comments on commit 5547b9e

Please sign in to comment.