From c733861b29aea24038aa214ab42b6b0863e8cf34 Mon Sep 17 00:00:00 2001 From: Ivan Zosimov Date: Mon, 4 Apr 2022 19:29:29 +0200 Subject: [PATCH] Fix review points --- README.md | 4 ++-- action.yml | 5 ++++- dist/setup/index.js | 7 ++++--- src/cache-restore.ts | 3 ++- src/main.ts | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 36f0d09..8360061 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: '1.14' + go-version: '1.17' check-latest: true cache: true - run: go run hello.go @@ -117,7 +117,7 @@ steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: '1.14' + go-version: '1.17' check-latest: true cache: true cache-dependency-path: subdir/go.sum diff --git a/action.yml b/action.yml index 00f5a35..01fb7d5 100644 --- a/action.yml +++ b/action.yml @@ -12,11 +12,14 @@ inputs: default: ${{ github.token }} cache: description: Used to specify whether go-modules caching is needed. Set to true, if you'd like to enable caching. + default: false cache-dependency-path: description: 'Used to specify the path to a dependency file - go.sum' +outputs: + cache-hit: + description: 'A boolean value to indicate if a cache was hit' runs: using: 'node16' main: 'dist/setup/index.js' post: 'dist/cache-save/index.js' post-if: success() - diff --git a/dist/setup/index.js b/dist/setup/index.js index 60c54cb..7658257 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -3700,7 +3700,7 @@ function run() { // If not supplied then problem matchers will still be setup. Useful for self-hosted. // let versionSpec = core.getInput('go-version'); - const cache = core.getInput('cache'); + const cache = core.getBooleanInput('cache'); core.info(`Setup go version spec ${versionSpec}`); if (versionSpec) { let token = core.getInput('token'); @@ -3723,7 +3723,7 @@ function run() { if (isGhes()) { throw new Error('Caching is not supported on GHES'); } - const packageManager = cache.toUpperCase() === 'TRUE' ? 'default' : cache; + const packageManager = 'default'; const cacheDependencyPath = core.getInput('cache-dependency-path'); yield cache_restore_1.restoreCache(packageManager, cacheDependencyPath); } @@ -34244,6 +34244,7 @@ const cache_utils_1 = __webpack_require__(143); exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager); const platform = process.env.RUNNER_OS; + const versionSpec = core.getInput('go-version'); const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo); const dependencyFilePath = cacheDependencyPath ? cacheDependencyPath @@ -34252,7 +34253,7 @@ exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0 if (!fileHash) { throw new Error('Some specified paths were not resolved, unable to cache dependencies.'); } - const primaryKey = `go-cache-${platform}-${fileHash}`; + const primaryKey = `${platform}-go${versionSpec}-${fileHash}`; core.debug(`primary key is ${primaryKey}`); core.saveState(constants_1.State.CachePrimaryKey, primaryKey); const cacheKey = yield cache.restoreCache([cachePath], primaryKey); diff --git a/src/cache-restore.ts b/src/cache-restore.ts index 08438b5..b3769fa 100644 --- a/src/cache-restore.ts +++ b/src/cache-restore.ts @@ -14,6 +14,7 @@ export const restoreCache = async ( ) => { const packageManagerInfo = await getPackageManagerInfo(packageManager); const platform = process.env.RUNNER_OS; + const versionSpec = core.getInput('go-version'); const cachePath = await getCacheDirectoryPath(packageManagerInfo); @@ -28,7 +29,7 @@ export const restoreCache = async ( ); } - const primaryKey = `go-cache-${platform}-${fileHash}`; + const primaryKey = `${platform}-go${versionSpec}-${fileHash}`; core.debug(`primary key is ${primaryKey}`); core.saveState(State.CachePrimaryKey, primaryKey); diff --git a/src/main.ts b/src/main.ts index 21f8ef6..42a24e7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,7 +16,7 @@ export async function run() { // let versionSpec = core.getInput('go-version'); - const cache = core.getInput('cache'); + const cache = core.getBooleanInput('cache'); core.info(`Setup go version spec ${versionSpec}`); if (versionSpec) { @@ -45,7 +45,7 @@ export async function run() { if (isGhes()) { throw new Error('Caching is not supported on GHES'); } - const packageManager = cache.toUpperCase() === 'TRUE' ? 'default' : cache; + const packageManager = 'default'; const cacheDependencyPath = core.getInput('cache-dependency-path'); await restoreCache(packageManager, cacheDependencyPath); }