forked from pukonu/action-deploy-webapp-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
63 lines (47 loc) · 1.27 KB
/
script.sh
File metadata and controls
63 lines (47 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash -l
set -e
# check configuration
err=0
build_path=$1
bucket_name=$2
bucket_key=$3
distribution_invalidation_path=$4
aws_region=AWS_REGION
ls -l $build_path
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
echo "AWS_ACCESS_KEY_ID was not found. Set this in your github secrets"
err=1
fi
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "AWS_SECRET_ACCESS_KEY was not found. Set this in your github secrets"
err=1
fi
if [ -z "$aws_region" ]; then
echo "Specify an AWS region"
err=1
fi
if [ -z "$bucket_name" ]; then
echo "Specify a bucket you will like to deploy to"
err=1
fi
if [ $err -eq 1 ]; then
exit 1
fi
output="AWS OUTPUT"
echo "::set-output name=aws-deploy-output::$output"
# Only add the "/" if a buket_key is defined
case "$bucket_key" in
"") formatted_bucket_key="" ;;
*) formatted_bucket_key="/$bucket_key" ;;
esac
aws s3 cp $build_path s3://$bucket_name$formatted_bucket_key --recursive
if [ -z "$DISTRIBUTION_ID" ]; then
echo "Skipping cloudfront invalidation..."
else
if [ -z "$distribution_invalidation_path" ]; then
echo "Specify the invalidation path. e.g. /* or /production/*"
exit 1
fi
echo "Invalidating cloudfront..."
aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths "$distribution_invalidation_path"
fi