This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
buildspec-fullcycle.yml
89 lines (86 loc) · 4.59 KB
/
buildspec-fullcycle.yml
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
version: 0.2
phases:
install:
commands:
- pip install Pygments
- curl -sSL https://get.docker.com/ | sh
- service docker start
- export CI=true
- export CODEBUILD=true
- export CODEBUILD_ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output text)
- export CODEBUILD_GIT_BRANCH="$(git symbolic-ref HEAD --short 2>/dev/null)"
- if [ "$CODEBUILD_GIT_BRANCH" = "" ] ; then
CODEBUILD_GIT_BRANCH="$(git branch -a --contains HEAD | sed -n 2p | awk '{ printf $1 }')";
export CODEBUILD_GIT_BRANCH=${CODEBUILD_GIT_BRANCH#remotes/origin/};
fi
- export CODEBUILD_GIT_CLEAN_BRANCH="$(echo $CODEBUILD_GIT_BRANCH | tr '/' '.')"
- export CODEBUILD_GIT_ESCAPED_BRANCH="$(echo $CODEBUILD_GIT_CLEAN_BRANCH | sed -e 's/[]\/$*.^[]/\\\\&/g')"
- export CODEBUILD_GIT_MESSAGE="$(git log -1 --pretty=%B)"
- export CODEBUILD_GIT_AUTHOR="$(git log -1 --pretty=%an)"
- export CODEBUILD_GIT_AUTHOR_EMAIL="$(git log -1 --pretty=%ae)"
- export CODEBUILD_GIT_COMMIT="$(git log -1 --pretty=%H)"
- export CODEBUILD_GIT_SHORT_COMMIT=$(echo $CODEBUILD_SOURCE_VERSION | cut -c 1-7)
- export CODEBUILD_GIT_TAG="$(git describe --tags --exact-match 2>/dev/null)"
- export CODEBUILD_GIT_MOST_RECENT_TAG="$(git describe --tags --abbrev=0)"
- export CODEBUILD_PULL_REQUEST=false
- if [ "${CODEBUILD_GIT_BRANCH#pr-}" != "$CODEBUILD_GIT_BRANCH" ] ; then
export CODEBUILD_PULL_REQUEST=${CODEBUILD_GIT_BRANCH#pr-};
fi
- export CODEBUILD_PROJECT=${CODEBUILD_BUILD_ID%:$CODEBUILD_LOG_PATH}
- export CODEBUILD_BUILD_URL=https://$AWS_DEFAULT_REGION.console.aws.amazon.com/codebuild/home?region=$AWS_DEFAULT_REGION#/builds/$CODEBUILD_BUILD_ID/view/new
- export IMAGE_TAG=$CODEBUILD_GIT_SHORT_COMMIT
- export ACCOUNT=$CODEBUILD_ACCOUNT_ID
- echo "==> AWS CodeBuild Extra Environment Variables:"
- echo "==> CI = $CI"
- echo "==> CODEBUILD = $CODEBUILD"
- echo "==> CODEBUILD_ACCOUNT_ID = $CODEBUILD_ACCOUNT_ID"
- echo "==> CODEBUILD_GIT_AUTHOR = $CODEBUILD_GIT_AUTHOR"
- echo "==> CODEBUILD_GIT_AUTHOR_EMAIL = $CODEBUILD_GIT_AUTHOR_EMAIL"
- echo "==> CODEBUILD_GIT_BRANCH = $CODEBUILD_GIT_BRANCH"
- echo "==> CODEBUILD_GIT_CLEAN_BRANCH = $CODEBUILD_GIT_CLEAN_BRANCH"
- echo "==> CODEBUILD_GIT_ESCAPED_BRANCH = $CODEBUILD_GIT_ESCAPED_BRANCH"
- echo "==> CODEBUILD_GIT_COMMIT = $CODEBUILD_GIT_COMMIT"
- echo "==> CODEBUILD_GIT_SHORT_COMMIT = $CODEBUILD_GIT_SHORT_COMMIT"
- echo "==> CODEBUILD_GIT_MESSAGE = $CODEBUILD_GIT_MESSAGE"
- echo "==> CODEBUILD_GIT_TAG = $CODEBUILD_GIT_TAG"
- echo "==> CODEBUILD_GIT_MOST_RECENT_TAG = $CODEBUILD_GIT_MOST_RECENT_TAG"
- echo "==> CODEBUILD_PROJECT = $CODEBUILD_PROJECT"
- echo "==> CODEBUILD_PULL_REQUEST = $CODEBUILD_PULL_REQUEST"
- if [ "$CODEBUILD_GIT_CLEAN_BRANCH" = "main" ] ; then
export DEPLOY_DIR='/';
else
export DEPLOY_DIR=${CODEBUILD_GIT_CLEAN_BRANCH};
fi
- echo '***** This is the current env:'
- printenv
- ls -lah
- pwd
build:
commands:
- mkdir -p themes/learn
- git clone https://github.com/matcornic/hugo-theme-learn.git themes/learn
- echo "<p class="build-number">${IMAGE_TAG}</p>" >> layouts/partials/menu-footer.html
- cat layouts/partials/menu-footer.html
- npm install
- if [ "${CODEBUILD_GIT_CLEAN_BRANCH}" != "main" ] ; then
sed -i "s@href=./.@href=\"/$CODEBUILD_GIT_CLEAN_BRANCH\"@" layouts/partials/logo.html;
fi
- cut -c1-50 layouts/partials/logo.html
- if [ "${CODEBUILD_GIT_CLEAN_BRANCH}" != "main" ] ; then
sed -i "s@baseURL =.*@baseURL = \"https://ecsworkshop.com/$CODEBUILD_GIT_CLEAN_BRANCH\"@" config.toml;
fi
- head config.toml
- npm install
- npm run build
- if [ "$CODEBUILD_GIT_CLEAN_BRANCH" = "main" ] ; then
docker run -v $PWD/public/:/public 18fgsa/html-proofer /public --empty-alt-ignore --allow-hash-href --url-ignore http://ecsdemo-nodejs/,http://ecsdemo-crystal/crystal --disable-external;
else
docker run -v $PWD/public/:/public 18fgsa/html-proofer /public --empty-alt-ignore --allow-hash-href --url-swap "/$CODEBUILD_GIT_CLEAN_BRANCH:" --url-ignore http://ecsdemo-nodejs/,http://ecsdemo-crystal/crystal --disable-external;
fi
post_build:
commands:
- if [ "${CODEBUILD_BUILD_SUCCEEDING}" != "1" ] ; then
echo "the build failed -- not continuing with post build";
exit 99;
fi
- ./codebuild-deploy.sh