This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbucket-pipelines.yml
207 lines (201 loc) · 11.2 KB
/
bitbucket-pipelines.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
## Author: Kevin Ma
## Pipeline:
#1) Runs semantic library to get semantic version
#2) Update version # in documentation (download URL) and package.json
#3) Deploys version's build folder in S3 (/build/x.x.x/)
#4) Deploys public folder in S3 (/public/x.x.x/)
#5) Deploys docs styles folder in S3 (/build/x.x.x/docs/)
#6) Deploys icon assets to root of S3
#7) Make and deploy index.html used to redirect users to the most updated docs
## TODO
#1) Only deploy updated files
#2) Invalidate CDN urls on pipeline success (manually update @ https://console.aws.amazon.com/cloudfront/home?#distribution-settings:EUU3JRBWPI1HQ)
#3) Only invalidate updated files
image: node:16.13.1
pipelines:
branches:
main:
- step:
name: Web Components Production
caches:
- node
script:
# Get an oauth access token using the client credentials, parsing out the token with jq (json processor).
- apt-get update && apt-get install -y curl jq moreutils
- export BB_TOKEN=$(echo "x-token-auth:")$(curl -s -X POST -u "${CLIENT_ID}:${CLIENT_SECRET}" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials -d scopes="repository" | jq --raw-output '.access_token')
- npm install -g gulp
- npm install gulp-minify gulp-zip del
- npx semantic-release
# set current tag number -- this will be used to deploy to the correct S3 public folder
- export updateTag=$(git describe --tags --abbrev=0)
- export updateTag="${updateTag#?}"
# update version # in package.json
- jq --arg updateTag $updateTag '.version = $updateTag' package.json|sponge package.json
# add %!CurrentVersion%! string filter
# - gulp addImageFilterStrs
# update version # in asset URL documentation page
- find src \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s/%!CurrentVersion%!/"$updateTag"/g"
# produce local comp scripts to ensure minified production scripts can be created
- gulp generateCompLibScripts
# update component script and style file extensions
- sed -i -e 's/ucla-lib-scripts.js/'"ucla-lib-scripts.min.js"'/g' src/components/_preview.hbs
- sed -i -e 's/ucla-lib.css/'"ucla-lib.min.css"'/g' src/components/_preview.hbs
- gulp production
# add updated package.json and compiled public assets
- git add package.json package-lock.json
# - git add -f public/*
- set +e git commit -m "[skip ci] Auto production build during CI with current tag upgraded to ${updateTag}" set -e
- set +e git push set -e
# deploy build to S3
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_PROD
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_PROD
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_PROD
S3_BUCKET: webcomponents.ucla.edu/build/${updateTag}
LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/build
ACL: 'public-read'
EXTRA_ARGS: "--delete"
# deploy public to S3
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_PROD
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_PROD
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_PROD
S3_BUCKET: webcomponents.ucla.edu/public/${updateTag}
LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/public
ACL: 'public-read'
EXTRA_ARGS: "--exclude=/public/docs/"
EXTRA_ARGS: "--delete"
# deploy public/docs to S3
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_PROD
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_PROD
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_PROD
S3_BUCKET: webcomponents.ucla.edu/build/${updateTag}/docs
LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/build/docs
ACL: 'private'
EXTRA_ARGS: "--delete"
# deploy icon images to S3
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_PROD
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_PROD
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_PROD
S3_BUCKET: webcomponents.ucla.edu/icons
LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/src/icons
EXTRA_ARGS: "--delete"
- mkdir redirection
- touch ./redirection/index.html
# redirection to most current version hack
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_PROD
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_PROD
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_PROD
S3_BUCKET: webcomponents.ucla.edu
LOCAL_PATH: ./redirection
EXTRA_ARGS: "--website-redirect=https://webcomponents.ucla.edu/build/${updateTag}/index.html"
- rm -rf ./redirection
- echo "Updates from the branch ==> $BITBUCKET_BRANCH <== has been included in S3 with the tag ==> $updateTag <=="
development:
- step:
name: Web Components Development
script:
# Get an oauth access token using the client credentials, parsing out the token with jq (json processor).
- apt-get update && apt-get install -y curl jq moreutils
- export BB_TOKEN=$(echo "x-token-auth:")$(curl -s -X POST -u "${CLIENT_ID}:${CLIENT_SECRET}" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials -d scopes="repository" | jq --raw-output '.access_token')
- npm install -g gulp
- npm install gulp-minify gulp-zip del
- npx semantic-release
# set current tag number -- this will be used to deploy to the correct S3 public folder
- export updateTag=$(git describe --tags --abbrev=0)
- export updateTag="${updateTag#?}"
# update version # in asset URL documentation page
# - find src \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s/build\/%!CurrentVersion%!/dev-webcomponents.ucla.edu\/build\/"$updateTag"/g"
# add %!CurrentVersion%! string filter
# - gulp addImageFilterStrs
- find src \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s/%!CurrentVersion%!/"$updateTag"/g"
# produce local comp scripts to ensure minified production scripts can be created
- gulp generateCompLibScripts
# update component script and style file extensions
- sed -i -e 's/ucla-lib-scripts.js/'"ucla-lib-scripts.min.js"'/g' src/components/_preview.hbs
- sed -i -e 's/ucla-lib.css/'"ucla-lib.min.css"'/g' src/components/_preview.hbs
- gulp production
# deploy build to S3
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_DEV
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_DEV
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_DEV
S3_BUCKET: dev-webcomponents-ucla-edu/build/${updateTag}
LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/build
ACL: 'public-read'
EXTRA_ARGS: "--delete"
# deploy public to S3
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_DEV
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_DEV
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_DEV
S3_BUCKET: dev-webcomponents-ucla-edu/public/${updateTag}
LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/public
ACL: 'public-read'
EXTRA_ARGS: "--exclude=/public/docs/"
EXTRA_ARGS: "--delete"
# deploy public/docs to S3
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_DEV
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_DEV
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_DEV
S3_BUCKET: dev-webcomponents-ucla-edu/build/${updateTag}/docs
LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/build/docs
ACL: 'private'
EXTRA_ARGS: "--delete"
# deploy icon images to S3
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_DEV
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_DEV
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_DEV
S3_BUCKET: dev-webcomponents-ucla-edu/icons
LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/src/icons
EXTRA_ARGS: "--delete"
- mkdir redirection
- touch ./redirection/index.html
# redirection to most current version hack
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_DEV
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_DEV
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_DEV
S3_BUCKET: dev-webcomponents-ucla-edu
LOCAL_PATH: ./redirection
EXTRA_ARGS: "--website-redirect=http://dev-webcomponents-ucla-edu.s3-us-west-1.amazonaws.com/build/${updateTag}/index.html"
- rm -rf ./redirection
- echo "Updates from the branch ==> $BITBUCKET_BRANCH <== has been included in S3 with the tag ==> $updateTag <=="
campus:
- step:
name: Web Components Campus
script:
# Get an oauth access token using the client credentials, parsing out the token with jq (json processor).
- apt-get update && apt-get install -y curl jq moreutils
- export BB_TOKEN=$(echo "x-token-auth:")$(curl -s -X POST -u "${CLIENT_ID}:${CLIENT_SECRET}" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials -d scopes="repository" | jq --raw-output '.access_token')
- npm install -g gulp
- npm install gulp-minify gulp-zip del
- gulp generateCompLibScripts
- sed -i -e 's/ucla-lib-scripts.js/'"ucla-lib-scripts.min.js"'/g' src/components/_preview.hbs
- sed -i -e 's/ucla-lib.css/'"ucla-lib.min.css"'/g' src/components/_preview.hbs
- gulp production
# deploy build to S3
- pipe: atlassian/aws-s3-deploy:0.4.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_DEV
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_DEV
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_DEV
S3_BUCKET: campus-webcomponents-ucla-edu
LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/build
ACL: 'public-read'
EXTRA_ARGS: "--delete"