From 0804865d6a1f039d59ce484e34899dc13d3585ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Costa?= Date: Tue, 17 Dec 2024 13:16:50 -0300 Subject: [PATCH 1/4] Add cp command --- commands/cp.sh | 24 ++++++++++++++++++++++++ entrypoint.sh | 6 ++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 commands/cp.sh diff --git a/commands/cp.sh b/commands/cp.sh new file mode 100755 index 0000000..cfd80e3 --- /dev/null +++ b/commands/cp.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +set -e + +if [ -z "$FILE" ]; then + echo "FILE is not set. Quitting." + exit 1 +fi + +if [ -z "$TARGET" ]; then + echo "FILE is not set. Quitting." + exit 1 +fi + +the_command="aws ${S3_PROFILE} ${ENDPOINT_APPEND} s3 cp s3://${S3_BUCKET}/${FILE} ${TARGET}" + +echo $the_command + +# Run the command. +output=$(sh -c "$the_command") + +echo $output + +echo "::set-output name=ls_output::${output}" diff --git a/entrypoint.sh b/entrypoint.sh index e22476b..560fe92 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -35,7 +35,7 @@ fi S3_PROFILE="--profile action-s3-utility" # Create a dedicated profile for this action -aws configure --profile action-s3-utility <<-EOF > /dev/null 2>&1 +aws configure --profile action-s3-utility <<-EOF >/dev/null 2>&1 ${S3_ACCESS_KEY_ID} ${S3_SECRET_ACCESS_KEY} ${S3_REGION} @@ -50,10 +50,12 @@ elif [[ "$COMMAND" == "exists" ]]; then . /commands/exists.sh elif [[ "$COMMAND" == "rm" ]]; then . /commands/rm.sh +elif [[ "$COMMAND" == "cp" ]]; then + . /commands/cp.sh fi # Clear out credentials after we're done. -aws configure --profile action-s3-utility <<-EOF > /dev/null 2>&1 +aws configure --profile action-s3-utility <<-EOF >/dev/null 2>&1 null null null From 750b94d3b289bd1db10269fed4b117b16611cc25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Costa?= Date: Tue, 17 Dec 2024 16:00:59 -0300 Subject: [PATCH 2/4] Update var name --- commands/cp.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/cp.sh b/commands/cp.sh index cfd80e3..9a79360 100755 --- a/commands/cp.sh +++ b/commands/cp.sh @@ -7,12 +7,12 @@ if [ -z "$FILE" ]; then exit 1 fi -if [ -z "$TARGET" ]; then - echo "FILE is not set. Quitting." +if [ -z "$DESTINATION" ]; then + echo "Destination is not set. Quitting." exit 1 fi -the_command="aws ${S3_PROFILE} ${ENDPOINT_APPEND} s3 cp s3://${S3_BUCKET}/${FILE} ${TARGET}" +the_command="aws ${S3_PROFILE} ${ENDPOINT_APPEND} s3 cp s3://${S3_BUCKET}/${FILE} ${DESTINATION}" echo $the_command From abfeec0e5094590badc7f9bcae97d9a8b59bce9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Costa?= Date: Tue, 17 Dec 2024 16:24:26 -0300 Subject: [PATCH 3/4] Add documentation --- README.md | 71 +++++++++++++++++++++++++++++++++++--------------- action.yml | 2 +- commands/cp.sh | 2 -- 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 6d61422..963297d 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,14 @@ of the commands provided by this GitHub Action. Sensitive information, especiall they'll be public to anyone browsing your repository's source code and CI logs. -| Key | Value | Suggested Type | Required | Default | -| ------------- | ------------- | ------------- | ------------- | ------------- | -| `COMMAND` | The action command (see below) you wish to execute | `env` | **Yes** | N/A | -| `S3_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 | -| `S3_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 | -| `S3_BUCKET` | The name of the bucket you're syncing to. For example, `jarv.is` or `my-app-releases`. | `secret env` | **Yes** | N/A | -| `S3_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` | -| `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) | - +| Key | Value | Suggested Type | Required | Default | +| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------- | ------------------------------------------------------------------ | +| `COMMAND` | The action command (see below) you wish to execute | `env` | **Yes** | N/A | +| `S3_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 | +| `S3_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 | +| `S3_BUCKET` | The name of the bucket you're syncing to. For example, `jarv.is` or `my-app-releases`. | `secret env` | **Yes** | N/A | +| `S3_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` | +| `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) | ## Commands @@ -47,9 +46,9 @@ You can add the following as a step in one of your workflows: Additional configuration for this command: -| Key | Value | Suggested Type | Required | Default | -| ------------- | ------------- | ------------- | ------------- | ------------- | -| `FILE` | The file you want to check for the existence of | `env` | No | `/` (root of bucket) | +| Key | Value | Suggested Type | Required | Default | +| ------ | ----------------------------------------------- | -------------- | -------- | ------- | +| `FILE` | The file you want to check for the existence of | `env` | Yes | N/A | ### `ls` @@ -76,9 +75,9 @@ You can add the following as a step in one of your workflows: Additional configuration for this command: -| Key | Value | Suggested Type | Required | Default | -| ------------- | ------------- | ------------- | ------------- | ------------- | -| `FILE` | The file you want to check for the existence of | `env` | No | `/` (root of bucket) | +| Key | Value | Suggested Type | Required | Default | +| ------ | ----------------------------------------------- | -------------- | -------- | ------- | +| `FILE` | The file you want to check for the existence of | `env` | Yes | N/A | ### `rm` @@ -105,9 +104,9 @@ You can add the following as a step in one of your workflows: Additional configuration for this command: -| Key | Value | Suggested Type | Required | Default | -| ------------- | ------------- | ------------- | ------------- | ------------- | -| `FILE` | The file you want to check for the existence of | `env` | No | `/` (root of bucket) | +| Key | Value | Suggested Type | Required | Default | +| ------ | ----------------------------------------------- | -------------- | -------- | ------- | +| `FILE` | The file you want to check for the existence of | `env` | Yes | N/A | ### `sync` @@ -134,6 +133,36 @@ You can add the following as a step in one of your workflows: Additional configuration for this command: -| Key | Value | Suggested Type | Required | Default | -| ------------- | ------------- | ------------- | ------------- | ------------- | -| `SOURCE_DIR` | The file or directory you wish to sync | `env` | No | `/` (root of bucket) | +| Key | Value | Suggested Type | Required | Default | +| ------------ | -------------------------------------- | -------------- | -------- | -------------------- | +| `SOURCE_DIR` | The file or directory you wish to sync | `env` | No | `/` (root of bucket) | + +### `cp` + +This command performs `aws s3 cp`. + +#### `workflow.yml` Step Example + +You can add the following as a step in one of your workflows: + +``` +- name: S3 cp + uses: the-events-calendar/action-s3-utility@main + env: + COMMAND: cp + S3_BUCKET: ${{ secrets.S3_BUCKET }} + S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} + S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.S3_REGION }} + S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} + FILE: 'some-file-name.txt' + DESTINATION: 'some-dir/some-file-name.txt' +``` + +#### Configuration + +Additional configuration for this command: + +| Key | Value | Suggested Type | Required | Default | +| ------------- | ---------------------------- | -------------- | -------- | ------- | +| `DESTINATION` | The destination file or dir. | `env` | Yes | N/A | diff --git a/action.yml b/action.yml index 3a2ef1f..bf05c9a 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: 'S3 Utility' -description: 'Execute various s3 (ls, sync, rm) and s3 helper commands (exists)' +description: 'Execute various s3 (ls, sync, rm, cp) and s3 helper commands (exists)' author: 'The Events Calendar (support@theeventscalendar.com)' branding: icon: file diff --git a/commands/cp.sh b/commands/cp.sh index 9a79360..4c9e588 100755 --- a/commands/cp.sh +++ b/commands/cp.sh @@ -20,5 +20,3 @@ echo $the_command output=$(sh -c "$the_command") echo $output - -echo "::set-output name=ls_output::${output}" From b70b1c8353b4ae50ed1be9b09210c92b498acc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Costa?= Date: Tue, 17 Dec 2024 16:27:32 -0300 Subject: [PATCH 4/4] Fix format --- README.md | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 963297d..e1975b6 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,14 @@ You can add the following as a step in one of your workflows: ``` - name: S3 exists uses: the-events-calendar/action-s3-utility@main - env: - COMMAND: exists - S3_BUCKET: ${{ secrets.S3_BUCKET }} - S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} - S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} - S3_REGION: ${{ secrets.S3_REGION }} - S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} - FILE: 'some-file-name.txt' + env: + COMMAND: exists + S3_BUCKET: ${{ secrets.S3_BUCKET }} + S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} + S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.S3_REGION }} + S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} + FILE: 'some-file-name.txt' ``` #### Configuration @@ -61,14 +61,14 @@ You can add the following as a step in one of your workflows: ``` - name: S3 ls uses: the-events-calendar/action-s3-utility@main - env: - COMMAND: ls - S3_BUCKET: ${{ secrets.S3_BUCKET }} - S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} - S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} - S3_REGION: ${{ secrets.S3_REGION }} - S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} - FILE: 'some-file-name.txt' + env: + COMMAND: ls + S3_BUCKET: ${{ secrets.S3_BUCKET }} + S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} + S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.S3_REGION }} + S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} + FILE: 'some-file-name.txt' ``` #### Configuration @@ -90,14 +90,14 @@ You can add the following as a step in one of your workflows: ``` - name: S3 rm uses: the-events-calendar/action-s3-utility@main - env: - COMMAND: rm - S3_BUCKET: ${{ secrets.S3_BUCKET }} - S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} - S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} - S3_REGION: ${{ secrets.S3_REGION }} - S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} - FILE: 'some-file-name.txt' + env: + COMMAND: rm + S3_BUCKET: ${{ secrets.S3_BUCKET }} + S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} + S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.S3_REGION }} + S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} + FILE: 'some-file-name.txt' ``` #### Configuration @@ -119,14 +119,14 @@ You can add the following as a step in one of your workflows: ``` - name: S3 sync uses: the-events-calendar/action-s3-utility@main - env: - COMMAND: sync - S3_BUCKET: ${{ secrets.S3_BUCKET }} - S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} - S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} - S3_REGION: ${{ secrets.S3_REGION }} - S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} - SOURCE_DIR: 'some-dir/' + env: + COMMAND: sync + S3_BUCKET: ${{ secrets.S3_BUCKET }} + S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} + S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.S3_REGION }} + S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} + SOURCE_DIR: 'some-dir/' ``` #### Configuration @@ -148,15 +148,15 @@ You can add the following as a step in one of your workflows: ``` - name: S3 cp uses: the-events-calendar/action-s3-utility@main - env: - COMMAND: cp - S3_BUCKET: ${{ secrets.S3_BUCKET }} - S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} - S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} - S3_REGION: ${{ secrets.S3_REGION }} - S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} - FILE: 'some-file-name.txt' - DESTINATION: 'some-dir/some-file-name.txt' + env: + COMMAND: cp + S3_BUCKET: ${{ secrets.S3_BUCKET }} + S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} + S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.S3_REGION }} + S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} + FILE: 'some-file-name.txt' + DESTINATION: 'some-dir/some-file-name.txt' ``` #### Configuration