Skip to content
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

Adding support in cache package to check if Artifact Cache service is enabled or not #1028

Merged
merged 28 commits into from Mar 25, 2022

Conversation

tiwarishub
Copy link
Contributor

@tiwarishub tiwarishub commented Mar 22, 2022

This PR introduced a function that can be used to check the presence of Artifact Cache service using the presence of ACTION_CACHE_URL env var. This var we only set in runner if Artifact Cache is present.

These are changes required on the package consumer side: actions/cache#774

We have tested it for GHES, where AC is only available in version >= 3.5

In 3.4 where AC is not present
image

In GHES, where AC is present
image

Linked: https://github.com/github/c2c-actions/issues/4065

@tiwarishub tiwarishub marked this pull request as ready for review March 23, 2022 04:47
@tiwarishub tiwarishub requested a review from a team as a code owner March 23, 2022 04:47
@aparna-ravindra
Copy link
Contributor

LGTM

@tiwarishub tiwarishub requested a review from vsvipul March 24, 2022 11:29
*/

export function isFeatureAvailable(): boolean {
return utils.isFeatureAvailable()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it useful to put the function in utils instead of just inlining it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the toolkit repo, the unit test cases for the cache.ts file are not in a single file and they are distributed as per functionality like saveCachetest.ts and restoreCachetest.ts. And I also wanted to add a unit test for this function and so the only place I thought where it suits most was utils. Let me know if it make sense

Copy link
Contributor

@brcrista brcrista Mar 24, 2022

Choose a reason for hiding this comment

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

Personally I would opt for keeping the app code simple and pushing complexity into the test code, but it's not a big deal.

You can also simplify the current code like

export const isFeatureAvailable = utils.isFeatureAvailable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it makes sense to keep the app code simple and move complexity to test code. Inlined the function and moved to test cases to the new file.

// Ideally we just use ACTIONS_CACHE_URL
const baseUrl: string = (
process.env['ACTIONS_CACHE_URL'] ||
process.env['ACTIONS_RUNTIME_URL'] ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Breaking change here. If we're going to remove this, we need to bump the package version to 2.0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aiqiaoy for 👀

Copy link
Contributor

Choose a reason for hiding this comment

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

Regardless of what we do in the runner, it technically is still a breaking change and we should update the major version accordingly. It's not a big deal. Alternatively, we can just keep the check for ACTIONS_RUNTIME_URL.

Copy link
Contributor

Choose a reason for hiding this comment

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

While technically yes it is a breaking change, pretty sure it is not so in practical terms. In hosted Actions, ACTIONS_CACHE_URL is set and no-one would be using the fallback. In GHES, caching was not available and hence need not worry about older server/runner versions.
Hence we should be okay to do without extra work of a major version change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated for major release to be safer side

tiwarishub and others added 4 commits March 24, 2022 17:17
Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
process.env['ACTIONS_RUNTIME_URL'] ||
''
).replace('pipelines', 'artifactcache')
const baseUrl: string = process.env['ACTIONS_CACHE_URL'] || ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need || ''?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually we don't need it but this safeguard was there from beginning so i didn't remove it

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.

None yet

5 participants