Merge pull request #7 from dmitry-shibanov/fix-stable-aliases-toolcache

Fix stable/oldstable aliases toolcache
This commit is contained in:
Milos Pantic 2022-12-09 09:32:11 +01:00 committed by GitHub
commit 5ae1786fb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 40 deletions

View File

@ -20,7 +20,7 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup Go and check latest - name: Setup Go Stable
uses: ./ uses: ./
with: with:
go-version: stable go-version: stable
@ -35,12 +35,33 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup Go and check latest - name: Setup Go oldStable
uses: ./ uses: ./
with: with:
go-version: oldstable go-version: oldstable
- name: Verify Go - name: Verify Go
run: go version run: go version
aliases-arch:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
version: [stable, oldstable]
architecture: [x64, x32]
exclude:
- os: macos-latest
architecture: x32
steps:
- uses: actions/checkout@v3
- name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }}
uses: ./
with:
go-version: ${{ matrix.version }}
architecture: ${{ matrix.architecture }}
- name: Verify Go
run: go version
local-cache: local-cache:
name: Setup local-cache version name: Setup local-cache version

38
dist/setup/index.js vendored
View File

@ -63234,7 +63234,14 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) {
if (versionSpec === utils_1.StableReleaseAlias.Stable || if (versionSpec === utils_1.StableReleaseAlias.Stable ||
versionSpec === utils_1.StableReleaseAlias.OldStable) { versionSpec === utils_1.StableReleaseAlias.OldStable) {
manifest = yield getManifest(auth); manifest = yield getManifest(auth);
versionSpec = yield resolveStableVersionInput(versionSpec, arch, osPlat, manifest); let stableVersion = yield resolveStableVersionInput(versionSpec, arch, osPlat, manifest);
if (!stableVersion) {
stableVersion = yield resolveStableVersionDist(versionSpec, arch);
if (!stableVersion) {
throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`);
}
}
versionSpec = stableVersion;
} }
if (checkLatest) { if (checkLatest) {
core.info('Attempting to resolve the latest version from the manifest...'); core.info('Attempting to resolve the latest version from the manifest...');
@ -63400,13 +63407,6 @@ function findMatch(versionSpec, arch = os_1.default.arch()) {
if (!candidates) { if (!candidates) {
throw new Error(`golang download url did not return results`); throw new Error(`golang download url did not return results`);
} }
if (versionSpec === utils_1.StableReleaseAlias.Stable ||
versionSpec === utils_1.StableReleaseAlias.OldStable) {
const fixedCandidates = candidates.map(item => {
return Object.assign(Object.assign({}, item), { version: makeSemver(item.version) });
});
versionSpec = yield resolveStableVersionInput(versionSpec, archFilter, platFilter, fixedCandidates);
}
let goFile; let goFile;
for (let i = 0; i < candidates.length; i++) { for (let i = 0; i < candidates.length; i++) {
let candidate = candidates[i]; let candidate = candidates[i];
@ -63479,8 +63479,23 @@ function parseGoVersionFile(versionFilePath) {
return contents.trim(); return contents.trim();
} }
exports.parseGoVersionFile = parseGoVersionFile; exports.parseGoVersionFile = parseGoVersionFile;
function resolveStableVersionDist(versionSpec, arch) {
return __awaiter(this, void 0, void 0, function* () {
let archFilter = sys.getArch(arch);
let platFilter = sys.getPlatform();
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
let candidates = yield module.exports.getVersionsDist(dlUrl);
if (!candidates) {
throw new Error(`golang download url did not return results`);
}
const fixedCandidates = candidates.map(item => {
return Object.assign(Object.assign({}, item), { version: makeSemver(item.version) });
});
const stableVersion = yield resolveStableVersionInput(versionSpec, archFilter, platFilter, fixedCandidates);
return stableVersion;
});
}
function resolveStableVersionInput(versionSpec, arch, platform, manifest) { function resolveStableVersionInput(versionSpec, arch, platform, manifest) {
var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const releases = manifest const releases = manifest
.map(item => { .map(item => {
@ -63493,16 +63508,13 @@ function resolveStableVersionInput(versionSpec, arch, platform, manifest) {
.filter(item => !!item && !semver.prerelease(item)); .filter(item => !!item && !semver.prerelease(item));
if (versionSpec === utils_1.StableReleaseAlias.Stable) { if (versionSpec === utils_1.StableReleaseAlias.Stable) {
core.info(`stable version resolved as ${releases[0]}`); core.info(`stable version resolved as ${releases[0]}`);
return (_a = releases[0]) !== null && _a !== void 0 ? _a : versionSpec; return releases[0];
} }
else { else {
const versions = releases.map(release => `${semver.major(release)}.${semver.minor(release)}`); const versions = releases.map(release => `${semver.major(release)}.${semver.minor(release)}`);
const uniqueVersions = Array.from(new Set(versions)); const uniqueVersions = Array.from(new Set(versions));
const oldstableVersion = releases.find(item => item.startsWith(uniqueVersions[1])); const oldstableVersion = releases.find(item => item.startsWith(uniqueVersions[1]));
core.info(`oldstable version resolved as ${oldstableVersion}`); core.info(`oldstable version resolved as ${oldstableVersion}`);
if (!oldstableVersion) {
return versionSpec;
}
return oldstableVersion; return oldstableVersion;
} }
}); });

View File

@ -44,12 +44,23 @@ export async function getGo(
versionSpec === StableReleaseAlias.OldStable versionSpec === StableReleaseAlias.OldStable
) { ) {
manifest = await getManifest(auth); manifest = await getManifest(auth);
versionSpec = await resolveStableVersionInput( let stableVersion = await resolveStableVersionInput(
versionSpec, versionSpec,
arch, arch,
osPlat, osPlat,
manifest manifest
); );
if (!stableVersion) {
stableVersion = await resolveStableVersionDist(versionSpec, arch);
if (!stableVersion) {
throw new Error(
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
);
}
}
versionSpec = stableVersion;
} }
if (checkLatest) { if (checkLatest) {
@ -267,24 +278,6 @@ export async function findMatch(
throw new Error(`golang download url did not return results`); throw new Error(`golang download url did not return results`);
} }
if (
versionSpec === StableReleaseAlias.Stable ||
versionSpec === StableReleaseAlias.OldStable
) {
const fixedCandidates = candidates.map(item => {
return {
...item,
version: makeSemver(item.version)
};
});
versionSpec = await resolveStableVersionInput(
versionSpec,
archFilter,
platFilter,
fixedCandidates
);
}
let goFile: IGoVersionFile | undefined; let goFile: IGoVersionFile | undefined;
for (let i = 0; i < candidates.length; i++) { for (let i = 0; i < candidates.length; i++) {
let candidate: IGoVersion = candidates[i]; let candidate: IGoVersion = candidates[i];
@ -373,12 +366,40 @@ export function parseGoVersionFile(versionFilePath: string): string {
return contents.trim(); return contents.trim();
} }
async function resolveStableVersionDist(versionSpec: string, arch: string) {
let archFilter = sys.getArch(arch);
let platFilter = sys.getPlatform();
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
let candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
dlUrl
);
if (!candidates) {
throw new Error(`golang download url did not return results`);
}
const fixedCandidates = candidates.map(item => {
return {
...item,
version: makeSemver(item.version)
};
});
const stableVersion = await resolveStableVersionInput(
versionSpec,
archFilter,
platFilter,
fixedCandidates
);
return stableVersion;
}
export async function resolveStableVersionInput( export async function resolveStableVersionInput(
versionSpec: string, versionSpec: string,
arch: string, arch: string,
platform: string, platform: string,
manifest: tc.IToolRelease[] | IGoVersion[] manifest: tc.IToolRelease[] | IGoVersion[]
): Promise<string> { ) {
const releases = manifest const releases = manifest
.map(item => { .map(item => {
const index = item.files.findIndex( const index = item.files.findIndex(
@ -394,7 +415,7 @@ export async function resolveStableVersionInput(
if (versionSpec === StableReleaseAlias.Stable) { if (versionSpec === StableReleaseAlias.Stable) {
core.info(`stable version resolved as ${releases[0]}`); core.info(`stable version resolved as ${releases[0]}`);
return releases[0] ?? versionSpec; return releases[0];
} else { } else {
const versions = releases.map( const versions = releases.map(
release => `${semver.major(release)}.${semver.minor(release)}` release => `${semver.major(release)}.${semver.minor(release)}`
@ -407,10 +428,6 @@ export async function resolveStableVersionInput(
core.info(`oldstable version resolved as ${oldstableVersion}`); core.info(`oldstable version resolved as ${oldstableVersion}`);
if (!oldstableVersion) {
return versionSpec;
}
return oldstableVersion; return oldstableVersion;
} }
} }