-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-test.sh
More file actions
executable file
·92 lines (77 loc) · 3.03 KB
/
Copy pathdeploy-test.sh
File metadata and controls
executable file
·92 lines (77 loc) · 3.03 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
MAIN_TARGET="main"
# Function to build and deploy a test page for the Stargate Web Client example
# $1: prefix - the prefix for the deployment, "stargate/v1/$MAIN_TARGET"
# $2: version - the version of the deployment (branch name or npm version)
# $3: deploying_branch - 1 if we are deploying a branch, 0 if we are deploying a version
build_and_deploy() {
prefix=$1
version=$2
deploying_branch=$3
echo "Building Stargate Web Client example version $version with prefix $prefix"
vite build --base=$prefix/$version/
if [ $? -ne 0 ]; then
echo "Build failed."
exit 1
fi
if [ -z "$APPBUILDER_BUCKET" ]; then
echo "APPBUILDER_BUCKET environment variable is not set."
exit 1
fi
cachecontrol="public, max-age=31536000, immutable"
# if we are deploying a branch, we need to change the cache control, compared to a version
if [ $deploying_branch -eq 1 ]; then
cachecontrol="public, max-age=0, s-maxage=86400"
fi
echo "Deploying to version $version with prefix $prefix to bucket $APPBUILDER_BUCKET"
# depending on the prefix, we need to deploy to different locations
if [ $prefix == "stargate/v1/$MAIN_TARGET" ]; then
aws s3 sync ./dist s3://$APPBUILDER_BUCKET/appbuilder/$prefix/$version/ --region us-east-1 --cache-control "$cachecontrol"
touch empty
aws s3 cp empty s3://$APPBUILDER_BUCKET/appbuilder/$prefix/$version --region us-east-1 \
--website-redirect https://appbuilder.shapediver.com/$prefix/$version/ --cache-control "$cachecontrol"
aws s3 cp empty s3://$APPBUILDER_BUCKET/appbuilder/$prefix/.invalidate --region us-east-1 \
--cache-control "$cachecontrol"
rm empty
else
echo "Unsupported prefix for deployment."
exit 1
fi
}
# load environment variables from .env file
if [ -f .env ]; then
export $(grep -v '^#' .env | sed 's/#.*//' | sed 's/^ *//;s/ *$//' | xargs)
fi
# where should we deploy?
prefix=$1
if [ -z "$prefix" ]; then
echo "Please specify a prefix."
exit 1
fi
# check for git changes
if [[ -n $(git status --porcelain) ]]; then
echo "There are uncommitted changes."
exit 1
fi
# Get the current branch
branch=$(git rev-parse --abbrev-ref HEAD)
# npm version
npm_version=$(node -p "require('./package.json').version")
echo "Current npm version: $npm_version"
deploying_branch=1
# If the branch is "development", "staging" or starts with "task/", we use the branch name as the version
if [ "$branch" == "development" ] || [ "$branch" == "staging" ]; then
deploying_branch=1
version=$branch
# And we create a new tag with the name "WordPressPlugin@branch"
git tag -fa "StargateWebClient@$branch" -m "Release of branch $branch"
git push origin "StargateWebClient@$branch" --force
elif [[ $branch == task/* ]]; then
deploying_branch=1
# In this case we have to remove the "task/" prefix
version=${branch#task/}
else
echo "Unsupported branch name."
exit 1
fi
build_and_deploy $prefix $version $deploying_branch