Skip to content

Commit

Permalink
Changes parameter and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Gomes committed Jun 29, 2020
1 parent a04ff8b commit ff22650
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
42 changes: 20 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
# GitHub Action to Sync S3 Bucket 🔄
# GitHub Action to delete files from S3 Bucket 🔄

This simple action uses the [vanilla AWS CLI](https://docs.aws.amazon.com/cli/index.html) to sync a directory (either from your repository or generated during your workflow) with a remote S3 bucket.
Fork of [s3-sync-action](https://github.com/jakejarvis/s3-sync-action).

This simple action uses the [vanilla AWS CLI](https://docs.aws.amazon.com/cli/index.html) to delete files from a S3 bucket.

## Usage

### `workflow.yml` Example

Place in a `.yml` file such as this one in your `.github/workflows` folder. [Refer to the documentation on workflow YAML syntax here.](https://help.github.com/en/articles/workflow-syntax-for-github-actions)

As of v0.3.0, all [`aws s3 sync` flags](https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html) are optional to allow for maximum customizability (that's a word, I promise) and must be provided by you via `args:`.
All [`aws s3 sync` flags](https://docs.aws.amazon.com/cli/latest/reference/s3/rm.html) are optional to allow for maximum customizability (that's a word, I promise) and must be provided by you via `args:`.

#### The following example includes optimal defaults for a public static website:
#### The following example includes a parameter to delete all files inside a folder:

- `--acl public-read` makes your files publicly readable (make sure your [bucket settings are also set to public](https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html)).
- `--follow-symlinks` won't hurt and fixes some weird symbolic link problems that may come up.
- Most importantly, `--delete` **permanently deletes** files in the S3 bucket that are **not** present in the latest version of your repository/build.
- **Optional tip:** If you're uploading the root of your repository, adding `--exclude '.git/*'` prevents your `.git` folder from syncing, which would expose your source code history if your project is closed-source. (To exclude more than one pattern, you must have one `--exclude` flag per exclusion. The single quotes are also important!)
- `--recursive` will delete recursively, removing folders and files inside those folders.

```yaml
name: Upload Website
name: Delete branch folder

on:
push:
delete:
branches:
- master

- '*'
- '!master'
jobs:
deploy:
remove:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- uses: jakejarvis/s3-sync-action@master
- name: Remove from S3
uses: vitorsgomes/s3-rm-action@master
with:
args: --acl public-read --follow-symlinks --delete
args: --recursive
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_S3_BUCKET: ${{ secrets.AWS_BUCKET_NAME }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
SOURCE_DIR: 'public' # optional: defaults to entire repository
AWS_REGION: ${{ secrets.AWS_REGION }}
PATH_TO_DELETE: ${{ github.event.ref }}
```
Expand All @@ -51,11 +50,10 @@ The following settings must be passed as environment variables as shown in the e
| ------------- | ------------- | ------------- | ------------- | ------------- |
| `AWS_ACCESS_KEY_ID` | Your AWS Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) | `secret env` | **Yes** | N/A |
| `AWS_SECRET_ACCESS_KEY` | Your AWS Secret Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) | `secret env` | **Yes** | N/A |
| `AWS_S3_BUCKET` | The name of the bucket you're syncing to. For example, `jarv.is` or `my-app-releases`. | `secret env` | **Yes** | N/A |
| `AWS_S3_BUCKET` | The name of the bucket you're removing something. For example, `jarv.is` or `my-app-releases`. | `secret env` | **Yes** | N/A |
| `AWS_REGION` | The region where you created your bucket. Set to `us-east-1` by default. [Full list of regions here.](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) | `env` | No | `us-east-1` |
| `AWS_S3_ENDPOINT` | The endpoint URL of the bucket you're syncing to. Can be used for [VPC scenarios](https://aws.amazon.com/blogs/aws/new-vpc-endpoint-for-amazon-s3/) or for non-AWS services using the S3 API, like [DigitalOcean Spaces](https://www.digitalocean.com/community/tools/adapting-an-existing-aws-s3-application-to-digitalocean-spaces). | `env` | No | Automatic (`s3.amazonaws.com` or AWS's region-specific equivalent) |
| `SOURCE_DIR` | The local directory (or file) you wish to sync/upload to S3. For example, `public`. Defaults to your entire repository. | `env` | No | `./` (root of cloned repository) |
| `DEST_DIR` | The directory inside of the S3 bucket you wish to sync/upload to. For example, `my_project/assets`. Defaults to the root of the bucket. | `env` | No | `/` (root of bucket) |
| `PATH_TO_DELETE` | The path to the file or directory inside of the S3 bucket you wish to remove. For example, `my_project/assets`. Defaults to the root of the bucket. | `env` | No | `/` (root of bucket) |


## License
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ EOF

# Sync using our dedicated profile and suppress verbose messages.
# All other flags are optional via the `args:` directive.
sh -c "aws s3 rm s3://${AWS_S3_BUCKET}/${DEST_DIR}/ \
sh -c "aws s3 rm s3://${AWS_S3_BUCKET}/${PATH_TO_DELETE}/ \
--profile s3-rm-action \
${ENDPOINT_APPEND} $*"

Expand Down

0 comments on commit ff22650

Please sign in to comment.