-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
31 lines (26 loc) · 865 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
31
const core = require('@actions/core');
const fs = require('fs');
const path = require('path');
const AWS = require('aws-sdk');
const github = require('@actions/github');
try {
const inputBucket = core.getInput('bucket');
const inputPath = core.getInput('path');
const inputKey = core.getInput('key');
const key = path.join(
github.context.payload.repository.full_name,
github.context.sha,
inputKey,
);
const stream = fs.createReadStream(inputPath);
AWS.config.update({ region: process.env.AWS_REGION || 'us-east-1' });
s3 = new AWS.S3({ apiVersion: process.env.AWS_API_VERISON || '2006-03-01' });
s3.upload({ Bucket: inputBucket, Key: key, Body: stream }, (err, data) => {
if (err) {
throw err;
}
core.info(`Uploaded ${inputPath} to ${data.Location}`);
});
} catch (error) {
core.setFailed(error.message);
}