From b0bbb20f57c43269ee6aa2759a68242e52cde306 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Wed, 1 Jan 2025 22:56:43 +0800 Subject: [PATCH] Prettier formatting --- .github/workflows/test-ghcup.yaml | 8 +- ghcup/src/index.ts | 4 +- ghcup/src/main.ts | 119 +++++++++++++++++------------- 3 files changed, 73 insertions(+), 58 deletions(-) diff --git a/.github/workflows/test-ghcup.yaml b/.github/workflows/test-ghcup.yaml index 70a6b93..58d9ad3 100644 --- a/.github/workflows/test-ghcup.yaml +++ b/.github/workflows/test-ghcup.yaml @@ -15,7 +15,7 @@ jobs: - [self-hosted, FreeBSD, X64] version: - latest - - '0.1.30.0' + - "0.1.30.0" runs-on: ${{ matrix.runs-on }} steps: - uses: actions/checkout@v4 @@ -34,17 +34,17 @@ jobs: - run: ghcup whereis ghc latest - run: which ghc - run: ghc --version - + - run: ghcup install cabal latest --set - run: ghcup whereis cabal latest - run: which cabal - run: cabal --version - + - run: ghcup install stack latest --set - run: ghcup whereis stack latest - run: which stack - run: stack --version - + - run: ghcup install hls latest --set - run: ghcup whereis hls latest - run: which haskell-language-server-wrapper diff --git a/ghcup/src/index.ts b/ghcup/src/index.ts index c17b083..6dce598 100644 --- a/ghcup/src/index.ts +++ b/ghcup/src/index.ts @@ -1,4 +1,4 @@ -import { main, getInputAsBool } from "./main.ts" +import { main, getInputAsBool } from "./main.ts"; import core from "@actions/core"; try { @@ -6,7 +6,7 @@ try { version: core.getInput("version"), release_channels: core.getMultilineInput("release-channels"), stack_hook: getInputAsBool("stack-hook"), - }) + }); } catch (error) { core.setFailed((error as Error).message); } diff --git a/ghcup/src/main.ts b/ghcup/src/main.ts index a43b8a0..ee83830 100644 --- a/ghcup/src/main.ts +++ b/ghcup/src/main.ts @@ -1,38 +1,39 @@ -import * as path from 'path'; -import * as fs from 'fs'; -import os from 'os'; -import { chmod } from 'fs/promises'; +import * as path from "path"; +import * as fs from "fs"; +import os from "os"; +import { chmod } from "fs/promises"; -import tc from '@actions/tool-cache'; -import core, { platform } from '@actions/core'; -import exec from '@actions/exec'; +import tc from "@actions/tool-cache"; +import core, { platform } from "@actions/core"; +import exec from "@actions/exec"; const ext = platform.isWindows ? ".exe" : ""; type Architecture = typeof platform.arch; -type GHCupArch = 'aarch64' | 'armv7' | 'i386' | 'x86_64'; +type GHCupArch = "aarch64" | "armv7" | "i386" | "x86_64"; const ghcup_arch_map: Map = new Map([ - ['arm64', 'aarch64'], - ['arm', 'armv7'], - ['ia32', 'i386'], - ['x64', 'x86_64'] + ["arm64", "aarch64"], + ["arm", "armv7"], + ["ia32", "i386"], + ["x64", "x86_64"], ]); type Platform = typeof platform.platform; -type GHCupOS = 'apple-darwin' | 'linux' | 'mingw64' | 'portbld-freebsd'; +type GHCupOS = "apple-darwin" | "linux" | "mingw64" | "portbld-freebsd"; const ghcup_os_map: Map = new Map([ - ['darwin', 'apple-darwin'], - ['linux', 'linux'], - ['win32', 'mingw64'], - ['freebsd', 'portbld-freebsd'] + ["darwin", "apple-darwin"], + ["linux", "linux"], + ["win32", "mingw64"], + ["freebsd", "portbld-freebsd"], ]); -const hook_url: string = 'https://www.haskell.org/ghcup/sh/hooks/stack/ghc-install.sh'; +const hook_url: string = + "https://www.haskell.org/ghcup/sh/hooks/stack/ghc-install.sh"; function ghcup_url(version: string, arch: GHCupArch, gos: GHCupOS): string { - if (version == 'latest') { + if (version == "latest") { return `https://downloads.haskell.org/ghcup/${arch}-${gos}-ghcup${ext}`; } else { return `https://downloads.haskell.org/ghcup/${version}/${arch}-${gos}-ghcup-${version}${ext}`; @@ -40,11 +41,10 @@ function ghcup_url(version: string, arch: GHCupArch, gos: GHCupOS): string { } async function ghcup(version: string) { - const ghcupDirectory = tc.find('ghcup', version) + const ghcupDirectory = tc.find("ghcup", version); if (ghcupDirectory) { - return ghcupDirectory + return ghcupDirectory; } else { - const arch = ghcup_arch_map.get(platform.arch); if (arch == undefined) { throw `GHCup does not support architecture ${platform.arch}`; @@ -57,63 +57,76 @@ async function ghcup(version: string) { const url = ghcup_url(version, arch, gos); - const tempDirectory = process.env['RUNNER_TEMP'] || ''; + const tempDirectory = process.env["RUNNER_TEMP"] || ""; const ghcupExeName = `ghcup${ext}`; const dest = path.join(tempDirectory, ghcupExeName); const ghcupPath = await tc.downloadTool(url, dest); - if (!(platform.isWindows)) { + if (!platform.isWindows) { await chmod(ghcupPath, "0765"); } - const ghcupDir = await tc.cacheFile(ghcupPath, ghcupExeName, "ghcup", version); + const ghcupDir = await tc.cacheFile( + ghcupPath, + ghcupExeName, + "ghcup", + version, + ); core.addPath(ghcupDir); return path.join(ghcupDir, ghcupExeName); } } function getStackRoot() { - const stackXdg = process.env['STACK_XDG']; - - const defaultStackRoot = (() => { if (platform.isWindows) { - const appdata = process.env['APPDATA'] || ''; - return stackXdg ? path.join(process.env['XDG_DATA_HOME'] ?? appdata, 'stack') : path.join(appdata, 'stack'); - } else { - const hdir = os.homedir(); - return stackXdg ? path.join(process.env['XDG_DATA_HOME'] ?? path.join(hdir, '.local', 'share'),'stack') : path.join(hdir, '.stack'); - } - })() - return process.env['STACK_ROOT'] ?? defaultStackRoot; + const stackXdg = process.env["STACK_XDG"]; + + const defaultStackRoot = (() => { + if (platform.isWindows) { + const appdata = process.env["APPDATA"] || ""; + return stackXdg + ? path.join(process.env["XDG_DATA_HOME"] ?? appdata, "stack") + : path.join(appdata, "stack"); + } else { + const hdir = os.homedir(); + return stackXdg + ? path.join( + process.env["XDG_DATA_HOME"] ?? path.join(hdir, ".local", "share"), + "stack", + ) + : path.join(hdir, ".stack"); + } + })(); + return process.env["STACK_ROOT"] ?? defaultStackRoot; } async function installStackHook() { const stack_root = getStackRoot(); - const hook_dest = path.join(stack_root, 'hooks', 'ghc-install.sh') + const hook_dest = path.join(stack_root, "hooks", "ghc-install.sh"); fs.rmSync(hook_dest, { force: true, }); // we do not cache, it isn't versioned const hookPath = await tc.downloadTool(hook_url, hook_dest); - if (!(platform.isWindows)) { + if (!platform.isWindows) { await chmod(hook_dest, "0765"); } core.debug(`stack ghcup hook is at ${hookPath}`); } export function getInputAsBool( - name: string, - options?: core.InputOptions + name: string, + options?: core.InputOptions, ): boolean { - const result = core.getInput(name, options); - return result.toLowerCase() === "true"; + const result = core.getInput(name, options); + return result.toLowerCase() === "true"; } export type Opts = { - version: string, - release_channels: string[], - stack_hook: boolean -} + version: string; + release_channels: string[]; + stack_hook: boolean; +}; export async function main(opts: Opts) { const ghcupPath = await ghcup(opts.version); @@ -130,17 +143,19 @@ export async function main(opts: Opts) { core.addPath(bindir); if (platform.isWindows) { - const ghcup_msys2 = process.env['GHCUP_MSYS2'] ?? 'C:\\msys64'; - core.exportVariable('GHCUP_MSYS2', ghcup_msys2); - core.debug(`GHCUP_MSYS2 is ${ghcup_msys2}`); + const ghcup_msys2 = process.env["GHCUP_MSYS2"] ?? "C:\\msys64"; + core.exportVariable("GHCUP_MSYS2", ghcup_msys2); + core.debug(`GHCUP_MSYS2 is ${ghcup_msys2}`); } if (opts.stack_hook) { - installStackHook() + installStackHook(); } await exec.exec(ghcupPath, [ - 'config', 'set', 'url-source', JSON.stringify(opts.release_channels) + "config", + "set", + "url-source", + JSON.stringify(opts.release_channels), ]); } -