generated from actions/javascript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
45 lines (38 loc) · 1.18 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
const core = require('@actions/core');
const isGlob = require('is-glob');
const glob = require('glob');
const uploader = require('./uploader')
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
async function run() {
try {
const cloudName = core.getInput('cloud-name') || process.env.CLOUDINARY_CLOUD_NAME;
const apiKey = core.getInput('api-key') || process.env.CLOUDINARY_API_KEY;
const apiSecret = core.getInput('api-secret') || process.env.CLOUDINARY_API_SECRET;
const imagePath = core.getInput('image');
const imagesPath = core.getInput('images');
if (!cloudName || !apiKey || !apiSecret) {
throw new Error('Cloudinary cloud name, api key and api secret are required');
}
let paths = [];
if (isJson(imagesPath)) {
paths = JSON.parse(imagesPath);
} else if (isGlob(imagesPath)) {
paths = glob.sync(imagesPath);
} else if (imagePath) {
paths = [imagePath];
} else {
throw new Error('one of image or images parameter is required');
}
await uploader(cloudName, apiKey, apiSecret, paths);
} catch (error) {
core.setFailed(error.message);
}
}
run();