Skip to content

Commit

Permalink
Check first for existing branches (see #12 for starting point)
Browse files Browse the repository at this point in the history
  • Loading branch information
wrandall22 committed Apr 25, 2024
1 parent 824ad2d commit 60dddf8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ EOF
case $AMPLIFY_COMMAND in

deploy)
sh -c "aws amplify create-branch --app-id=${AmplifyAppId} --branch-name=$BRANCH_NAME \
${backend_env_arg} ${environment_variables_arg} --region=${AWS_REGION}"
echo "deploying"
branch_exists=$(sh -c "aws amplify get-branch --app-id=${AmplifyAppId} --branch-name=$BRANCH_NAME --region=${AWS_REGION}")

sleep 10
if [[ -z "$branch_exists" ]]; then
echo "branch_exists is empty"
sh -c "aws amplify create-branch --app-id=${AmplifyAppId} --branch-name=$BRANCH_NAME \
${backend_env_arg} ${environment_variables_arg} --region=${AWS_REGION}"

sleep 10
fi
echo "starting job"

sh -c "aws amplify start-job --app-id=${AmplifyAppId} --branch-name=$BRANCH_NAME --job-type=RELEASE --region=${AWS_REGION}"
;;
Expand All @@ -80,7 +87,7 @@ EOF

if [ -z "$GITHUB_TOKEN" ] ; then
echo "Skipping comment as GITHUB_TOKEN not provided"
else
else
SUBDOMAIN_NAME=$(echo $BRANCH_NAME | sed 's/[^a-zA-Z0-9-]/-/')
curl -X POST $COMMENT_URL -H "Content-Type: application/json" -H "Authorization: token $GITHUB_TOKEN" --data '{ "body": "'"Preview branch generated at https://$SUBDOMAIN_NAME.${AmplifyAppId}.amplifyapp.com"'" }'
fi

0 comments on commit 60dddf8

Please sign in to comment.