-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caching on GHES #452
Caching on GHES #452
Changes from 2 commits
7af0f4d
1c630f9
62e9de9
8a5e1b5
fea0c2a
ebee360
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ describe('run', () => { | |
let getStateSpy: jest.SpyInstance; | ||
let saveCacheSpy: jest.SpyInstance; | ||
let getCommandOutputSpy: jest.SpyInstance; | ||
let isCacheActionAvailable: jest.SpyInstance; | ||
let hashFilesSpy: jest.SpyInstance; | ||
let existsSpy: jest.SpyInstance; | ||
|
||
|
@@ -70,6 +71,9 @@ describe('run', () => { | |
|
||
// utils | ||
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput'); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above comment. Is this change required here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thank you. |
||
isCacheActionAvailable = jest.spyOn(utils, 'isCacheFeatureAvailable'); | ||
isCacheActionAvailable.mockImplementation(() => true); | ||
}); | ||
|
||
afterEach(() => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,26 @@ | ||
import * as core from '@actions/core'; | ||
import * as cache from '@actions/cache'; | ||
import path from 'path'; | ||
import * as utils from '../src/cache-utils'; | ||
import {PackageManagerInfo} from '../src/cache-utils'; | ||
import {PackageManagerInfo, isCacheFeatureAvailable} from '../src/cache-utils'; | ||
|
||
describe('cache-utils', () => { | ||
const commonPath = '/some/random/path'; | ||
const versionYarn1 = '1.2.3'; | ||
const versionYarn2 = '2.3.4'; | ||
|
||
let debugSpy: jest.SpyInstance; | ||
let getCommandOutputSpy: jest.SpyInstance; | ||
|
||
function getPackagePath(name: string) { | ||
if (name === utils.supportedPackageManagers.npm.getCacheFolderCommand) { | ||
return `${commonPath}/npm`; | ||
} else if ( | ||
name === utils.supportedPackageManagers.pnpm.getCacheFolderCommand | ||
) { | ||
return `${commonPath}/pnpm`; | ||
} else { | ||
if (name === utils.supportedPackageManagers.yarn1.getCacheFolderCommand) { | ||
return `${commonPath}/yarn1`; | ||
} else { | ||
return `${commonPath}/yarn2`; | ||
} | ||
} | ||
} | ||
let isFeatureAvailable: jest.SpyInstance; | ||
let info: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); | ||
debugSpy = jest.spyOn(core, 'debug'); | ||
debugSpy.mockImplementation(msg => {}); | ||
|
||
info = jest.spyOn(core, 'info'); | ||
|
||
isFeatureAvailable = jest.spyOn(cache, 'isFeatureAvailable'); | ||
|
||
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput'); | ||
}); | ||
|
||
|
@@ -51,7 +40,35 @@ describe('cache-utils', () => { | |
}); | ||
}); | ||
|
||
it('isCacheFeatureAvailable is false', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the description, Please add whether the scenario is of GHES or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thank you. |
||
isFeatureAvailable.mockImplementation(() => false); | ||
process.env['GITHUB_SERVER_URL'] = 'https://www.test.com'; | ||
|
||
expect(isCacheFeatureAvailable()).toBe(false); | ||
expect(info).toHaveBeenCalledWith( | ||
'[warning]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.' | ||
); | ||
}); | ||
|
||
it('isCacheFeatureAvailable is false', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thank you. |
||
isFeatureAvailable.mockImplementation(() => false); | ||
process.env['GITHUB_SERVER_URL'] = ''; | ||
|
||
expect(isCacheFeatureAvailable()).toBe(false); | ||
expect(info).toHaveBeenCalledWith( | ||
'[warning]An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.' | ||
); | ||
}); | ||
|
||
it('isCacheFeatureAvailable is true', () => { | ||
isFeatureAvailable.mockImplementation(() => true); | ||
|
||
expect(isCacheFeatureAvailable()).toBe(true); | ||
expect(info).not.toHaveBeenCalled(); | ||
}); | ||
|
||
afterEach(() => { | ||
process.env['GITHUB_SERVER_URL'] = ''; | ||
jest.resetAllMocks(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change and L53 change is required? Because I think in restore restoreCache function we don't check
isCacheActionAvailable
functions. This we are checking in main.tsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you.