4
0
Fork 0
mirror of https://github.com/actions/setup-go.git synced 2025-11-07 12:36:55 +00:00

Compare commits

...

20 commits

Author SHA1 Message Date
Anton Troshin
1e25f2b888
Merge 461004e4c9 into 7bc60db215 2025-10-28 18:20:53 +05:30
Nicholas Ngai
7bc60db215
Fall back to downloading from go.dev/dl instead of storage.googleapis.com/golang (#665)
* Fall back to downloading from dl.google.com/go instead of storage.googleapis.com/golang

* Use go.dev/dl instead
2025-10-27 15:43:21 -05:00
Anton Troshin
461004e4c9
fix: add check for D: drive existence in Windows cache directory setup
Signed-off-by: Anton Troshin <18515134+antontroshin@users.noreply.github.com>
2025-06-12 02:24:23 -05:00
Anton Troshin
6ccafa914b
Merge branch 'main' of github.com:antontroshin/setup-go into windows-go-mod-cache 2025-06-12 02:13:10 -05:00
Anton Troshin
fdd38598b9
add GOTMPDIR override for Windows workflow
add validation for GOCACHE, GOMODCACHE, and GOTMPDIR on Windows

Signed-off-by: Anton Troshin <anton@diagrid.io>
2025-03-07 13:35:32 -06:00
Anton Troshin
bda02de888
remove previous attempt logic
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 21:28:54 -06:00
Anton Troshin
be775566d4
try different approach by overriding go ENV GOCACHE and GOMODCACHE vars for Windows
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 21:15:12 -06:00
Anton Troshin
5b1dffca1b
remove empty cache folders to be able to create symlinks
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 20:15:14 -06:00
Anton Troshin
e91efc513b
fix
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 19:27:12 -06:00
Anton Troshin
e3c077dd6d
more logs and logic change
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 16:51:26 -06:00
Anton Troshin
f8cf508b5f
lint and build
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 16:21:45 -06:00
Anton Troshin
c8eefa5dde
wrap with try, debugging errors
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 16:20:55 -06:00
Anton Troshin
896e2cbf0f
add logs
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 13:05:53 -06:00
Anton Troshin
fd3fcb34ee
move symlink check
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 12:28:31 -06:00
Anton Troshin
6cd0eaadd6
lint and build
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 12:09:58 -06:00
Anton Troshin
0dc6404f6a
add check for existing symlink
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 11:50:35 -06:00
Anton Troshin
434fb17078
Fix path replace
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-19 10:50:13 -06:00
Anton Troshin
97e00a50c1
build
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-18 19:26:53 -06:00
Anton Troshin
0859a18f70
add logs
Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-18 19:24:46 -06:00
Anton Troshin
28b19b8019
Add GOCACHE AND GOMODCACHE symlink on Windows
Use D drive for faster cache restore

Signed-off-by: Anton Troshin <anton@diagrid.io>
2024-11-18 18:53:10 -06:00
7 changed files with 141 additions and 10 deletions

View file

@ -134,3 +134,40 @@ jobs:
with:
go-version: ${{ matrix.go }}
cache: ${{ matrix.cache }}
go-mod-cache-and-tmp-location:
name: 'Validate if GOCACHE, GOMODCACHE, GOTMPDIR is set to drive D:'
runs-on: windows-latest
strategy:
matrix:
cache: [false]
go: [1.20.1]
steps:
- uses: actions/checkout@v4
- name: 'Setup ${{ matrix.go }}, cache: ${{ matrix.cache }}'
uses: ./
with:
go-version: ${{ matrix.go }}
cache: ${{ matrix.cache }}
- name: 'Check if go mod cache and tmp location is set correctly'
run: |
go env GOCACHE
go env GOMODCACHE
go env GOTMPDIR
if [ $(go env GOCACHE) != 'D:\Users\runneradmin\AppData\Local\go-build' ];then
echo 'go env GOCACHE should return "D:\Users\runneradmin\AppData\Local\go-build"'
exit 1
fi
if [ $(go env GOMODCACHE) != 'D:\Users\runneradmin\go\pkg\mod' ];then
echo 'go env GOMODCACHE should return "D:\Users\runneradmin\go\pkg\mod"'
exit 1
fi
if [ $(go env GOTMPDIR) != 'D:\gotmp' ];then
echo 'go env GOTMPDIR should return "D:\gotmp"'
exit 1
fi
shell: bash

View file

@ -27,7 +27,7 @@ See full release notes on the [releases page](https://github.com/actions/setup-g
The action will first check the local cache for a version match. If a version is not found locally, it will pull it from
the `main` branch of the [go-versions](https://github.com/actions/go-versions/blob/main/versions-manifest.json)
repository. On miss or failure, it will fall back to downloading directly
from [go dist](https://storage.googleapis.com/golang). To change the default behavior, please use
from [go dist](https://go.dev/dl). To change the default behavior, please use
the [check-latest input](#check-latest-version).
**Note:** The `setup-go` action uses executable binaries which are built by Golang side. The action does not build
@ -240,7 +240,7 @@ When dynamically downloading Go distributions, `setup-go` downloads distribution
These calls to `actions/go-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting).
If more requests are made within the time frame, then the action leverages the `raw API` to retrieve the version-manifest. This approach does not impose a rate limit and hence facilitates unrestricted consumption. This is particularly beneficial for GHES runners, which often share the same IP, to avoid the quick exhaustion of the unauthenticated rate limit.
If that fails as well the action will try to download versions directly from https://storage.googleapis.com/golang.
If that fails as well the action will try to download versions directly from https://go.dev/dl.
If that fails as well you can get a higher rate limit with [generating a personal access token on github.com](https://github.com/settings/tokens/new) and passing it as the `token` input to the action:

View file

@ -389,7 +389,7 @@ describe('setup-go', () => {
const expPath = path.win32.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalledWith(
'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip',
'https://go.dev/dl/go1.13.1.windows-amd64.zip',
'C:\\temp\\go1.13.1.windows-amd64.zip',
undefined
);
@ -946,7 +946,7 @@ use .
const expectedUrl =
platform === 'win32'
? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}`
: `https://storage.googleapis.com/golang/go${version}.${osSpec}-${arch}.${fileExtension}`;
: `https://go.dev/dl/go${version}.${osSpec}-${arch}.${fileExtension}`;
// ... but not in the local cache
findSpy.mockImplementation(() => '');

43
dist/setup/index.js vendored
View file

@ -94077,7 +94077,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.restoreCache = void 0;
exports.setWindowsCacheDirectories = exports.restoreCache = void 0;
const cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186));
const glob = __importStar(__nccwpck_require__(8090));
@ -94085,6 +94085,7 @@ const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const constants_1 = __nccwpck_require__(9042);
const cache_utils_1 = __nccwpck_require__(1678);
const os_1 = __importDefault(__nccwpck_require__(2037));
const restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
const packageManagerInfo = yield (0, cache_utils_1.getPackageManagerInfo)(packageManager);
const platform = process.env.RUNNER_OS;
@ -94112,6 +94113,43 @@ const restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awa
core.info(`Cache restored from key: ${cacheKey}`);
});
exports.restoreCache = restoreCache;
const setWindowsCacheDirectories = () => __awaiter(void 0, void 0, void 0, function* () {
if (os_1.default.platform() !== 'win32')
return;
if (!fs_1.default.existsSync('D:'))
return;
let goCache = yield (0, cache_utils_1.getCommandOutput)(`go env GOCACHE`);
core.info(`GOCACHE: ${goCache}`);
goCache = goCache.replace('C:', 'D:').replace('c:', 'd:');
if (!fs_1.default.existsSync(goCache)) {
core.info(`${goCache} does not exist. Creating`);
fs_1.default.mkdirSync(goCache, { recursive: true });
}
const setOutput = yield (0, cache_utils_1.getCommandOutput)(`go env -w GOCACHE=${goCache}`);
core.info(`go env -w GOCACHE output: ${setOutput}`);
let goModCache = yield (0, cache_utils_1.getCommandOutput)(`go env GOMODCACHE`);
core.info(`GOMODCACHE: ${goModCache}`);
goModCache = goModCache.replace('C:', 'D:').replace('c:', 'd:');
if (!fs_1.default.existsSync(goModCache)) {
core.info(`${goModCache} does not exist. Creating`);
fs_1.default.mkdirSync(goModCache, { recursive: true });
}
const setModOutput = yield (0, cache_utils_1.getCommandOutput)(`go env -w GOMODCACHE=${goModCache}`);
core.info(`go env -w GOMODCACHE output: ${setModOutput}`);
let goTmpDir = yield (0, cache_utils_1.getCommandOutput)(`go env GOTMPDIR`);
core.info(`GOTMPDIR: ${goTmpDir}`);
if (!goTmpDir || goTmpDir === '') {
goTmpDir = 'D:\\gotmp';
}
goTmpDir = goTmpDir.replace('C:', 'D:').replace('c:', 'd:');
if (!fs_1.default.existsSync(goTmpDir)) {
core.info(`${goTmpDir} does not exist. Creating`);
fs_1.default.mkdirSync(goTmpDir, { recursive: true });
}
const setGoTmpOutput = yield (0, cache_utils_1.getCommandOutput)(`go env -w GOTMPDIR=${goTmpDir}`);
core.info(`go env -w GOTMPDIR output: ${setGoTmpOutput}`);
});
exports.setWindowsCacheDirectories = setWindowsCacheDirectories;
const findDependencyFile = (packageManager) => {
const dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE;
@ -94583,7 +94621,7 @@ function getInfoFromDist(versionSpec, arch) {
if (!version) {
return null;
}
const downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
const downloadUrl = `https://go.dev/dl/${version.files[0].filename}`;
return {
type: 'dist',
downloadUrl: downloadUrl,
@ -94790,6 +94828,7 @@ const os_1 = __importDefault(__nccwpck_require__(2037));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield (0, cache_restore_1.setWindowsCacheDirectories)();
//
// versionSpec is optional. If supplied, install / use from the tool cache
// If not supplied then problem matchers will still be setup. Useful for self-hosted.

View file

@ -4,9 +4,14 @@ import * as glob from '@actions/glob';
import path from 'path';
import fs from 'fs';
import {State, Outputs} from './constants';
import {Outputs, State} from './constants';
import {PackageManagerInfo} from './package-managers';
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
import {
getCacheDirectoryPath,
getCommandOutput,
getPackageManagerInfo
} from './cache-utils';
import os from 'os';
export const restoreCache = async (
versionSpec: string,
@ -50,6 +55,55 @@ export const restoreCache = async (
core.info(`Cache restored from key: ${cacheKey}`);
};
export const setWindowsCacheDirectories = async () => {
if (os.platform() !== 'win32') return;
if (!fs.existsSync('D:')) return;
let goCache = await getCommandOutput(`go env GOCACHE`);
core.info(`GOCACHE: ${goCache}`);
goCache = goCache.replace('C:', 'D:').replace('c:', 'd:');
if (!fs.existsSync(goCache)) {
core.info(`${goCache} does not exist. Creating`);
fs.mkdirSync(goCache, {recursive: true});
}
const setOutput = await getCommandOutput(`go env -w GOCACHE=${goCache}`);
core.info(`go env -w GOCACHE output: ${setOutput}`);
let goModCache = await getCommandOutput(`go env GOMODCACHE`);
core.info(`GOMODCACHE: ${goModCache}`);
goModCache = goModCache.replace('C:', 'D:').replace('c:', 'd:');
if (!fs.existsSync(goModCache)) {
core.info(`${goModCache} does not exist. Creating`);
fs.mkdirSync(goModCache, {recursive: true});
}
const setModOutput = await getCommandOutput(
`go env -w GOMODCACHE=${goModCache}`
);
core.info(`go env -w GOMODCACHE output: ${setModOutput}`);
let goTmpDir = await getCommandOutput(`go env GOTMPDIR`);
core.info(`GOTMPDIR: ${goTmpDir}`);
if (!goTmpDir || goTmpDir === '') {
goTmpDir = 'D:\\gotmp';
}
goTmpDir = goTmpDir.replace('C:', 'D:').replace('c:', 'd:');
if (!fs.existsSync(goTmpDir)) {
core.info(`${goTmpDir} does not exist. Creating`);
fs.mkdirSync(goTmpDir, {recursive: true});
}
const setGoTmpOutput = await getCommandOutput(
`go env -w GOTMPDIR=${goTmpDir}`
);
core.info(`go env -w GOTMPDIR output: ${setGoTmpOutput}`);
};
const findDependencyFile = (packageManager: PackageManagerInfo) => {
const dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE!;

View file

@ -389,7 +389,7 @@ async function getInfoFromDist(
return null;
}
const downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
const downloadUrl = `https://go.dev/dl/${version.files[0].filename}`;
return <IGoVersionInfo>{
type: 'dist',

View file

@ -3,7 +3,7 @@ import * as io from '@actions/io';
import * as installer from './installer';
import * as semver from 'semver';
import path from 'path';
import {restoreCache} from './cache-restore';
import {restoreCache, setWindowsCacheDirectories} from './cache-restore';
import {isCacheFeatureAvailable} from './cache-utils';
import cp from 'child_process';
import fs from 'fs';
@ -12,6 +12,7 @@ import {Architecture} from './types';
export async function run() {
try {
await setWindowsCacheDirectories();
//
// versionSpec is optional. If supplied, install / use from the tool cache
// If not supplied then problem matchers will still be setup. Useful for self-hosted.