From c1bef10b7b3bd8fece5bc1e9f3a4ba0fcc8a0d6d Mon Sep 17 00:00:00 2001 From: Yinlin Chen Date: Thu, 10 Sep 2020 12:38:01 -0400 Subject: [PATCH] add amplify commands --- README.md | 4 ++-- action.yml | 9 +++++---- entrypoint.sh | 26 +++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8bc5b002..7043473f 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,10 @@ jobs: echo "##[set-output name=setbranchname;]$(echo ${GITHUB_HEAD_REF//[-_]/} | cut -c-10)" - name: deploy PR preview - uses: yinlinchen/amplify-preview-actions@0.1 + uses: yinlinchen/amplify-preview-actions@0.2 with: branch_name: ${{ steps.setenvname.outputs.setbranchname }} - aws_cli_version: '1.18.135' + amplify_command: deploy env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/action.yml b/action.yml index c8aa2bdd..9f821e3f 100644 --- a/action.yml +++ b/action.yml @@ -4,15 +4,16 @@ inputs: branch_name: description: 'GitHub branch name to deploy' required: true - aws_cli_version: - description: 'version of AWS Cli to use' - required: false + amplify_command: + description: 'amplify command: SUPPORTED: [deploy, delete]' + required: true + runs: using: 'docker' image: 'Dockerfile' args: - ${{ inputs.branch_name }} - - ${{ inputs.aws_cli_version }} + - ${{ inputs.amplify_command }} branding: icon: 'git-commit' color: 'blue' diff --git a/entrypoint.sh b/entrypoint.sh index 47ba9174..71e2d8d8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,6 +26,11 @@ if [ -z "$1" ] ; then exit 1 fi +if [ -z "$2" ] ; then + echo "You must provide amplify_command input parameter in order to deploy" + exit 1 +fi + aws configure --profile amplify-preview-actions <<-EOF > /dev/null 2>&1 ${AWS_ACCESS_KEY_ID} ${AWS_SECRET_ACCESS_KEY} @@ -33,12 +38,27 @@ ${AWS_REGION} text EOF -sh -c "aws amplify create-branch --app-id=${AmplifyAppId} --branch-name=$1 \ +case $2 in + + deploy) + sh -c "aws amplify create-branch --app-id=${AmplifyAppId} --branch-name=$1 \ --backend-environment-arn=${BackendEnvARN} --region=${AWS_REGION}" -sleep 10 + sleep 10 + + sh -c "aws amplify start-job --app-id=${AmplifyAppId} --branch-name=$1 --job-type=RELEASE --region=${AWS_REGION}" + ;; + + delete) + sh -c "aws amplify delete-branch --app-id=${AmplifyAppId} --branch-name=$1 --region=${AWS_REGION}" + ;; + + *) + echo "amplify command $2 is invalid or not supported" + exit 1 + ;; -sh -c "aws amplify start-job --app-id=${AmplifyAppId} --branch-name=$1 --job-type=RELEASE --region=${AWS_REGION}" +esac aws configure --profile amplify-preview-actions <<-EOF > /dev/null 2>&1 null