Skip to content

Commit

Permalink
Enable caching by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Feb 13, 2023
1 parent a3d889c commit eced1f8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ The action has a built-in functionality for caching and restoring go modules and

The action defaults to search for the dependency file - go.sum in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` input for cases when multiple dependency files are used, or they are located in different subdirectories.

Since 4.0.0 the cache is enabled by default.

**Caching without specifying dependency file path**
```yaml
steps:
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inputs:
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
cache:
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
default: false
default: true
cache-dependency-path:
description: 'Used to specify the path to a dependency file - go.sum'
architecture:
Expand Down
10 changes: 8 additions & 2 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60457,8 +60457,14 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
});
exports.getPackageManagerInfo = getPackageManagerInfo;
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
const cachePaths = pathList.filter(item => item);
const pathOutputs = yield Promise.allSettled(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
pathOutputs
.filter(output => output.status === 'rejected')
.forEach(output => core.warning(`getting cache directory path failed: ${output.reason}`));
const cachePaths = pathOutputs
.filter(output => output.status === 'fulfilled' &&
output.value)
.map(output => output.value);
if (!cachePaths.length) {
throw new Error(`Could not get cache folder paths.`);
}
Expand Down
10 changes: 8 additions & 2 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63130,8 +63130,14 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
});
exports.getPackageManagerInfo = getPackageManagerInfo;
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
const cachePaths = pathList.filter(item => item);
const pathOutputs = yield Promise.allSettled(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
pathOutputs
.filter(output => output.status === 'rejected')
.forEach(output => core.warning(`getting cache directory path failed: ${output.reason}`));
const cachePaths = pathOutputs
.filter(output => output.status === 'fulfilled' &&
output.value)
.map(output => output.value);
if (!cachePaths.length) {
throw new Error(`Could not get cache folder paths.`);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "setup-go",
"version": "3.3.0",
"version": "4.0.0",
"private": true,
"description": "setup go action",
"main": "lib/setup-go.js",
Expand Down
20 changes: 18 additions & 2 deletions src/cache-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,29 @@ export const getPackageManagerInfo = async (packageManager: string) => {
export const getCacheDirectoryPath = async (
packageManagerInfo: PackageManagerInfo
) => {
const pathList = await Promise.all(
const pathOutputs = await Promise.allSettled(
packageManagerInfo.cacheFolderCommandList.map(command =>
getCommandOutput(command)
)
);

const cachePaths = pathList.filter(item => item);
pathOutputs
.filter(output => output.status === 'rejected')
.forEach(output =>
core.warning(
`getting cache directory path failed: ${
(output as PromiseRejectedResult).reason
}`
)
);

const cachePaths = pathOutputs
.filter(
output =>
output.status === 'fulfilled' &&
(output as PromiseFulfilledResult<string>).value
)
.map(output => (output as PromiseFulfilledResult<string>).value);

if (!cachePaths.length) {
throw new Error(`Could not get cache folder paths.`);
Expand Down

0 comments on commit eced1f8

Please sign in to comment.