diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a102b78d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.8-alpine + +LABEL "com.github.actions.name"="AWS Amplify PR Previews for Public Repository" +LABEL "com.github.actions.description"="This action deploys your AWS Amplify pull request for your public repository" +LABEL "com.github.actions.icon"="git-commit" +LABEL "com.github.actions.color"="blue" + +LABEL version="0.2" +LABEL "repository"="https://github.com/yinlinchen/amplify-preview-actions.git" +LABEL "homepage"="https://github.com/yinlinchen/amplify-preview-actions" +LABEL maintainer="Yinlin Chen " + +ENV AWSCLI_VERSION='1.18.14' + +RUN pip install --quiet --no-cache-dir awscli==${AWSCLI_VERSION} + +ADD entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..ac5d4f92 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# amplify-preview-actions + diff --git a/action.yml b/action.yml new file mode 100644 index 00000000..c8aa2bdd --- /dev/null +++ b/action.yml @@ -0,0 +1,18 @@ +name: 'amplify-preview-actions' +description: 'This action builds and deploys your AWS Amplify pull request preview for public repository' +inputs: + branch_name: + description: 'GitHub branch name to deploy' + required: true + aws_cli_version: + description: 'version of AWS Cli to use' + required: false +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.branch_name }} + - ${{ inputs.aws_cli_version }} +branding: + icon: 'git-commit' + color: 'blue' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..47ba9174 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +set -e + +if [ -z "$AWS_ACCESS_KEY_ID" ] && [ -z "$AWS_SECRET_ACCESS_KEY" ] ; then + echo "You must provide the action with both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables in order to deploy" + exit 1 +fi + +if [ -z "$AWS_REGION" ] ; then + AWS_REGION="us-east-1" +fi + +if [ -z "$AmplifyAppId" ] ; then + echo "You must provide AmplifyAppId environment variable in order to deploy" + exit 1 +fi + +if [ -z "$BackendEnvARN" ] ; then + echo "You must provide BackendEnvARN environment variable in order to deploy" + exit 1 +fi + +if [ -z "$1" ] ; then + echo "You must provide branch name 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} +${AWS_REGION} +text +EOF + +sh -c "aws amplify create-branch --app-id=${AmplifyAppId} --branch-name=$1 \ + --backend-environment-arn=${BackendEnvARN} --region=${AWS_REGION}" + +sleep 10 + +sh -c "aws amplify start-job --app-id=${AmplifyAppId} --branch-name=$1 --job-type=RELEASE --region=${AWS_REGION}" + +aws configure --profile amplify-preview-actions <<-EOF > /dev/null 2>&1 +null +null +null +text +EOF \ No newline at end of file