use getCurrentPackageManager and isCacheEnabled

This commit is contained in:
Sergey Dolin 2023-01-30 15:11:16 +01:00
parent 03f925ed17
commit b179378e1e
2 changed files with 12 additions and 8 deletions

View file

@ -2,7 +2,12 @@ import * as core from '@actions/core';
import * as cache from '@actions/cache'; import * as cache from '@actions/cache';
import fs from 'fs'; import fs from 'fs';
import {State} from './constants'; 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 // 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 // @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 cachePackages = async () => {
const cacheInput = core.getBooleanInput('cache'); if (!(await isCacheEnabled())) {
if (!cacheInput) {
return; return;
} }
const packageManager = 'default'; const packageManager = getCurrentPackageManager();
const state = core.getState(State.CacheMatchedKey); const state = core.getState(State.CacheMatchedKey);
const primaryKey = core.getState(State.CachePrimaryKey); const primaryKey = core.getState(State.CachePrimaryKey);

View file

@ -4,10 +4,11 @@ import * as installer from './installer';
import * as semver from 'semver'; import * as semver from 'semver';
import path from 'path'; import path from 'path';
import {restoreCache} from './cache-restore'; import {restoreCache} from './cache-restore';
import {isCacheFeatureAvailable} from './cache-utils'; import {isCacheEnabled, isCacheFeatureAvailable} from './cache-utils';
import cp from 'child_process'; import cp from 'child_process';
import fs from 'fs'; import fs from 'fs';
import os from 'os'; import os from 'os';
import {getCurrentPackageManager} from './package-managers';
export async function run() { export async function run() {
try { try {
@ -17,7 +18,6 @@ export async function run() {
// //
const versionSpec = resolveVersionInput(); const versionSpec = resolveVersionInput();
const cache = core.getBooleanInput('cache');
core.info(`Setup go version spec ${versionSpec}`); core.info(`Setup go version spec ${versionSpec}`);
let arch = core.getInput('architecture'); let arch = core.getInput('architecture');
@ -59,8 +59,8 @@ export async function run() {
let goPath = await io.which('go'); let goPath = await io.which('go');
let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); let goVersion = (cp.execSync(`${goPath} version`) || '').toString();
if (cache && isCacheFeatureAvailable()) { if ((await isCacheEnabled()) && isCacheFeatureAvailable()) {
const packageManager = 'default'; const packageManager = getCurrentPackageManager();
const cacheDependencyPath = core.getInput('cache-dependency-path'); const cacheDependencyPath = core.getInput('cache-dependency-path');
await restoreCache( await restoreCache(
parseGoVersion(goVersion), parseGoVersion(goVersion),