-
Notifications
You must be signed in to change notification settings - Fork 821
Expand file tree
/
Copy pathshared-scripts-windows.sh
More file actions
131 lines (119 loc) · 4.08 KB
/
Copy pathshared-scripts-windows.sh
File metadata and controls
131 lines (119 loc) · 4.08 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# set exit on error to true
set -e
# The flags address the issue here: https://github.com/boto/botocore/issues/1716
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL="*"
# We have custom caching for our CodeBuild pipelines
# which allows us to share caches with jobs in the same batch
# storeCache <local path> <cache location>
function storeCache {
localPath="$1"
alias="$2"
s3Path="s3://$CACHE_BUCKET_NAME/$CODEBUILD_SOURCE_VERSION/$alias"
echo writing cache to $s3Path
# zip contents and upload to s3
if ! (cd $localPath && tar cz . | aws s3 cp - $s3Path); then
echo Something went wrong storing the cache.
fi
echo done writing cache
cd $CODEBUILD_SRC_DIR
}
function storeCacheFile {
localFilePath="$1"
alias="$2"
s3Path="s3://$CACHE_BUCKET_NAME/$CODEBUILD_SOURCE_VERSION/$alias"
echo writing cache to $s3Path
# zip contents and upload to s3
if ! (aws s3 cp $localFilePath $s3Path); then
echo Something went wrong storing the cache.
fi
echo done writing cache
cd $CODEBUILD_SRC_DIR
}
# loadCache <cache location> <local path>
function loadCache {
alias="$1"
localPath="$2"
s3Path="s3://$CACHE_BUCKET_NAME/$CODEBUILD_SOURCE_VERSION/$alias"
echo loading cache from $s3Path
# create directory if it doesn't exist yet
mkdir -p $localPath
# check if cache exists in s3
if ! aws s3 ls $s3Path > /dev/null; then
echo "Cache not found."
exit 0
fi
# tar --help
# load cache and unzip it
# if ! (cd $localPath && aws s3 cp $s3Path cache.tar && ls && tar -xzkf cache.tar); then
# echo "Something went wrong fetching the cache. Continuing anyway."
# fi
if ! (cd $localPath && aws s3 cp $s3Path - | tar xzkf -); then
echo "Something went wrong fetching the cache. Continuing anyway."
fi
echo done loading cache
cd $CODEBUILD_SRC_DIR
}
function loadCacheFile {
alias="$1"
localFilePath="$2"
s3Path="s3://$CACHE_BUCKET_NAME/$CODEBUILD_SOURCE_VERSION/$alias"
echo loading cache file from $s3Path
# check if cache file exists in s3
if ! aws s3 ls $s3Path > /dev/null; then
echo "Cache file not found."
exit 0
fi
# load cache file
if ! (aws s3 cp $s3Path $localFilePath); then
echo "Something went wrong fetching the cache file. Continuing anyway."
fi
echo done loading cache
cd $CODEBUILD_SRC_DIR
}
function _loadTestAccountCredentials {
echo ASSUMING PARENT TEST ACCOUNT credentials
session_id=$((1 + $RANDOM % 10000))
creds=$(aws sts assume-role --role-arn $TEST_ACCOUNT_ROLE --role-session-name testSession${session_id} --duration-seconds 3600)
if [ -z $(echo $creds | jq -c -r '.AssumedRoleUser.Arn') ]; then
echo "Unable to assume parent e2e account role."
return
fi
echo "Using account credentials for $(echo $creds | jq -c -r '.AssumedRoleUser.Arn')"
export AWS_ACCESS_KEY_ID=$(echo $creds | jq -c -r ".Credentials.AccessKeyId")
export AWS_SECRET_ACCESS_KEY=$(echo $creds | jq -c -r ".Credentials.SecretAccessKey")
export AWS_SESSION_TOKEN=$(echo $creds | jq -c -r ".Credentials.SessionToken")
}
function _lsOut {
ls ..
ls ~
}
function _build {
echo Windows Build
yarn run production-build
yarn build-tests
}
function _saveBuild {
_lsOut
storeCache $CODEBUILD_SRC_DIR repo-windows
}
function _install_packaged_cli_win {
echo Install Amplify Packaged CLI to PATH
# rename the command to amplify
cd $CODEBUILD_SRC_DIR/out
cp amplify-pkg-win-x64.exe amplify.exe
echo Move to CLI Binary to already existing PATH
# This is a Hack to make sure the Amplify CLI is in the PATH
cp $CODEBUILD_SRC_DIR/out/amplify.exe C:/Users/ContainerAdministrator/AppData/Local/Microsoft/WindowsApps
ls C:/Users/ContainerAdministrator/AppData/Local/Microsoft/WindowsApps
# reset working directory
cd $CODEBUILD_SRC_DIR
}
function _scanArtifacts {
if ! yarn ts-node .circleci/scan_artifacts_codebuild.ts; then
echo "Cleaning the repository"
git clean -fdx
exit 1
fi
}