forked from randomairborne/r2-release
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
39 lines (35 loc) · 1.14 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
const S3 = require('aws-sdk/clients/s3');
const core = require('@actions/core');
const fs = require('fs');
const path = require('path');
try {
const endpoint = core.getInput('endpoint');
const accessKeyID = core.getInput('access_key_id');
const secretAccessKey = core.getInput('secret_access_key');
const bucket = core.getInput('bucket');
const file = core.getInput('file');
const destination = core.getInput('destination');
const s3 = new S3({
endpoint: endpoint,
accessKeyId: accessKeyID,
secretAccessKey: secretAccessKey,
signatureVersion: 'v4',
});
const fileContent = fs.readFileSync(file);
let uploadParams = {
Bucket: bucket,
Key: destination ? destination : path.basename(file),
Body: fileContent
};
// call S3 to retrieve upload file to specified bucket
s3.upload(uploadParams, function (err, data) {
if (err) {
console.log("Error", err);
core.setFailed(err);
} if (data) {
console.log("Upload Success", data.Location);
}
});
} catch (error) {
core.setFailed(error.message);
}