Skip to content

Commit

Permalink
Merge pull request #7 from nionata/master
Browse files Browse the repository at this point in the history
Upload to a specific directory
  • Loading branch information
shallwefootball authored Jun 24, 2020
2 parents 9bf85ee + fc4e274 commit 7ca30b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ jobs:
The following settings must be passed as environment variables as shown in the example. Sensitive information, especially `aws_key_id` and `aws_secret_access_key`, should be [set as encrypted secrets](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) — otherwise, they'll be public to anyone browsing your repository's source code

| name | description |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `aws_key_id` | (Required) Your AWS Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) |
| name | description |
| ----------------------- | ------------------------------------------------------------ |
| `aws_key_id` | (Required) Your AWS Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) |
| `aws_secret_access_key` | (Required) Your AWS Secret Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) |
| `aws_bucket` | (Required) The name of the bucket you're upload to. |
| `source_dir` | (Required) The local directory (or file) you wish to upload to S3. |
| `aws_bucket` | (Required) The name of the bucket you're upload to. |
| `source_dir` | (Required) The local directory (or file) you wish to upload to S3. |
| `destination_dir` | (Optional) The destination directory in S3<br />If this field is excluded a [shortid](https://github.com/dylang/shortid) will be generated |

> To upload to the root directory, set `destination_dir` to ""

## Action outputs

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
source_dir:
required: true
description: 'directory to upload'
destination_dir:
required: false
description: 'destination directory for upload'
outputs:
object_key:
description: 'object key'
Expand Down
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2414,12 +2414,15 @@ const BUCKET = core.getInput('aws_bucket', {
const SOURCE_DIR = core.getInput('source_dir', {
required: true
});
const DESTINATION_DIR = core.getInput('destination_dir', {
required: false
})

const s3 = new S3({
accessKeyId: AWS_KEY_ID,
secretAccessKey: SECRET_ACCESS_KEY
});
const objKey = shortid();
const objKey = DESTINATION_DIR !== undefined ? DESTINATION_DIR : `${shortid()}/`;
const paths = klawSync(SOURCE_DIR, {
nodir: true
});
Expand All @@ -2437,7 +2440,7 @@ function upload(params) {
function run() {
return Promise.all(
paths.map(p => {
const Key = p.path.replace(path.join(process.cwd(), SOURCE_DIR), objKey);
const Key = p.path.replace(path.join(process.cwd(), SOURCE_DIR, '/'), objKey);
const fileStream = fs.createReadStream(p.path);
const params = {
Bucket: BUCKET,
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ const BUCKET = core.getInput('aws_bucket', {
const SOURCE_DIR = core.getInput('source_dir', {
required: true
});
const DESTINATION_DIR = core.getInput('destination_dir', {
required: false
})

const s3 = new S3({
accessKeyId: AWS_KEY_ID,
secretAccessKey: SECRET_ACCESS_KEY
});
const objKey = shortid();
const objKey = DESTINATION_DIR !== undefined ? DESTINATION_DIR : `${shortid()}/`;
const paths = klawSync(SOURCE_DIR, {
nodir: true
});
Expand All @@ -41,7 +44,7 @@ function upload(params) {
function run() {
return Promise.all(
paths.map(p => {
const Key = p.path.replace(path.join(process.cwd(), SOURCE_DIR), objKey);
const Key = p.path.replace(path.join(process.cwd(), SOURCE_DIR, '/'), objKey);
const fileStream = fs.createReadStream(p.path);
const params = {
Bucket: BUCKET,
Expand Down

0 comments on commit 7ca30b1

Please sign in to comment.