-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbitbucket-pipelines.yml
225 lines (213 loc) · 9.89 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
image: node:16.10.0
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
services:
docker:
memory: 2048
steps:
- step: &build-test
name: Build and test
caches:
- sonar
script:
- npm install --quiet
- npm run build-prod angular-common-services
- npm run build-prod angular-common-components
- npm run test
artifacts:
- projects/angular-common-components/coverage/lcov.info
- step: &analyze-sonarcloud
name: Analyze on SonarCloud
max-time: 15
caches:
- sonar
script:
- pipe: sonarsource/sonarcloud-scan:1.2.1
variables:
SONAR_SCANNER_OPTS: -Xmx2048m
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources="projects/angular-common-components/src,projects/angular-common-services/src"
-Dsonar.tests=projects/angular-common-components/src
-Dsonar.test.inclusions="**/testing/**,**/*.spec.ts"
-Dsonar.test.coverage.exclusions=**/mock/**
-Dsonar.typescript.lcov.reportPaths=projects/angular-common-components/coverage/lcov.info'
- step: &build-and-push-new-version-of-services
name: Push services to npm
script:
- git pull
- npm install --quiet
- npm run build-prod angular-common-services
- npm run angular-common-services-pack
- pipe: atlassian/npm-publish:0.3.2
variables:
NPM_TOKEN: $NPM_TOKEN
FOLDER: 'dist/angular-common-services'
EXTRA_ARGS: '--access public'
- step: &build-and-push-new-version-of-components
name: Push components to npm
script:
- git pull
- npm install --quiet
- npm run build-prod angular-common-components
- npm run angular-common-components-pack
- pipe: atlassian/npm-publish:0.3.2
variables:
NPM_TOKEN: $NPM_TOKEN
FOLDER: 'dist/angular-common-components'
EXTRA_ARGS: '--access public'
- step: &push-to-github
name: Push to GitHub
script:
- git remote set-url origin [email protected]:openchannel/angular-template-libraries.git
- git remote -v
- git push origin --force master:main
- git push origin --force --tags
- step: &build-app
name: "Build"
script:
- npm install
- npm run angular-common-services-pack
- npm run build-prod angular-common-components && npm run angular-common-components-pack
- npm run docs:json
- npm run scss-to-css
- npm run build-storybook
artifacts:
- storybook-static/**
- step: &build_compodoc_documentation_for_services
name: "Build compodoc documentation for services"
script:
- npm i
- npm run build-compodoc-services
artifacts:
- compodoc-static/**
- step: &deploy-compodoc
name: "Deploy to Environment"
image: atlassian/pipelines-awscli
script:
- unset CNAME
- export CNAME=${COMPODOC_CNAME}
- source infra/config-files/${CONFIG_FILE_SUFFIX}
- export PREFIX_NAME="openchannel-compodoc-${ENVIRONMENT}"
- chmod +x infra/scripts/*
- export CERTIFICATE_ARN=`./infra/scripts/getCertificate.sh us-east-1 *.${HOSTED_ZONE_NAME:0:-1}`
- aws cloudformation deploy --region $REGION --stack-name ${CLOUDFORMATION_STACKNAME}-cloudfront --capabilities CAPABILITY_NAMED_IAM --no-fail-on-empty-changeset --template-file infra/cloudformation/service-cloudfront.yml --parameter-overrides CNAME=$SITE_URL CertificateArn=$CERTIFICATE_ARN ProjectName=$APP_NAME ClusterName=$CLUSTER_NAME PrefixName=$PREFIX_NAME
- echo "aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/${CLUSTER_NAME}/${APP_NAME}/DISTRIBUTION_ID --output text --query Parameter.Value"
- echo "aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/${CLUSTER_NAME}/${APP_NAME}/AWS_S3 --output text --query Parameter.Value"
- export DISTRIBUTION_ID=`aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/${CLUSTER_NAME}/${APP_NAME}/DISTRIBUTION_ID --output text --query Parameter.Value`
- export AWS_S3="`aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/${CLUSTER_NAME}/${APP_NAME}/AWS_S3 --output text --query Parameter.Value`"
- aws s3 sync --delete compodoc-static/services/ s3://$AWS_S3
- aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /*
- step: &deploy-app
name: "Deploy to Environment"
image: atlassian/pipelines-awscli
script:
- source infra/config-files/${CONFIG_FILE_SUFFIX}
- chmod +x infra/scripts/*
- export CERTIFICATE_ARN=`./infra/scripts/getCertificate.sh us-east-1 *.${HOSTED_ZONE_NAME:0:-1}`
- aws cloudformation deploy --region $REGION --stack-name ${CLOUDFORMATION_STACKNAME}-cloudfront --capabilities CAPABILITY_NAMED_IAM --no-fail-on-empty-changeset --template-file infra/cloudformation/service-cloudfront.yml --parameter-overrides CNAME=$SITE_URL CertificateArn=$CERTIFICATE_ARN ProjectName=$APP_NAME ClusterName=$CLUSTER_NAME PrefixName=$PREFIX_NAME Logging="true"
- echo "aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/${CLUSTER_NAME}/${APP_NAME}/DISTRIBUTION_ID --output text --query Parameter.Value"
- echo "aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/${CLUSTER_NAME}/${APP_NAME}/AWS_S3 --output text --query Parameter.Value"
- export DISTRIBUTION_ID=`aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/${CLUSTER_NAME}/${APP_NAME}/DISTRIBUTION_ID --output text --query Parameter.Value`
- export AWS_S3="`aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/${CLUSTER_NAME}/${APP_NAME}/AWS_S3 --output text --query Parameter.Value`"
- aws s3 sync --delete storybook-static/ s3://$AWS_S3
- aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /*
- step: &up-project-version
name: "Up version"
script:
- /bin/bash ./scripts/package-json-version/script.sh $PROJECT_VERSION
- git add .
- git commit -m "Up version to $PROJECT_VERSION. [skip ci]"
- git push
- step: &create-changelog-with-git-tag
name: "Create changelog and add git tag"
script:
# Get current package.json version
- projectVerion=$(node -e "console.log(require('./package.json').version)")
# Validate package.json version
- if [[ ! $projectVerion == +([0-9]).+([0-9]).+([0-9]) ]]; then echo "Error. package.json file includes prerelease version $projectVerion. Must be like '1.1.1'. Please change version."; exit 1; fi
# Install required libs for changelog script
- npm i --prefix ./scripts/changelog-builder
# Generate new changelog file or skip
- EMAIL=${JIRA_EMAIL} API_KEY=${JIRA_API_KEY} RELEASE_VERSION=${JIRA_RELEASE_VERSION} PROJECT_VERSION=$projectVerion node ./scripts/changelog-builder/script.js
# Commit and push
- if [[ ! -z $(git status --porcelain) ]]; then git add . ; git commit -m "Created changelog.md for $JIRA_RELEASE_VERSION release. [skip ci]" ; git push ; else echo 'Changelog not changed.'; fi
# Create git tag and push
- /bin/bash ./scripts/create-and-push-github-tag/script.sh "${PUSH_TAG_FORCE}"
pipelines:
pull-requests:
'**':
- step: *build-test
- step: *analyze-sonarcloud
custom:
publish-components:
- step: *build-and-push-new-version-of-components
publish-services:
- step: *build-and-push-new-version-of-services
Deploy to dev1:
- step: *build-app
- step:
<<: *deploy-app
deployment: dev1
Deploy to stage1:
- step: *build-app
- step:
<<: *deploy-app
deployment: stage1
Deploy to us1:
- step: *build-app
- step:
<<: *deploy-app
deployment: us1
Up version:
- variables:
- name: PROJECT_VERSION
- step: *up-project-version
Up version and publish:
- variables:
- name: PROJECT_VERSION
- step: *build-test
- step: *up-project-version
- parallel:
- step: *build-and-push-new-version-of-services
- step: *build-and-push-new-version-of-components
Publish services and components:
- step: *build-test
- parallel:
- step: *build-and-push-new-version-of-services
- step: *build-and-push-new-version-of-components
Create changelog and Git Tag:
- variables:
- name: JIRA_RELEASE_VERSION
- name: PUSH_TAG_FORCE
- step: *build-test
- step: *create-changelog-with-git-tag
Dev1 compodoc (services):
- step: *build_compodoc_documentation_for_services
- step:
<<: *deploy-compodoc
deployment: dev1
Stage1 compodoc (services):
- step: *build_compodoc_documentation_for_services
- step:
<<: *deploy-compodoc
deployment: stage1
US1 compodoc (services):
- step: *build_compodoc_documentation_for_services
- step:
<<: *deploy-compodoc
deployment: us1
branches:
develop:
- step: *build-test
- step: *analyze-sonarcloud
release/*:
- step: *build-test
- step: *analyze-sonarcloud
master:
- step: *build-test
- step: *analyze-sonarcloud
- step: *push-to-github
- parallel:
- step: *build-and-push-new-version-of-services
- step: *build-and-push-new-version-of-components