-
Notifications
You must be signed in to change notification settings - Fork 13
/
azure-pipelines.yml
142 lines (129 loc) · 5.55 KB
/
azure-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
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
- releases/r1-release
- demo/develop
- demo2/develop
- develop
variables:
- group: 'Platform Release Variables'
pool:
vmImage: ubuntu-latest
workspace:
clean: all
steps:
- checkout: self
persistCredentials: true
clean: true
- script: |
#!/bin/bash
git checkout develop
git checkout -
BEHIND=$(git rev-list --left-right --count develop...HEAD|awk '{print$1}')
if [ $BEHIND -ne 0 ]
then
echo "false"
echo "CI failed, Your branch $(Build.SourceBranch) is $BEHIND commits behind of develop branch changes, Kindly merge the changes from develop branch and rerun the pipeline"
exit 1
else
echo "true"
fi
condition: not(or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/develop'), eq(variables['Build.SourceBranch'], 'refs/heads/demo/develop'), eq(variables['Build.SourceBranch'], 'refs/heads/demo2/develop'), eq(variables['Build.SourceBranch'], 'refs/heads/releases/r1-release'), startsWith(variables['Build.SourceBranch'], 'refs/heads/hotfix'), eq(variables['System.PullRequest.TargetBranch'], 'master'), eq(variables['System.PullRequest.TargetBranch'], 'releases/r1-release'), eq(variables['System.PullRequest.TargetBranch'], 'demo/develop'), eq(variables['System.PullRequest.TargetBranch'], 'demo2/develop')))
displayName: "Check if Branch is in Sync"
- task: NodeTool@0
inputs:
versionSpec: '12.20.x'
displayName: 'Use Node 12'
- task: CmdLine@2
inputs:
script: |
#!/bin/bash
git config --global user.email "[email protected]"
git config --global user.name "Automated VSTS Build Server"
BRANCH=$(echo $(Build.SourceBranch) | sed 's/refs\/heads\///')
echo "Checking out $BRANCH"
git checkout $BRANCH
displayName: 'Attach branch'
condition: not(eq(variables['Build.SourceBranchName'], 'merge'))
- script: |
echo "@emgage:=registry" > .npmrc
echo "//registry.npmjs.org/:_authToken=$(NPM_TOKEN)" >> .npmrc
displayName: "Write NPMRC"
- task: CmdLine@2
inputs:
script: |
npm install
npm rebuild node-sass
displayName: 'Npm Install'
- task: CmdLine@2
inputs:
script: 'npm run build-dev'
displayName: 'Npm Install'
- task: CmdLine@2
inputs:
script: |
#!/bin/bash
lib_path='engage-ui@develop/lib'
git update-index --assume-unchanged .npmrc
VERSION_1=$(npm view engage-ui@latest version)
VERSION_2=$(npm view engage-ui@develop version)
VERSION_3=$(npm view engage-ui@demo version)
VERSION_4=$(npm view engage-ui@release version)
VERSION_5=$(npm view engage-ui@squad6 version)
VERSION_6=$(npm view engage-ui@demo2 version)
NEWEST_VERSION=$(printf '%s\n' "$VERSION_1" "$VERSION_2" "$VERSION_3" "$VERSION_4" "$VERSION_5" "$VERSION_6"| sort -rV | head -n1)
echo "$NEWEST_VERSION"
# Sometimes version in package.json doesn't get updated hence making sure it is updated manually.
sed -i "s/\"version\": \".*\",/\"version\": \"$NEWEST_VERSION\",/g" package.json
git update-index --assume-unchanged package.json
BRANCH_NAME="$(echo $(Build.SourceBranch)|sed 's#refs/heads/##g')"
# Tag master a major release, release and demo as minor releases and rest as prerelease.
case "$BRANCH_NAME" in
'master')
npm version --no-git-tag-version major
npm publish --tag latest
lib_path='engage-ui@latest/lib'
;;
'demo2/develop')
npm version --no-git-tag-version minor
npm publish --tag demo2
lib_path='engage-ui@demo2/lib'
;;
'demo/develop')
npm version --no-git-tag-version minor
npm publish --tag demo
lib_path='engage-ui@demo/lib'
;;
'releases/r1-release')
npm version --no-git-tag-version minor
npm publish --tag release
lib_path='engage-ui@release/lib'
;;
*)
npm version --no-git-tag-version prerelease
npm publish --tag develop
lib_path='engage-ui@develop/lib'
;;
esac
echo "publishing to $lib_path"
git add .
git commit -m "chore: Release" --no-verify
git push
echo "##vso[task.setvariable variable=engageui]$lib_path"
displayName: 'Tag and Publish'
condition: and(not(startsWith(variables['Build.SourceVersionMessage'], 'chore')), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/develop'), eq(variables['Build.SourceBranch'], 'refs/heads/demo/develop'), eq(variables['Build.SourceBranch'], 'refs/heads/demo2/develop'), eq(variables['Build.SourceBranch'], 'refs/heads/releases/r1-release')))
- task: S3Upload@1
inputs:
awsCredentials: 'AWS Connection'
regionName: 'us-west-2'
bucketName: 'emgage.software'
sourceFolder: '$(System.DefaultWorkingDirectory)'
globExpressions: 'lib/+(EngageUI.js|DeliciousTheme.js)'
targetFolder: 'cdn/$(engageui)'
filesAcl: 'public-read'
flattenFolders: true
condition: and(not(startsWith(variables['Build.SourceVersionMessage'], 'chore')), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/develop'), eq(variables['Build.SourceBranch'], 'refs/heads/demo/develop'), eq(variables['Build.SourceBranch'], 'refs/heads/demo2/develop'), eq(variables['Build.SourceBranch'], 'refs/heads/releases/r1-release')))
displayName: 'Copy to S3'