Skip to content

Commit

Permalink
added logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeressian committed Jun 26, 2020
1 parent ef0a7d3 commit b9560c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uploader from './uploader';
import { getInput, setFailed } from '@actions/core';
import { getInput, setFailed, info } from '@actions/core';
import { join } from 'path';
import { Utils } from '@technote-space/github-action-helper';

Expand All @@ -8,6 +8,7 @@ async function run() {
const source = join(Utils.getWorkspace(), getInput('source'));
const storageZoneName = getInput('storageZoneName');
const accessKey = getInput('accessKey');
info(`Deploying ${source}`);
await uploader(source, storageZoneName, accessKey);
} catch (error) {
setFailed(error.message);
Expand Down
8 changes: 7 additions & 1 deletion src/uploader.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import fs from 'fs';
import fetch from 'node-fetch';
import readdirp from 'readdirp';
import { info } from '@actions/core';

function uploadFile(entry: readdirp.EntryInfo, storageName: string, accessKey: string) {
const stats = fs.statSync(entry.fullPath);
const fileSizeInBytes = stats.size;

let readStream = fs.createReadStream(entry.fullPath);
console.log(entry);
info(`Deploying ${entry.path}`);
return fetch(`https://storage.bunnycdn.com/${storageName}/${entry.path}`, {
method: 'POST',
headers: {
"AccessKey": accessKey,
"Content-length": fileSizeInBytes.toString()
},
body: readStream
}).then(response => {
if (response.status === 200) {
info(`Successfull deployment of ${entry.path}`);
}
return response;
});
}

Expand Down

0 comments on commit b9560c2

Please sign in to comment.