-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
30 lines (29 loc) · 859 Bytes
/
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
const core = require('@actions/core');
try {
const regexPattern = core.getInput('regex_pattern');
const regexFlags = core.getInput('regex_flags');
const searchString = core.getInput('search_string');
if (!regexPattern) {
core.setFailed('regex_pattern input is required');
return;
}
if (!regexFlags) {
core.setFailed('regex_flags input is required');
return;
}
if (!searchString) {
core.setFailed('search_string input is required');
return;
}
const regex = new RegExp(regexPattern, regexFlags ?? '');
const matches = searchString.match(regex);
if (!matches) {
console.log('Could not find any matches');
return;
}
console.log('Found:', matches);
console.log('set output "first_match":', matches[0]);
core.setOutput('first_match', matches[0]);
} catch (error) {
core.setFailed(error.message);
}