This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
forked from haskell-actions/run-ormolu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
107 lines (82 loc) · 3.59 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
106
107
import * as path from 'path';
import * as fs from 'fs';
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 fourmolu_version = '0.6.0.0';
// XXX: These release binaries appear to be dynamically linked, so they may not
// run on some systems.
const fourmolu_linux_url = 'https://github.com/fourmolu/fourmolu/releases/download/v' + fourmolu_version + '/fourmolu-' + fourmolu_version + '-linux-x86_64';
// TODO: As of this writing, there are no Windows or MacOSX binaries available
// for fourmolu. However, according to
// https://brandonchinn178.github.io/blog/2022/05/19/automating-fourmolu-releases-with-github-actions.html,
// they should be available from the next release. We may need to change these URLs
// when the actual binaries are available.
//const fourmolu_windows_url = 'https://github.com/fourmolu/fourmolu/releases/download/v' + fourmolu_version + '/fourmolu-' + fourmolu_version + '-windows-x86_64';
//const fourmolu_macos_url = 'https://github.com/fourmolu/fourmolu/releases/download/v' + fourmolu_version + '/fourmolu-' + fourmolu_version + '-darwin-x86_64';
const input_pattern = core.getInput('pattern');
const input_follow_symbolic_links = core.getInput('follow-symbolic-links').toUpperCase() !== 'FALSE';
const input_extra_args = core.getInput('extra-args');
async function run() {
try {
// Download fourmolu binary
var fourmolu_downloaded_binary;
if (process.platform === 'linux') {
fourmolu_downloaded_binary = await tool_cache.downloadTool(fourmolu_linux_url);
}
// else if (process.platform === 'darwin') {
// fourmolu_downloaded_binary = await tool_cache.downloadTool(fourmolu_macos_url);
// }
// else if (process.platform === 'win32') {
// fourmolu_downloaded_binary = await tool_cache.downloadTool(fourmolu_windows_url);
// }
else {
core.setFailed("no fourmolu binary found for platform: " + process.platform);
}
// At this point, fourmolu_downloaded_binary is the fourmolu binary we just
// downloaded, but tool_cache.downloadTool() gives it a random UUID as a
// name. We rename it to `fourmolu` here.
const fourmolu_binary = path.join(path.dirname(fourmolu_downloaded_binary), 'fourmolu');
fs.renameSync(fourmolu_downloaded_binary, fourmolu_binary)
// Cache fourmolu executable
const fourmolu_cached_dir = await tool_cache.cacheDir(
path.dirname(fourmolu_binary),
'fourmolu',
fourmolu_version
);
const fourmolu_cached_path = path.join(fourmolu_cached_dir, 'fourmolu');
// Set mode
exec.exec('chmod', ['+x', fourmolu_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(' ');
}
// Run fourmolu
await exec.exec(fourmolu_cached_path, ['--version']);
if (files.length > 0) {
await exec.exec(
fourmolu_cached_path,
['--color', 'always', '--check-idempotence', '--mode', 'check']
.concat(extra_args)
.concat(files)
);
}
else {
core.warning("The glob patterns did not match any source files");
}
} catch (error) {
core.setFailed("fourmolu detected unformatted files");
}
}
run();