mirror of
https://github.com/actions/setup-go.git
synced 2026-07-17 02:28:06 +00:00
Migrate to ESM and upgrade dependencies (#763)
* Migrate to ESM and upgrade dependencies * Remove unused tsconfig.eslint.json * bump version to 7.0.0 in package.json and package-lock.json * Add ESM migration note to README for V7 * Remove unnecessary devDependencies: ts-node, @types/jest * npm audit fix * Update README with ESM migration details Clarified migration details to ESM for action compatibility. * Downgrade @types/node to ^24, clean up tsconfig and README.
This commit is contained in:
@@ -4,9 +4,9 @@ import * as glob from '@actions/glob';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
import {State, Outputs} from './constants';
|
||||
import {PackageManagerInfo} from './package-managers';
|
||||
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
|
||||
import {State, Outputs} from './constants.js';
|
||||
import {PackageManagerInfo} from './package-managers.js';
|
||||
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils.js';
|
||||
|
||||
export const restoreCache = async (
|
||||
versionSpec: string,
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as cache from '@actions/cache';
|
||||
import fs from 'fs';
|
||||
import {State} from './constants';
|
||||
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
|
||||
import {State} from './constants.js';
|
||||
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils.js';
|
||||
|
||||
// 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
|
||||
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
||||
import {
|
||||
supportedPackageManagers,
|
||||
PackageManagerInfo
|
||||
} from './package-managers.js';
|
||||
|
||||
export const getCommandOutput = async (toolCommand: string) => {
|
||||
let {stdout, stderr, exitCode} = await exec.getExecOutput(
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import * as httpm from '@actions/http-client';
|
||||
import type {IGoVersion} from './installer.js';
|
||||
|
||||
export async function getVersionsDist(
|
||||
dlUrl: string
|
||||
): Promise<IGoVersion[] | null> {
|
||||
// this returns versions descending so latest is first
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('setup-go', [], {
|
||||
allowRedirects: true,
|
||||
maxRedirects: 3
|
||||
});
|
||||
return (await http.getJson<IGoVersion[]>(dlUrl)).result;
|
||||
}
|
||||
+14
-23
@@ -3,13 +3,14 @@ import * as core from '@actions/core';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import * as httpm from '@actions/http-client';
|
||||
import * as sys from './system';
|
||||
import * as sys from './system.js';
|
||||
import crypto from 'crypto';
|
||||
import cp from 'child_process';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import {StableReleaseAlias, isSelfHosted} from './utils';
|
||||
import {Architecture} from './types';
|
||||
import {StableReleaseAlias, isSelfHosted} from './utils.js';
|
||||
import {Architecture} from './types.js';
|
||||
import {getVersionsDist} from './go-version-fetch.js';
|
||||
|
||||
export const GOTOOLCHAIN_ENV_VAR = 'GOTOOLCHAIN';
|
||||
export const GOTOOLCHAIN_LOCAL_VAL = 'local';
|
||||
@@ -167,12 +168,14 @@ export async function getGo(
|
||||
if (err instanceof tc.HTTPError && err.httpStatusCode === 404) {
|
||||
throw new Error(
|
||||
`The requested Go version ${versionSpec} is not available for platform ${osPlat}/${arch}. ` +
|
||||
`Download URL returned HTTP 404: ${downloadUrl}`
|
||||
`Download URL returned HTTP 404: ${downloadUrl}`,
|
||||
{cause: err}
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`Failed to download Go ${versionSpec} for platform ${osPlat}/${arch} ` +
|
||||
`from ${downloadUrl}: ${err}`
|
||||
`from ${downloadUrl}: ${err}`,
|
||||
{cause: err}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -218,7 +221,9 @@ export async function getGo(
|
||||
core.info('Install from dist');
|
||||
downloadPath = await installGoVersion(info, undefined, arch);
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
|
||||
throw new Error(`Failed to download version ${versionSpec}: ${err}`, {
|
||||
cause: err
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -569,9 +574,7 @@ export async function findMatch(
|
||||
let result: IGoVersion | undefined;
|
||||
let match: IGoVersion | undefined;
|
||||
|
||||
const candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
|
||||
dlUrl
|
||||
);
|
||||
const candidates: IGoVersion[] | null = await getVersionsDist(dlUrl);
|
||||
if (!candidates) {
|
||||
throw new Error(`golang download url did not return results`);
|
||||
}
|
||||
@@ -607,17 +610,6 @@ export async function findMatch(
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getVersionsDist(
|
||||
dlUrl: string
|
||||
): Promise<IGoVersion[] | null> {
|
||||
// this returns versions descending so latest is first
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('setup-go', [], {
|
||||
allowRedirects: true,
|
||||
maxRedirects: 3
|
||||
});
|
||||
return (await http.getJson<IGoVersion[]>(dlUrl)).result;
|
||||
}
|
||||
|
||||
//
|
||||
// Convert the go version syntax into semver for semver matching
|
||||
// 1.13.1 => 1.13.1
|
||||
@@ -686,9 +678,8 @@ async function resolveStableVersionDist(
|
||||
) {
|
||||
const archFilter = sys.getArch(arch);
|
||||
const platFilter = sys.getPlatform();
|
||||
const candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
|
||||
GOLANG_DOWNLOAD_URL
|
||||
);
|
||||
const candidates: IGoVersion[] | null =
|
||||
await getVersionsDist(GOLANG_DOWNLOAD_URL);
|
||||
if (!candidates) {
|
||||
throw new Error(`golang download url did not return results`);
|
||||
}
|
||||
|
||||
+10
-5
@@ -1,14 +1,15 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as installer from './installer';
|
||||
import * as installer from './installer.js';
|
||||
import * as semver from 'semver';
|
||||
import path from 'path';
|
||||
import {restoreCache} from './cache-restore';
|
||||
import {isCacheFeatureAvailable} from './cache-utils';
|
||||
import {fileURLToPath} from 'url';
|
||||
import {restoreCache} from './cache-restore.js';
|
||||
import {isCacheFeatureAvailable} from './cache-utils.js';
|
||||
import cp from 'child_process';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import {Architecture} from './types';
|
||||
import {Architecture} from './types.js';
|
||||
|
||||
export async function run() {
|
||||
try {
|
||||
@@ -91,7 +92,11 @@ export async function run() {
|
||||
}
|
||||
|
||||
// add problem matchers
|
||||
const matchersPath = path.join(__dirname, '../..', 'matchers.json');
|
||||
const matchersPath = path.join(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
'../..',
|
||||
'matchers.json'
|
||||
);
|
||||
core.info(`##[add-matcher]${matchersPath}`);
|
||||
|
||||
// output the version actually being used
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
import {run} from './main';
|
||||
import {run} from './main.js';
|
||||
|
||||
run();
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import os from 'os';
|
||||
import {Architecture} from './types';
|
||||
import {Architecture} from './types.js';
|
||||
|
||||
export function getPlatform(): string {
|
||||
// darwin and linux match already
|
||||
|
||||
Reference in New Issue
Block a user