Fix review points

This commit is contained in:
Ivan Zosimov 2022-04-04 19:29:29 +02:00
parent c1691a39b4
commit c733861b29
5 changed files with 14 additions and 9 deletions

View file

@ -105,7 +105,7 @@ steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-go@v3 - uses: actions/setup-go@v3
with: with:
go-version: '1.14' go-version: '1.17'
check-latest: true check-latest: true
cache: true cache: true
- run: go run hello.go - run: go run hello.go
@ -117,7 +117,7 @@ steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-go@v3 - uses: actions/setup-go@v3
with: with:
go-version: '1.14' go-version: '1.17'
check-latest: true check-latest: true
cache: true cache: true
cache-dependency-path: subdir/go.sum cache-dependency-path: subdir/go.sum

View file

@ -12,11 +12,14 @@ inputs:
default: ${{ github.token }} default: ${{ github.token }}
cache: cache:
description: Used to specify whether go-modules caching is needed. Set to true, if you'd like to enable caching. 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: cache-dependency-path:
description: 'Used to specify the path to a dependency file - go.sum' 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: runs:
using: 'node16' using: 'node16'
main: 'dist/setup/index.js' main: 'dist/setup/index.js'
post: 'dist/cache-save/index.js' post: 'dist/cache-save/index.js'
post-if: success() post-if: success()

7
dist/setup/index.js vendored
View file

@ -3700,7 +3700,7 @@ function run() {
// If not supplied then problem matchers will still be setup. Useful for self-hosted. // If not supplied then problem matchers will still be setup. Useful for self-hosted.
// //
let versionSpec = core.getInput('go-version'); let versionSpec = core.getInput('go-version');
const cache = core.getInput('cache'); const cache = core.getBooleanInput('cache');
core.info(`Setup go version spec ${versionSpec}`); core.info(`Setup go version spec ${versionSpec}`);
if (versionSpec) { if (versionSpec) {
let token = core.getInput('token'); let token = core.getInput('token');
@ -3723,7 +3723,7 @@ function run() {
if (isGhes()) { if (isGhes()) {
throw new Error('Caching is not supported on GHES'); 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'); const cacheDependencyPath = core.getInput('cache-dependency-path');
yield cache_restore_1.restoreCache(packageManager, cacheDependencyPath); 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* () { exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager); const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
const platform = process.env.RUNNER_OS; const platform = process.env.RUNNER_OS;
const versionSpec = core.getInput('go-version');
const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo); const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
const dependencyFilePath = cacheDependencyPath const dependencyFilePath = cacheDependencyPath
? cacheDependencyPath ? cacheDependencyPath
@ -34252,7 +34253,7 @@ exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0
if (!fileHash) { if (!fileHash) {
throw new Error('Some specified paths were not resolved, unable to cache dependencies.'); 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.debug(`primary key is ${primaryKey}`);
core.saveState(constants_1.State.CachePrimaryKey, primaryKey); core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
const cacheKey = yield cache.restoreCache([cachePath], primaryKey); const cacheKey = yield cache.restoreCache([cachePath], primaryKey);

View file

@ -14,6 +14,7 @@ export const restoreCache = async (
) => { ) => {
const packageManagerInfo = await getPackageManagerInfo(packageManager); const packageManagerInfo = await getPackageManagerInfo(packageManager);
const platform = process.env.RUNNER_OS; const platform = process.env.RUNNER_OS;
const versionSpec = core.getInput('go-version');
const cachePath = await getCacheDirectoryPath(packageManagerInfo); 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.debug(`primary key is ${primaryKey}`);
core.saveState(State.CachePrimaryKey, primaryKey); core.saveState(State.CachePrimaryKey, primaryKey);

View file

@ -16,7 +16,7 @@ export async function run() {
// //
let versionSpec = core.getInput('go-version'); let versionSpec = core.getInput('go-version');
const cache = core.getInput('cache'); const cache = core.getBooleanInput('cache');
core.info(`Setup go version spec ${versionSpec}`); core.info(`Setup go version spec ${versionSpec}`);
if (versionSpec) { if (versionSpec) {
@ -45,7 +45,7 @@ export async function run() {
if (isGhes()) { if (isGhes()) {
throw new Error('Caching is not supported on GHES'); 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'); const cacheDependencyPath = core.getInput('cache-dependency-path');
await restoreCache(packageManager, cacheDependencyPath); await restoreCache(packageManager, cacheDependencyPath);
} }