diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f07d394 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +indent_style = space + +[*.{js,jsx,ts,tsx,py,sh,md,gql,graphql,yaml,yml,json,sql,njk,scss,css}] +indent_style = space +indent_size = 2 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3120f66 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# Container image that runs your code +FROM amazon/aws-cli:2.23.8 + +# Copies your code file from your action repository to the filesystem path `/` of the container +COPY entrypoint.sh /entrypoint.sh + +# Code file to execute when the docker container starts up (`entrypoint.sh`) +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 74213f8..7b1f6a6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,51 @@ -# aws-cli-action +# AWS Command Line Interface GitHub Action +## References + +* https://github.com/jakejarvis/s3-sync-action +* https://github.com/keithweaver/aws-s3-github-action + +## Creating new releases + +``` +git add -A; +git commit -m "" +git tag -a -m "" v1.3 +git push --follow-tags +``` + +## Description + +This GitHub Action uses the latest version of the AWS CLI in a Docker container to provide an environment to execute AWS CLI commands. It's designed to enable seamless interaction with AWS services, making it easier to manage AWS resources, deploy applications, and automate workflows directly from your GitHub workflows. + +## Usage + +You can use this action in your GitHub workflows by including it as a step in your workflow file. Below is an example of how to use this action to run a simple AWS CLI command: + +```yaml +name: Example S3 Copy Command +run-name: example-s3-copy-command + +on: + pull_request: + branches: [ main ] + + push: + branches: [ main ] + +jobs: + aws_cli_: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: AWS CLI Command + uses: sahil87/aws-cli-action@v1.3 + #OR sahil87/aws-cli-action@main + with: + args: > + s3 cp \ + --recursive \ + ${{ env.cp_source }} ${{ env.cp_destination }} diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..0d643b3 --- /dev/null +++ b/action.yaml @@ -0,0 +1,21 @@ +name: 'AWS Command Line Interface' +description: 'GitHub Action with the latest AWS CLI in Docker, enabling execution of AWS CLI commands.' +branding: + icon: "terminal" + color: 'orange' + +# inputs: +# aws_default_region: +# description: 'AWS Default Region' +# required: true +# aws_acces_key_id: +# description: 'AWS Access Key ID' +# required: true +# aws_secret_access_key: +# description: 'AWS Secret Access Key' +# required: true + +runs: + using: 'docker' + image: Dockerfile + # image: 'docker://amazon/aws-cli:2.23.8' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..b5dd4c1 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +set -e + +if [ -z "$AWS_ACCESS_KEY_ID" ]; then + echo "AWS_ACCESS_KEY_ID is not set. Quitting." + exit 1 +fi + +if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then + echo "AWS_SECRET_ACCESS_KEY is not set. Quitting." + exit 1 +fi + +# Default to us-east-1 if AWS_DEFAULT_REGION not set. +if [ -z "$AWS_DEFAULT_REGION" ]; then + AWS_DEFAULT_REGION="us-east-1" +fi + +# Create a dedicated profile for this action to avoid conflicts +# with past/future actions. +# https://github.com/jakejarvis/s3-sync-action/issues/1 +aws configure --profile s3-sync-action <<-EOF > /dev/null 2>&1 +${AWS_ACCESS_KEY_ID} +${AWS_SECRET_ACCESS_KEY} +${AWS_DEFAULT_REGION} +text +EOF + +echo "aws $*" +sh -c "aws $*" + +# Clear out credentials after we're done. +# We need to re-run `aws configure` with bogus input instead of +# deleting ~/.aws in case there are other credentials living there. +# https://forums.aws.amazon.com/thread.jspa?threadID=148833 +aws configure --profile s3-sync-action <<-EOF > /dev/null 2>&1 +null +null +null +text +EOF