-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yaml
50 lines (45 loc) · 3.15 KB
/
buildspec.yaml
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
version: 0.2 # this is the version for the buildspec parser, not the file version
env:
git-credential-helper: yes
phases:
install:
runtime-versions:
nodejs: 12
python: 3.7 # pre-commit hooks often use Python, so make sure to pin python version
commands:
- node --version
- npm --version
- python --version
- echo "Git Branch information:"
- git branch -av
- SHA_OF_REMOTE_MASTER=$(git branch -av | grep remotes/origin/master | grep -oP "master\s+\K\w+")
- SHA_OF_REMOTE_DEVELOPMENT=$(git branch -av | grep remotes/origin/development | grep -oP "development\s+\K\w+")
# In CodeBuild, sometimes a direct SHA is grabbed rather than a branch, so the 'name' of the branch is listed as: (no branch)
# So can't use traditional grep to just check that the name of the current branch is 'master', have to explicitly check the SHAs
- SHA_OF_LOCAL_COMMIT=$(git branch -av | grep "*" | grep -oP " \s+\K\w+")
- echo "Creating virtual environment for Python" # sometimes pre-commit can have odd issues when not in venv (Eli 4/6/20)
- python -m venv venv
- echo "Entering virtual environment"
- . venv/bin/activate
- pip freeze
- pip install pip==20.0.2 --upgrade # Eli (4/3/20) no known specific reason for this version, just pinning the version for consistency
- pip install pre-commit==2.2.0 # Eli (12/10/19) no known specific reason for this version, just pinning the version for consistency
- pip freeze
- pre-commit install # Install pre-commit hooks
- echo "Installing npm packages directly from package-lock.json. The prepare script also installs pre-commit hooks"
- npm ci
pre_build:
commands:
- echo "Running pre-commit hooks on all the files to ensure code quality was maintained during commits"
- pre-commit run -a
build:
commands:
- echo "Build started on $(date)"
- echo "Generating static files for deployment"
- npm run build
- echo "Listing changes that would be made in deployment to S3"
- aws s3 sync --delete dist/ s3://staging-$DESTINATION_BUCKET_NAME --dryrun
# Only run the following command if the APPLY_TAG environmental variable is set (i.e. =1) https://stackoverflow.com/questions/39619956/short-way-to-run-command-if-variable-is-set (extra outer parentheses needed to make YAML parser happy)
# Colon (or maybe semi-colon) is causing issue with CodeBuild YAML parser, so needed to wrap whole command in single quote
- 'if [ "$DEPLOYMENT_STAGE" = "PRODUCTION" ] ; then if [ "$SHA_OF_LOCAL_COMMIT" = "$SHA_OF_REMOTE_MASTER" ] || [ "$SHA_OF_LOCAL_COMMIT" = "$SHA_OF_REMOTE_DEVELOPMENT" ]; then echo "Current branch matches SHA of remote master or development so deployment is allowed"; else echo "Current branch is not master or development--deployment to Production is NOT ALLOWED. SHA of current commit is $SHA_OF_LOCAL_COMMIT but SHA of remote master is $SHA_OF_REMOTE_MASTER and SHA of remote development is $SHA_OF_REMOTE_DEVELOPMENT" && exit 1; fi && echo "Deploying to S3" && aws s3 sync --delete dist/ s3://$DESTINATION_BUCKET_NAME ; fi'
- echo "Build completed on $(date)"