Skip to content

Commit

Permalink
Adding support in cache package to check if Artifact Cache service is…
Browse files Browse the repository at this point in the history
… enabled or not (#1028)

* Added support to check if Artifact cache service is enabled or not.

* enablingForGHES

* added ACTIONS_CACHE_URL in fixtures

* Fix CI

* CI fix

* changed function name

* Function rename

* Updated release

* added test case

* Update RELEASES.md

* Lint errors

* lint

* linting

* lint

* update name to actions service

* Update packages/cache/src/internal/cacheUtils.ts

Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>

* review comments

* linting

* linting

* push to start CI

* Update RELEASES.md

* remove extra spaces

* reverting version update

* Revert "reverting version update"

This reverts commit af84eba.

* Update RELEASES.md

Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
  • Loading branch information
tiwarishub and brcrista committed Mar 25, 2022
1 parent 39b9640 commit b463992
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
3 changes: 3 additions & 0 deletions packages/cache/RELEASES.md
Expand Up @@ -53,3 +53,6 @@

### 1.0.11
- Fix file downloads > 2GB([issue](https://github.com/actions/cache/issues/773))

### 2.0.0
- Added support to check if Actions cache service feature is available or not [#1028](https://github.com/actions/toolkit/pull/1028)
4 changes: 2 additions & 2 deletions packages/cache/__tests__/__fixtures__/index.js
Expand Up @@ -3,10 +3,10 @@
const fs = require('fs');
const os = require('os');
const filePath = process.env[`GITHUB_ENV`]
fs.appendFileSync(filePath, `ACTIONS_RUNTIME_URL=${process.env.ACTIONS_RUNTIME_URL}${os.EOL}`, {
fs.appendFileSync(filePath, `ACTIONS_RUNTIME_TOKEN=${process.env.ACTIONS_RUNTIME_TOKEN}${os.EOL}`, {
encoding: 'utf8'
})
fs.appendFileSync(filePath, `ACTIONS_RUNTIME_TOKEN=${process.env.ACTIONS_RUNTIME_TOKEN}${os.EOL}`, {
fs.appendFileSync(filePath, `ACTIONS_CACHE_URL=${process.env.ACTIONS_CACHE_URL}${os.EOL}`, {
encoding: 'utf8'
})
fs.appendFileSync(filePath, `GITHUB_RUN_ID=${process.env.GITHUB_RUN_ID}${os.EOL}`, {
Expand Down
14 changes: 14 additions & 0 deletions packages/cache/__tests__/cache.test.ts
@@ -0,0 +1,14 @@
import * as cache from '../src/cache'

test('isFeatureAvailable returns true if server url is set', () => {
try {
process.env['ACTIONS_CACHE_URL'] = 'http://cache.com'
expect(cache.isFeatureAvailable()).toBe(true)
} finally {
delete process.env['ACTIONS_CACHE_URL']
}
})

test('isFeatureAvailable returns false if server url is not set', () => {
expect(cache.isFeatureAvailable()).toBe(false)
})
4 changes: 2 additions & 2 deletions packages/cache/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cache/package.json
@@ -1,6 +1,6 @@
{
"name": "@actions/cache",
"version": "1.0.11",
"version": "2.0.0",
"preview": true,
"description": "Actions cache lib",
"keywords": [
Expand Down
10 changes: 10 additions & 0 deletions packages/cache/src/cache.ts
Expand Up @@ -43,6 +43,16 @@ function checkKey(key: string): void {
}
}

/**
* isFeatureAvailable to check the presence of Actions cache service
*
* @returns boolean return true if Actions cache service feature is available, otherwise false
*/

export function isFeatureAvailable(): boolean {
return !!process.env['ACTIONS_CACHE_URL']
}

/**
* Restores cache from keys
*
Expand Down
7 changes: 1 addition & 6 deletions packages/cache/src/internal/cacheHttpClient.ts
Expand Up @@ -31,12 +31,7 @@ import {
const versionSalt = '1.0'

function getCacheApiUrl(resource: string): string {
// Ideally we just use ACTIONS_CACHE_URL
const baseUrl: string = (
process.env['ACTIONS_CACHE_URL'] ||
process.env['ACTIONS_RUNTIME_URL'] ||
''
).replace('pipelines', 'artifactcache')
const baseUrl: string = process.env['ACTIONS_CACHE_URL'] || ''
if (!baseUrl) {
throw new Error('Cache Service Url not found, unable to restore cache.')
}
Expand Down

0 comments on commit b463992

Please sign in to comment.