-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
137 lines (118 loc) · 5.31 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
# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
- develop
- rl* # release branches to be built should be named rl[insertSemverHere]
# - ft* # feature branches to be built should be named ft[insertGithubIssueNumberHere]
- hf* # hotfix branches to be built should be named hf[insertGithubIssueNumberHere]
pool:
vmImage: "windows-2019"
variables:
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
appName: "pr$(System.PullRequest.PullRequestNumber)"
${{ if not(eq(variables['Build.Reason'], 'PullRequest')) }}:
appName: "$(Build.SourceBranchName)"
${{ if eq(variables['Build.SourceBranchName'], 'master') }}: # only works if you have a master branch
envName: "preproduction"
${{ if eq(variables['Build.SourceBranchName'], 'develop') }}: # only works if you have a develop branch
envName: "nonproduction"
${{ if contains(variables['Build.SourceBranchName'], 'ft') }}: # only works if you have a feature branch
envName: "nonproduction"
${{ if contains(variables['Build.SourceBranchName'], 'merge') }}: # only works if you have a PR branch
envName: "nonproduction"
${{ if contains(variables['Build.SourceBranchName'], 'rl') }}: # only works if you have a release branch
envName: "production"
steps:
- task: NodeTool@0
inputs:
versionSpec: "14.x"
displayName: "Install Node.js"
- script: |
npm install
displayName: "Install dependencies"
- script: |
npm test
displayName: "run unit and integration tests"
- script: |
if not exist "C:\Program Files (x86)\Google" mkdir "C:\Program Files (x86)\Google"
if not exist "C:\Program Files (x86)\Google\Chrome" mkdir "C:\Program Files (x86)\Google\Chrome"
mklink /D "C:\Program Files (x86)\Google\Chrome\Application" "C:\Program Files\Google\Chrome\Application"
echo "Getting webdriver for Chrome version"
pwsh -Command "echo $(Get-Item 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe').VersionInfo.ProductVersion"
pwsh -Command "./node_modules/.bin/webdriver-manager update --versions.chrome $(Get-Item 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe').VersionInfo.ProductVersion"
displayName: "add chrome driver to node directory "
condition: |
or(
eq(variables['Build.Reason'], 'PullRequest'),
eq(variables['Build.SourceBranch'], 'refs/heads/master'),
eq(variables['Build.SourceBranch'], 'refs/heads/develop')
)
failOnStderr: true
- script: |
npm run-script e2e
displayName: "run end-to-end tests"
condition: |
or(
eq(variables['Build.Reason'], 'PullRequest'),
eq(variables['Build.SourceBranch'], 'refs/heads/master'),
eq(variables['Build.SourceBranch'], 'refs/heads/develop')
)
- script: |
npm run-script lint
displayName: "run linting"
condition: |
or(
eq(variables['Build.Reason'], 'PullRequest'),
eq(variables['Build.SourceBranch'], 'refs/heads/master'),
eq(variables['Build.SourceBranch'], 'refs/heads/develop')
)
- script: |
npm run-script build -- --configuration=$(envName)
displayName: "npm build"
- task: CopyFiles@2
displayName: "Copy Build Artifacts to Staging Directory"
inputs:
SourceFolder: "$(System.DefaultWorkingDirectory)/dist/single-page-web-app"
Contents: |
**
TargetFolder: "$(Build.ArtifactStagingDirectory)"
- task: AzureCLI@2
displayName: "Create Container for Build Artefacts in Storage Account"
inputs:
azureSubscription: azure-ad-app-math-dojo-ui-pipeline
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
$accountNameExists = az storage account check-name --name mathdojouibuild$(appName) --subscription 5594cd6c-b674-4323-8517-5e859a399468 | ConvertFrom-Json
Write-Host "Does the account name exist for mathdojouibuild$(appName): $accountNameExists"
If ($accountNameExists.nameAvailable) {
try {
az storage account create --name mathdojouibuild$(appName) --kind StorageV2 --location uksouth --resource-group math-dojo-hzprod-web-ui --subscription 5594cd6c-b674-4323-8517-5e859a399468
}
catch {
Write-Host "An error occurred:"
Write-Host $_
}
}
az storage blob service-properties update --account-name mathdojouibuild$(appName) --static-website --index-document index.html --404-document index.html --auth-mode login
- task: AzureFileCopy@3
displayName: "Copy Build Artifacts to Blob Storage"
inputs:
sourcePath: "$(Build.ArtifactStagingDirectory)"
azureSubscription: azure-ad-app-math-dojo-ui-pipeline
destination: AzureBlob
storage: "mathdojouibuild$(appName)"
containerName: $web
copyFilesInParallel: true
cleanTargetBeforeCopy: true
- task: AzureCLI@2
displayName: "Show url for stored blob contents"
inputs:
azureSubscription: azure-ad-app-math-dojo-ui-pipeline
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az storage account show -n mathdojouibuild$(appName) -g math-dojo-hzprod-web-ui --query "primaryEndpoints.web" --output tsv