-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
55 lines (46 loc) · 1.33 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
const YAML = require("yaml");
const extractActions = require("./extractActions");
const replaceActions = require("./replaceActions");
const findRefOnGithub = require("./findRefOnGithub");
const checkAllowedRepos = require("./checkAllowedRepos");
const isSha = require("./isSha");
module.exports = async function (
input,
allowed,
ignoreShas,
allowEmpty,
debug,
yamlLineWidth,
yamlNullStr,
comment
) {
allowed = allowed || [];
ignoreShas = ignoreShas || false;
// Parse the workflow file
let workflow = YAML.parseDocument(input);
// Extract list of actions
let actions = extractActions(workflow, allowEmpty, comment, debug);
for (let i in actions) {
// Should this action be updated?
const action = `${actions[i].owner}/${actions[i].repo}`;
if (checkAllowedRepos(action, allowed, debug)) {
continue;
}
if (ignoreShas && isSha(actions[i])) {
continue;
}
// Look up those actions on Github
const newVersion = await findRefOnGithub(actions[i], debug);
actions[i].newVersion = newVersion;
// Rewrite each action, replacing the uses block with a specific sha
workflow = replaceActions(workflow, actions[i], comment);
}
stringOpts = {
lineWidth: yamlLineWidth,
nullStr: yamlNullStr,
};
return {
workflow: workflow.toString(stringOpts),
actions,
};
};