Initial project setup
Partly ported from actions/setup-ruby
This commit is contained in:
54
src/installer.ts
Normal file
54
src/installer.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
|
||||
export async function cacheHaskellTool(installDir: string, tool: string) {
|
||||
const baseGHCDir: string = path.join(installDir, tool);
|
||||
const versions: string[] = fs.readdirSync(baseGHCDir);
|
||||
for (const v of versions) {
|
||||
const version = normalizeVersion(v);
|
||||
core.debug(`found ${tool} version: ${v} normalized to ${version}`);
|
||||
const dir: string = path.join(baseGHCDir, v);
|
||||
await tc.cacheDir(dir, tool, version);
|
||||
}
|
||||
}
|
||||
|
||||
export async function findHaskellGHCVersion(version: string) {
|
||||
return _findHaskellToolVersion('ghc', version);
|
||||
}
|
||||
|
||||
export async function findHaskellCabalVersion(version: string) {
|
||||
return _findHaskellToolVersion('cabal', version);
|
||||
}
|
||||
|
||||
export async function _findHaskellToolVersion(tool: string, version: string) {
|
||||
version = normalizeVersion(version);
|
||||
const installDir: string | null = tc.find(tool, version);
|
||||
if (!installDir) {
|
||||
throw new Error(`Version ${version} of ${tool} not found`);
|
||||
}
|
||||
|
||||
const toolPath: string = path.join(installDir, 'bin');
|
||||
|
||||
core.addPath(toolPath);
|
||||
}
|
||||
|
||||
// This function is required to convert the version 1.10 to 1.10.0.
|
||||
// Because caching utility accept only sementic version,
|
||||
// which have patch number as well.
|
||||
function normalizeVersion(version: string): string {
|
||||
const versionPart = version.split('.');
|
||||
if (versionPart[1] == null) {
|
||||
//append minor and patch version if not available
|
||||
return version.concat('.0.0');
|
||||
}
|
||||
if (versionPart[2] == null) {
|
||||
//append patch version if not available
|
||||
return version.concat('.0');
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
15
src/setup-haskell.ts
Normal file
15
src/setup-haskell.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import * as core from '@actions/core';
|
||||
import {findHaskellGHCVersion, cacheHaskellTool} from './installer';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
await cacheHaskellTool('/opt', 'ghc');
|
||||
await cacheHaskellTool('/opt', 'cabal');
|
||||
let ghcVersion = core.getInput('ghc-version');
|
||||
await findHaskellGHCVersion(ghcVersion);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user