Skip to content

Commit

Permalink
feat: add aws-setup and aws-s3-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Feb 24, 2023
1 parent 2b302b3 commit 54133b7
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ This is a collection of reusable composite actions for GitHub Actions workflows.
- [Actions](#actions)
- [Authentication](#authentication)
- [setup-app-credentials](#setup-app-credentials)
- [AWS](#aws)
- [aws-setup](#aws-setup)
- [aws-s3-sync](#aws-s3-sync)
- [Node](#node)
- [npm-install](#npm-install)
- [setup-node](#setup-node)
Expand Down Expand Up @@ -107,6 +110,62 @@ Generate credentials and git committer details for a [GitHub app].

See also [setup-git-credentials] for setting up git using a [GitHub app].

### AWS

#### aws-setup

[Source](aws-setup/action.yml)

Setup AWS credentials for use with other AWS actions.

##### Example

```yaml
- uses: myparcelnl/actions/aws-setup@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
```

##### Inputs

| Required | Name | Description | Example | Default |
|----------|-------------------------|----------------------------|----------------------------------------|---------|
| Yes | `aws-access-key-id` | The AWS access key ID. | `${{ secrets.AWS_ACCESS_KEY_ID }}` ||
| Yes | `aws-secret-access-key` | The AWS secret access key. | `${{ secrets.AWS_SECRET_ACCESS_KEY }}` ||
| Yes | `aws-region` | The AWS region. | `eu-west-1` ||

#### aws-s3-sync

[Source](aws-s3-sync/action.yml)

Sync a directory to an S3 bucket. Must be run after [aws-setup].

##### Example

```yaml
- uses: myparcelnl/actions/aws-setup@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1

- uses: myparcelnl/actions/aws-s3-sync@v3
with:
source: dist
bucket: my-bucket
delete: true
```

##### Inputs

| Required | Name | Description | Example | Default |
|----------|----------|-------------------------------------------------------------------------------|-----------------------------|---------|
| Yes | `source` | The directory to sync. | `dist` ||
| Yes | `bucket` | Name of the S3 bucket to sync to. | `${{ secrets.AWS_BUCKET }}` ||
| No | `delete` | Delete files that exist in the destination but not in the source during sync. | `true` | `false` |

### Node

#### npm-install
Expand Down
37 changes: 37 additions & 0 deletions aws-s3-sync/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Sync files to S3'
description: 'Sync files to S3 and invalidate CloudFront'

inputs:
source:
description: 'Path to the folder to sync.'
required: true

bucket:
description: 'Name of the S3 bucket to sync to.'
required: true

delete:
description: 'Delete files that exist in the destination but not in the source during sync.'
required: false

distribution-id:
description: 'The CloudFront distribution id. If provided, the distribution will be invalidated after the sync.'
required: false

runs:
using: composite
steps:
- name: 'Sync files'
shell: bash
run: |
aws s3 sync "${{ inputs.source }}" \
"s3://${{ inputs.bucket }}" \
${{ inputs.delete && '--delete' }}
- name: 'Invalidate CloudFront'
if: inputs.distribution-id != ''
shell: bash
run: |
aws cloudfront create-invalidation \
--distribution-id ${{ inputs.distribution-id }} \
--paths "/*"
32 changes: 32 additions & 0 deletions aws-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'Setup AWS CLI'

description: 'Install and configure the AWS CLI'

inputs:
region:
description: 'The default region'
required: true

access-key-id:
description: 'The access key id'
required: true

secret-access-key:
description: 'The secret access key'
required: true

runs:
using: composite
steps:
- name: 'Install aws cli'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y awscli
- name: 'Configure aws cli'
shell: bash
run: |
aws configure set default.region ${{ inputs.region }}
aws configure set aws_access_key_id ${{ inputs.access-key-id }}
aws configure set aws_secret_access_key ${{ inputs.secret-access-key }}

0 comments on commit 54133b7

Please sign in to comment.