From b179378e1e5851e9d6a33a10cb553a3b7481cde7 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Mon, 30 Jan 2023 15:11:16 +0100 Subject: [PATCH] use `getCurrentPackageManager` and `isCacheEnabled` --- src/cache-save.ts | 12 ++++++++---- src/main.ts | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cache-save.ts b/src/cache-save.ts index 6c5d3fa..84850c7 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -2,7 +2,12 @@ import * as core from '@actions/core'; import * as cache from '@actions/cache'; import fs from 'fs'; import {State} from './constants'; -import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils'; +import { + getCacheDirectoryPath, + getPackageManagerInfo, + isCacheEnabled +} from './cache-utils'; +import {getCurrentPackageManager} from './package-managers'; // Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in // @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to @@ -28,12 +33,11 @@ export async function run() { } const cachePackages = async () => { - const cacheInput = core.getBooleanInput('cache'); - if (!cacheInput) { + if (!(await isCacheEnabled())) { return; } - const packageManager = 'default'; + const packageManager = getCurrentPackageManager(); const state = core.getState(State.CacheMatchedKey); const primaryKey = core.getState(State.CachePrimaryKey); diff --git a/src/main.ts b/src/main.ts index 6cdb2e6..ec09ac0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,10 +4,11 @@ import * as installer from './installer'; import * as semver from 'semver'; import path from 'path'; import {restoreCache} from './cache-restore'; -import {isCacheFeatureAvailable} from './cache-utils'; +import {isCacheEnabled, isCacheFeatureAvailable} from './cache-utils'; import cp from 'child_process'; import fs from 'fs'; import os from 'os'; +import {getCurrentPackageManager} from './package-managers'; export async function run() { try { @@ -17,7 +18,6 @@ export async function run() { // const versionSpec = resolveVersionInput(); - const cache = core.getBooleanInput('cache'); core.info(`Setup go version spec ${versionSpec}`); let arch = core.getInput('architecture'); @@ -59,8 +59,8 @@ export async function run() { let goPath = await io.which('go'); let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); - if (cache && isCacheFeatureAvailable()) { - const packageManager = 'default'; + if ((await isCacheEnabled()) && isCacheFeatureAvailable()) { + const packageManager = getCurrentPackageManager(); const cacheDependencyPath = core.getInput('cache-dependency-path'); await restoreCache( parseGoVersion(goVersion),