Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Toolchain download before cache download #456

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58600,8 +58600,8 @@ const cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const package_managers_1 = __nccwpck_require__(6663);
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
const getCommandOutput = (toolCommand, execOpts) => __awaiter(void 0, void 0, void 0, function* () {
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, Object.assign(Object.assign({}, execOpts), { ignoreReturnCode: true }));
if (exitCode) {
stderr = !stderr.trim()
? `The '${toolCommand}' command failed with exit code: ${exitCode}`
Expand All @@ -58619,8 +58619,8 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
return obtainedPackageManager;
});
exports.getPackageManagerInfo = getPackageManagerInfo;
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const pathOutputs = yield Promise.allSettled(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command); })));
const getCacheDirectoryPath = (packageManagerInfo, execOpts) => __awaiter(void 0, void 0, void 0, function* () {
const pathOutputs = yield Promise.allSettled(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command, execOpts); })));
const results = pathOutputs.map(item => {
if (item.status === 'fulfilled') {
return item.value;
Expand Down
22 changes: 15 additions & 7 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61194,7 +61194,9 @@ const cache_utils_1 = __nccwpck_require__(1678);
const restoreCache = (versionSpec, 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 cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo, {
env: Object.assign(Object.assign({}, process.env), { GOTOOLCHAIN: 'local' })
});
const dependencyFilePath = cacheDependencyPath
? cacheDependencyPath
: findDependencyFile(packageManagerInfo);
Expand Down Expand Up @@ -61270,8 +61272,8 @@ const cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const package_managers_1 = __nccwpck_require__(6663);
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
const getCommandOutput = (toolCommand, execOpts) => __awaiter(void 0, void 0, void 0, function* () {
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, Object.assign(Object.assign({}, execOpts), { ignoreReturnCode: true }));
if (exitCode) {
stderr = !stderr.trim()
? `The '${toolCommand}' command failed with exit code: ${exitCode}`
Expand All @@ -61289,8 +61291,8 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
return obtainedPackageManager;
});
exports.getPackageManagerInfo = getPackageManagerInfo;
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const pathOutputs = yield Promise.allSettled(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command); })));
const getCacheDirectoryPath = (packageManagerInfo, execOpts) => __awaiter(void 0, void 0, void 0, function* () {
const pathOutputs = yield Promise.allSettled(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command, execOpts); })));
const results = pathOutputs.map(item => {
if (item.status === 'fulfilled') {
return item.value;
Expand Down Expand Up @@ -61817,7 +61819,11 @@ function run() {
const added = yield addBinToPath();
core.debug(`add bin ${added}`);
const goPath = yield io.which('go');
const goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString();
// run `go version` with the bundled Go toolchain to avoid potentially
// downloading one into the cache
const goVersion = (child_process_1.default.execSync(`${goPath} version`, {
env: Object.assign(Object.assign({}, process.env), { GOTOOLCHAIN: 'local' })
}) || '').toString();
if (cache && cache_utils_1.isCacheFeatureAvailable()) {
const packageManager = 'default';
const cacheDependencyPath = core.getInput('cache-dependency-path');
Expand Down Expand Up @@ -61854,7 +61860,9 @@ function addBinToPath() {
core.debug('go not in the path');
return added;
}
const buf = child_process_1.default.execSync('go env GOPATH');
const buf = child_process_1.default.execSync('go env GOPATH', {
env: Object.assign(Object.assign({}, process.env), { GOTOOLCHAIN: 'local' })
});
if (buf.length > 1) {
const gp = buf.toString().trim();
core.debug(`go env GOPATH :${gp}:`);
Expand Down
4 changes: 3 additions & 1 deletion src/cache-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const restoreCache = async (
const packageManagerInfo = await getPackageManagerInfo(packageManager);
const platform = process.env.RUNNER_OS;

const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
const cachePaths = await getCacheDirectoryPath(packageManagerInfo, {
env: {...process.env, GOTOOLCHAIN: 'local'}
});

const dependencyFilePath = cacheDependencyPath
? cacheDependencyPath
Expand Down
12 changes: 8 additions & 4 deletions src/cache-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';

export const getCommandOutput = async (toolCommand: string) => {
export const getCommandOutput = async (
toolCommand: string,
execOpts?: exec.ExecOptions
) => {
let {stdout, stderr, exitCode} = await exec.getExecOutput(
toolCommand,
undefined,
{ignoreReturnCode: true}
{...execOpts, ignoreReturnCode: true}
);

if (exitCode) {
Expand All @@ -32,11 +35,12 @@ export const getPackageManagerInfo = async (packageManager: string) => {
};

export const getCacheDirectoryPath = async (
packageManagerInfo: PackageManagerInfo
packageManagerInfo: PackageManagerInfo,
execOpts?: exec.ExecOptions
) => {
const pathOutputs = await Promise.allSettled(
packageManagerInfo.cacheFolderCommandList.map(async command =>
getCommandOutput(command)
getCommandOutput(command, execOpts)
)
);

Expand Down
12 changes: 10 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ export async function run() {
core.debug(`add bin ${added}`);

const goPath = await io.which('go');
const goVersion = (cp.execSync(`${goPath} version`) || '').toString();
// run `go version` with the bundled Go toolchain to avoid potentially
// downloading one into the cache
const goVersion = (
cp.execSync(`${goPath} version`, {
env: {...process.env, GOTOOLCHAIN: 'local'}
}) || ''
).toString();

if (cache && isCacheFeatureAvailable()) {
const packageManager = 'default';
Expand Down Expand Up @@ -105,7 +111,9 @@ export async function addBinToPath(): Promise<boolean> {
return added;
}

const buf = cp.execSync('go env GOPATH');
const buf = cp.execSync('go env GOPATH', {
env: {...process.env, GOTOOLCHAIN: 'local'}
});
if (buf.length > 1) {
const gp = buf.toString().trim();
core.debug(`go env GOPATH :${gp}:`);
Expand Down