-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
61 lines (51 loc) · 1.49 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
const core = require('@actions/core');
const SplitFactory = require('@splitsoftware/splitio').SplitFactory;
const checkInputParam = function (param, errMsg) {
if (param == '') {
core.setFailed(errMsg);
throw errMsg;
}
};
try {
const apiKey = core.getInput('api-key');
checkInputParam(apiKey, 'API Key is required');
core.debug('api-key: ' + apiKey.substring(0, 5) + '...');
const key = core.getInput('key');
checkInputParam(key, 'User/Evaluation key is required');
core.debug('key: ' + key);
const splits = core.getMultilineInput('splits');
core.debug('Splits: ' + splits);
var factory;
if (apiKey == 'localhost') {
factory = SplitFactory({
core: {
authorizationKey: apiKey,
},
features: '.github/splitio/.split',
});
} else {
factory = SplitFactory({
core: {
authorizationKey: apiKey,
},
});
}
var client = factory.client();
client.on(client.Event.SDK_READY, async function () {
var result = client.getTreatments(key, splits);
for (const splitName in result) {
if (Object.hasOwnProperty.call(result, splitName)) {
const treatment = result[splitName];
// Export env var
core.exportVariable(splitName, treatment);
}
}
// Set the step output
//core.setOutput('result', JSON.stringify(result));
core.setOutput('result', result);
await client.destroy(); // flush the impressions
client = null;
});
} catch (error) {
core.setFailed(error.message);
}