-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
105 lines (79 loc) · 3.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import * as path from 'path';
const core = require('@actions/core');
const github = require('@actions/github');
const tool_cache = require('@actions/tool-cache');
const exec = require('@actions/exec');
const glob = require('@actions/glob');
const input_version = core.getInput('version');
const ormolu_version = input_version === 'latest' ? '0.7.7.0' : input_version;
const ormolu_linux_url = 'https://github.com/tweag/ormolu/releases/download/' + ormolu_version + '/ormolu-x86_64-linux.zip';
const ormolu_windows_url = 'https://github.com/tweag/ormolu/releases/download/' + ormolu_version + '/ormolu-x86_64-windows.zip';
const ormolu_darwin_url = 'https://github.com/tweag/ormolu/releases/download/' + ormolu_version + '/ormolu-aarch64-darwin.zip';
const input_pattern = core.getInput('pattern');
const input_respect_cabal_files = core.getInput('respect-cabal-files').toUpperCase() !== 'FALSE';
const input_follow_symbolic_links = core.getInput('follow-symbolic-links').toUpperCase() !== 'FALSE';
const input_mode = core.getInput('mode').toLowerCase();
const input_extra_args = core.getInput('extra-args');
async function run() {
try {
// Download ormolu archive
var ormolu_archive;
if (process.platform === 'win32') {
ormolu_archive = await tool_cache.downloadTool(ormolu_windows_url);
}
else if (process.platform === 'darwin') {
ormolu_archive = await tool_cache.downloadTool(ormolu_darwin_url);
}
else {
ormolu_archive = await tool_cache.downloadTool(ormolu_linux_url);
}
// Unpack the archive
const ormolu_extracted_dir = process.env['RUNNER_TEMP'];
await tool_cache.extractZip(ormolu_archive, ormolu_extracted_dir);
// const ormolu_extracted_path = path.join(ormolu_extracted_dir, 'ormolu');
// Cache ormolu executable
const ormolu_cached_dir = await tool_cache.cacheDir(
ormolu_extracted_dir,
'ormolu',
ormolu_version
);
const ormolu_cached_path = path.join(ormolu_cached_dir, 'ormolu');
// Set mode
await exec.exec('chmod', ['+x', ormolu_cached_path], {silent: true});
// Glob for the files to format
const globber = await glob.create(
input_pattern,
{
followSymbolicLinks: input_follow_symbolic_links
}
);
const files = await globber.glob();
// Extra args
var extra_args = [];
if (input_extra_args) {
extra_args = input_extra_args.split(' ');
}
// Respect Cabal files
var respect_cabal_files = [];
if (!(input_respect_cabal_files)) {
respect_cabal_files = ['--no-cabal'];
}
// Run ormolu
await exec.exec(ormolu_cached_path, ['--version']);
if (files.length > 0) {
await exec.exec(
ormolu_cached_path,
['--color', 'always', '--check-idempotence', '--mode', input_mode]
.concat(respect_cabal_files)
.concat(extra_args)
.concat(files)
);
}
else {
core.warning("The glob patterns did not match any source files");
}
} catch (error) {
core.setFailed("Ormolu detected unformatted files");
}
}
run();