-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: add dynamically loaded cache-dependencies module
This reduces the main bundle size by⚠️ 1.1 MB minified! This bundle is loaded only when caching is enabled. The reason for this huge reduction is that caching dependencies uses the `@actions/cache` package, which is an extremely large package with big dependencies. `setup-python` is used in `setup-cpp` as a library. This optimization reduces the bundle size for that package as well.
- Loading branch information
Showing
5 changed files
with
119 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as cache from '@actions/cache'; | ||
import * as core from '@actions/core'; | ||
import {getCacheDistributor} from './cache-distributions/cache-factory'; | ||
|
||
export async function cacheDependencies(cache: string, pythonVersion: string) { | ||
if (isCacheFeatureAvailable()) { | ||
const cacheDependencyPath = | ||
core.getInput('cache-dependency-path') || undefined; | ||
const cacheDistributor = getCacheDistributor( | ||
cache, | ||
pythonVersion, | ||
cacheDependencyPath | ||
); | ||
await cacheDistributor.restoreCache(); | ||
} | ||
} | ||
|
||
function isGhes(): boolean { | ||
const ghUrl = new URL( | ||
process.env['GITHUB_SERVER_URL'] || 'https://github.com' | ||
); | ||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; | ||
} | ||
|
||
export function isCacheFeatureAvailable(): boolean { | ||
if (cache.isFeatureAvailable()) { | ||
return true; | ||
} | ||
|
||
if (isGhes()) { | ||
core.warning( | ||
'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.' | ||
); | ||
return false; | ||
} | ||
|
||
core.warning( | ||
'The runner was not able to contact the cache service. Caching will be skipped' | ||
); | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters