mirror of
https://github.com/actions/setup-go.git
synced 2026-11-14 05:02:26 +00:00
Add support for native Go version syntax in go-version input (#804)
* Add support for native Go version syntax in go-version input * Enhance Go-native version handling and update tests and documentation * Update docs
This commit is contained in:
committed by
GitHub
parent
90ad2b35f6
commit
3c1b57c66a
+27
-4
@@ -60,6 +60,11 @@ export async function getGo(
|
||||
const osPlat: string = os.platform();
|
||||
const customBaseUrl = goDownloadBaseUrl?.replace(/\/+$/, '');
|
||||
|
||||
const originalVersionSpec = versionSpec;
|
||||
if (isGoNativeVersion(versionSpec)) {
|
||||
versionSpec = makeSemver(versionSpec);
|
||||
}
|
||||
|
||||
if (
|
||||
versionSpec === StableReleaseAlias.Stable ||
|
||||
versionSpec === StableReleaseAlias.OldStable
|
||||
@@ -146,7 +151,11 @@ export async function getGo(
|
||||
core.info(
|
||||
'Skipping version listing for known direct-download URL. Constructing download URL directly.'
|
||||
);
|
||||
info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl);
|
||||
info = getInfoFromDirectDownload(
|
||||
originalVersionSpec,
|
||||
arch,
|
||||
customBaseUrl
|
||||
);
|
||||
} else {
|
||||
try {
|
||||
info = await getInfoFromDist(versionSpec, arch, customBaseUrl);
|
||||
@@ -156,7 +165,11 @@ export async function getGo(
|
||||
);
|
||||
}
|
||||
if (!info) {
|
||||
info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl);
|
||||
info = getInfoFromDirectDownload(
|
||||
originalVersionSpec,
|
||||
arch,
|
||||
customBaseUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,13 +180,13 @@ export async function getGo(
|
||||
const downloadUrl = info?.downloadUrl || customBaseUrl;
|
||||
if (err instanceof tc.HTTPError && err.httpStatusCode === 404) {
|
||||
throw new Error(
|
||||
`The requested Go version ${versionSpec} is not available for platform ${osPlat}/${arch}. ` +
|
||||
`The requested Go version ${originalVersionSpec} is not available for platform ${osPlat}/${arch}. ` +
|
||||
`Download URL returned HTTP 404: ${downloadUrl}`,
|
||||
{cause: err}
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`Failed to download Go ${versionSpec} for platform ${osPlat}/${arch} ` +
|
||||
`Failed to download Go ${originalVersionSpec} for platform ${osPlat}/${arch} ` +
|
||||
`from ${downloadUrl}: ${err}`,
|
||||
{cause: err}
|
||||
);
|
||||
@@ -610,6 +623,12 @@ export async function findMatch(
|
||||
return result;
|
||||
}
|
||||
|
||||
export function isGoNativeVersion(version: string): boolean {
|
||||
const expression =
|
||||
/^go[1-9]\d*\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*)|(?:beta|rc)[1-9]\d*)?$/;
|
||||
return expression.test(version);
|
||||
}
|
||||
|
||||
//
|
||||
// Convert the go version syntax into semver for semver matching
|
||||
// 1.13.1 => 1.13.1
|
||||
@@ -617,6 +636,10 @@ export async function findMatch(
|
||||
// 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
|
||||
// 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
|
||||
export function makeSemver(version: string): string {
|
||||
const validVersion = semver.valid(version);
|
||||
if (validVersion) {
|
||||
return validVersion;
|
||||
}
|
||||
version = version.replace('go', '');
|
||||
version = version.replace('beta', '-beta.').replace('rc', '-rc.');
|
||||
const parts = version.split('-');
|
||||
|
||||
+12
@@ -215,6 +215,18 @@ function resolveVersionInput(): string {
|
||||
}
|
||||
|
||||
if (version) {
|
||||
const customBaseUrl =
|
||||
core.getInput('go-download-base-url') ||
|
||||
process.env['GO_DOWNLOAD_BASE_URL'];
|
||||
if (
|
||||
version.startsWith('go') &&
|
||||
!customBaseUrl &&
|
||||
!installer.isGoNativeVersion(version)
|
||||
) {
|
||||
throw new Error(
|
||||
`Invalid Go version "${version}". Go-native versions must look like go1.21, go1.21.5, go1.18beta2, or go1.21rc2. For version ranges, use SemVer syntax (e.g. ~1.21, ^1.21).`
|
||||
);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user