Initial project setup

Partly ported from actions/setup-ruby
This commit is contained in:
Timothy Clem
2019-09-23 19:56:26 -07:00
commit 1068d0618d
15 changed files with 5796 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
!node_modules/
__tests__/runner/*

11
.prettierrc.json Normal file
View File

@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

22
LICENSE Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2018 GitHub, Inc. and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

52
README.md Normal file
View File

@@ -0,0 +1,52 @@
# setup-haskell
<p align="left">
<a href="https://github.com/actions/setup-haskell"><img alt="GitHub Actions status" src="https://github.com/actions/setup-haskell/workflows/Main%20workflow/badge.svg"></a>
</p>
This action sets up a Haskell environment for use in actions by:
- optionally installing a version of ghc and cabal and adding to PATH. Note that this action only uses versions of ghc and cabal already installed in the cache. The action will fail if no matching versions are found.
- registering problem matchers for error output
# Usage
See [action.yml](action.yml)
Basic:
``` yaml
steps:
- uses: actions/checkout@master
- uses: actions/setup-haskell@v1
with:
ghc-version: '8.6.5' # Version range or exact version of ghc to use, using semvers version range syntax.
- run: runghc Hello.hs
```
Matrix Testing:
``` yaml
jobs:
build:
runs-on: ubuntu-16.04
strategy:
matrix:
ghc: [ '8.2.2', '8.6.5' ]
name: Haskell GHC ${{ matrix.ghc }} sample
steps:
- uses: actions/checkout@master
- name: Setup Haskell
uses: actions/setup-haskell@v1
with:
ghc-version: ${{ matrix.ghc }}
- run: runghc Hello.hs
```
# License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
# Contributions
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)

View File

@@ -0,0 +1,83 @@
import * as io from '@actions/io';
import fs = require('fs');
import os = require('os');
import path = require('path');
const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp');
process.env['AGENT_TOOLSDIRECTORY'] = toolDir;
process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir;
import {
findHaskellGHCVersion,
findHaskellCabalVersion,
cacheHaskellTool
} from '../src/installer';
describe('find-haskell', () => {
beforeAll(async () => {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
const ghcDir: string = path.join(tempDir, 'ghc', '8.6.5', 'bin');
await io.mkdirP(ghcDir);
fs.writeFileSync(`${ghcDir}.complete`, 'hello');
await cacheHaskellTool(tempDir, 'ghc');
const cabalDir: string = path.join(tempDir, 'cabal', '2.0', 'bin');
await io.mkdirP(cabalDir);
fs.writeFileSync(`${cabalDir}.complete`, 'hello');
await cacheHaskellTool(tempDir, 'cabal');
});
afterAll(async () => {
try {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
} catch {
console.log('Failed to remove test directories');
}
}, 100000);
it('Caches ghc into tool cache', async () => {
const ghcDir: string = path.join(tempDir, 'ghc', '8.6.4', 'bin');
await io.mkdirP(ghcDir);
fs.writeFileSync(`${ghcDir}.complete`, 'hello');
await cacheHaskellTool(tempDir, 'ghc');
const installDir: string = path.join(toolDir, 'ghc', '8.6.4', os.arch());
expect(fs.existsSync(installDir)).toBe(true);
});
it('Caches cabal into tool cache', async () => {
const cabalDir: string = path.join(tempDir, 'cabal', '2.4', 'bin');
await io.mkdirP(cabalDir);
fs.writeFileSync(`${cabalDir}.complete`, 'hello');
await cacheHaskellTool(tempDir, 'cabal');
const installDir: string = path.join(toolDir, 'cabal', '2.4.0', os.arch());
expect(fs.existsSync(installDir)).toBe(true);
});
it('Uses version of ghc installed in cache', async () => {
// This will throw if it doesn't find it in the cache (because no such version exists)
await findHaskellGHCVersion('8.6.5');
});
it('Uses version of cabal installed in cache', async () => {
// This will throw if it doesn't find it in the cache (because no such version exists)
await findHaskellCabalVersion('2.0');
});
it('findHaskellGHCVersion throws if cannot find any version of ghc', async () => {
let thrown = false;
try {
await findHaskellGHCVersion('9.9.9');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});
});

10
action.yml Normal file
View File

@@ -0,0 +1,10 @@
name: 'Setup Haskell environment'
description: 'Setup a Haskell environment and add it to the PATH'
author: 'GitHub'
inputs:
ghc-version:
description: 'Version range or exact version of ghc to use.'
default: '>= 8.6.5'
runs:
using: 'node12'
main: 'lib/setup-haskell.js'

22
docs/contributors.md Normal file
View File

@@ -0,0 +1,22 @@
# Contributors
### Checkin
- Do checkin source (src)
- Do checkin build output (lib)
- Do checkin runtime node_modules
- Do not checkin devDependency node_modules (husky can help see below)
### devDependencies
In order to handle correctly checking in node_modules without devDependencies, we run [Husky](https://github.com/typicode/husky) before each commit.
This step ensures that formatting and checkin rules are followed and that devDependencies are excluded. To make sure Husky runs correctly, please use the following workflow:
```
npm install # installs all devDependencies including Husky
git add abc.ext # Add the files you've changed. This should include files in src, lib, and node_modules (see above)
git commit -m "Informative commit message" # Commit. This will run Husky
```
During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier) as well as pruning out devDependencies using `npm prune --production`.
It will also make sure these changes are appropriately included in your commit (no further work is needed)

11
jest.config.js Normal file
View File

@@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}

62
lib/installer.js Normal file
View File

@@ -0,0 +1,62 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const tc = __importStar(require("@actions/tool-cache"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const semver = __importStar(require("semver"));
function cacheHaskell(installDir, tool) {
return __awaiter(this, void 0, void 0, function* () {
const baseGHCDir = path.join(installDir, tool);
const versions = fs.readdirSync(baseGHCDir);
for (const v of versions) {
const version = semver.clean(v);
if (!version) {
continue;
}
core.debug(`found ${tool} version: ${version}`);
const dir = path.join(baseGHCDir, version);
yield tc.cacheDir(dir, tool, version);
}
});
}
exports.cacheHaskell = cacheHaskell;
function findHaskellGHCVersion(version) {
return __awaiter(this, void 0, void 0, function* () {
return _findHaskellToolVersion('ghc', version);
});
}
exports.findHaskellGHCVersion = findHaskellGHCVersion;
function findHaskellCabalVersion(version) {
return __awaiter(this, void 0, void 0, function* () {
return _findHaskellToolVersion('cabal', version);
});
}
exports.findHaskellCabalVersion = findHaskellCabalVersion;
function _findHaskellToolVersion(tool, version) {
return __awaiter(this, void 0, void 0, function* () {
const installDir = tc.find(tool, version);
if (!installDir) {
throw new Error(`Version ${version} of ${tool} not found`);
}
const toolPath = path.join(installDir, 'bin');
core.addPath(toolPath);
});
}
exports._findHaskellToolVersion = _findHaskellToolVersion;

34
lib/setup-haskell.js Normal file
View File

@@ -0,0 +1,34 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const installer_1 = require("./installer");
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
installer_1.cacheHaskell('/opt', 'ghc');
installer_1.cacheHaskell('/opt', 'cabal');
let ghcVersion = core.getInput('ghc-version');
yield installer_1.findHaskellGHCVersion(ghcVersion);
}
catch (error) {
core.setFailed(error.message);
}
});
}
run();

5305
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

50
package.json Normal file
View File

@@ -0,0 +1,50 @@
{
"name": "setup-haskell",
"version": "1.0.0",
"private": true,
"description": "setup haskell action",
"main": "lib/setup-haskell.js",
"scripts": {
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/actions/setup-haskell.git"
},
"keywords": [
"actions",
"haskell",
"ghc",
"cabal",
"setup"
],
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.1.1",
"@actions/tool-cache": "^1.1.1",
"semver": "^6.1.1"
},
"devDependencies": {
"@actions/io": "^1.0.1",
"@types/jest": "^24.0.18",
"@types/node": "^12.7.5",
"@types/semver": "^6.0.2",
"husky": "^2.3.0",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"prettier": "^1.17.1",
"ts-jest": "^24.1.0",
"typescript": "^3.6.3"
},
"husky": {
"skipCI": true,
"hooks": {
"pre-commit": "npm run build && npm run format",
"post-commit": "npm prune --production && git add node_modules/* && git commit -m \"Husky commit correct node modules\""
}
}
}

54
src/installer.ts Normal file
View 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
View 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();

63
tsconfig.json Normal file
View File

@@ -0,0 +1,63 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": ["node_modules", "**/*.test.ts"]
}