mirror of
https://github.com/actions/setup-go.git
synced 2025-05-04 14:14:34 +00:00
Add and configure ESLint and update configuration for Prettier (#341)
* Turn on ESLint and update Prettier * Update eslint config * Update eslint config * Update dependencies * Update ESLint and Prettier configurations * update package.json * Update prettier command * Update prettier config file * Change CRLF to LF * Update docs * Update docs
This commit is contained in:
@ -48,7 +48,7 @@ export const restoreCache = async (
|
||||
};
|
||||
|
||||
const findDependencyFile = (packageManager: PackageManagerInfo) => {
|
||||
let dependencyFile = packageManager.dependencyFilePattern;
|
||||
const dependencyFile = packageManager.dependencyFilePattern;
|
||||
const workspace = process.env.GITHUB_WORKSPACE!;
|
||||
const rootContent = fs.readdirSync(workspace);
|
||||
|
||||
|
@ -35,7 +35,7 @@ export const getCacheDirectoryPath = async (
|
||||
packageManagerInfo: PackageManagerInfo
|
||||
) => {
|
||||
const pathList = await Promise.all(
|
||||
packageManagerInfo.cacheFolderCommandList.map(command =>
|
||||
packageManagerInfo.cacheFolderCommandList.map(async command =>
|
||||
getCommandOutput(command)
|
||||
)
|
||||
);
|
||||
|
@ -37,7 +37,7 @@ export async function getGo(
|
||||
arch = os.arch()
|
||||
) {
|
||||
let manifest: tc.IToolRelease[] | undefined;
|
||||
let osPlat: string = os.platform();
|
||||
const osPlat: string = os.platform();
|
||||
|
||||
if (
|
||||
versionSpec === StableReleaseAlias.Stable ||
|
||||
@ -83,8 +83,7 @@ export async function getGo(
|
||||
}
|
||||
|
||||
// check cache
|
||||
let toolPath: string;
|
||||
toolPath = tc.find('go', versionSpec, arch);
|
||||
const toolPath = tc.find('go', versionSpec, arch);
|
||||
// If not found in cache, download
|
||||
if (toolPath) {
|
||||
core.info(`Found in cache @ ${toolPath}`);
|
||||
@ -246,13 +245,12 @@ async function getInfoFromDist(
|
||||
versionSpec: string,
|
||||
arch: string
|
||||
): Promise<IGoVersionInfo | null> {
|
||||
let version: IGoVersion | undefined;
|
||||
version = await findMatch(versionSpec, arch);
|
||||
const version: IGoVersion | undefined = await findMatch(versionSpec, arch);
|
||||
if (!version) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let downloadUrl: string = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
|
||||
const downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
|
||||
|
||||
return <IGoVersionInfo>{
|
||||
type: 'dist',
|
||||
@ -282,8 +280,8 @@ export async function findMatch(
|
||||
|
||||
let goFile: IGoVersionFile | undefined;
|
||||
for (let i = 0; i < candidates.length; i++) {
|
||||
let candidate: IGoVersion = candidates[i];
|
||||
let version = makeSemver(candidate.version);
|
||||
const candidate: IGoVersion = candidates[i];
|
||||
const version = makeSemver(candidate.version);
|
||||
|
||||
core.debug(`check ${version} satisfies ${versionSpec}`);
|
||||
if (semver.satisfies(version, versionSpec)) {
|
||||
@ -331,9 +329,9 @@ export async function getVersionsDist(
|
||||
export function makeSemver(version: string): string {
|
||||
version = version.replace('go', '');
|
||||
version = version.replace('beta', '-beta.').replace('rc', '-rc.');
|
||||
let parts = version.split('-');
|
||||
const parts = version.split('-');
|
||||
|
||||
let semVersion = semver.coerce(parts[0])?.version;
|
||||
const semVersion = semver.coerce(parts[0])?.version;
|
||||
if (!semVersion) {
|
||||
throw new Error(
|
||||
`The version: ${version} can't be changed to SemVer notation`
|
||||
@ -369,9 +367,9 @@ export function parseGoVersionFile(versionFilePath: string): string {
|
||||
}
|
||||
|
||||
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';
|
||||
const archFilter = sys.getArch(arch);
|
||||
const platFilter = sys.getPlatform();
|
||||
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
|
||||
const candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
|
||||
dlUrl
|
||||
);
|
||||
|
20
src/main.ts
20
src/main.ts
@ -27,8 +27,8 @@ export async function run() {
|
||||
}
|
||||
|
||||
if (versionSpec) {
|
||||
let token = core.getInput('token');
|
||||
let auth = !token ? undefined : `token ${token}`;
|
||||
const token = core.getInput('token');
|
||||
const auth = !token ? undefined : `token ${token}`;
|
||||
|
||||
const checkLatest = core.getBooleanInput('check-latest');
|
||||
|
||||
@ -51,13 +51,13 @@ export async function run() {
|
||||
core.exportVariable('GOROOT', installDir);
|
||||
}
|
||||
|
||||
let added = await addBinToPath();
|
||||
const added = await addBinToPath();
|
||||
core.debug(`add bin ${added}`);
|
||||
core.info(`Successfully set up Go version ${versionSpec}`);
|
||||
}
|
||||
|
||||
let goPath = await io.which('go');
|
||||
let goVersion = (cp.execSync(`${goPath} version`) || '').toString();
|
||||
const goPath = await io.which('go');
|
||||
const goVersion = (cp.execSync(`${goPath} version`) || '').toString();
|
||||
|
||||
if (cache && isCacheFeatureAvailable()) {
|
||||
const packageManager = 'default';
|
||||
@ -79,7 +79,7 @@ export async function run() {
|
||||
core.setOutput('go-version', parseGoVersion(goVersion));
|
||||
|
||||
core.startGroup('go env');
|
||||
let goEnv = (cp.execSync(`${goPath} env`) || '').toString();
|
||||
const goEnv = (cp.execSync(`${goPath} env`) || '').toString();
|
||||
core.info(goEnv);
|
||||
core.endGroup();
|
||||
} catch (error) {
|
||||
@ -89,16 +89,16 @@ export async function run() {
|
||||
|
||||
export async function addBinToPath(): Promise<boolean> {
|
||||
let added = false;
|
||||
let g = await io.which('go');
|
||||
const g = await io.which('go');
|
||||
core.debug(`which go :${g}:`);
|
||||
if (!g) {
|
||||
core.debug('go not in the path');
|
||||
return added;
|
||||
}
|
||||
|
||||
let buf = cp.execSync('go env GOPATH');
|
||||
const buf = cp.execSync('go env GOPATH');
|
||||
if (buf.length > 1) {
|
||||
let gp = buf.toString().trim();
|
||||
const gp = buf.toString().trim();
|
||||
core.debug(`go env GOPATH :${gp}:`);
|
||||
if (!fs.existsSync(gp)) {
|
||||
// some of the hosted images have go install but not profile dir
|
||||
@ -106,7 +106,7 @@ export async function addBinToPath(): Promise<boolean> {
|
||||
await io.mkdirP(gp);
|
||||
}
|
||||
|
||||
let bp = path.join(gp, 'bin');
|
||||
const bp = path.join(gp, 'bin');
|
||||
if (!fs.existsSync(bp)) {
|
||||
core.debug(`creating ${bp}`);
|
||||
await io.mkdirP(bp);
|
||||
|
@ -1,4 +1,4 @@
|
||||
const os = require('os');
|
||||
import os from 'os';
|
||||
|
||||
export function getPlatform(): string {
|
||||
// darwin and linux match already
|
||||
|
Reference in New Issue
Block a user