forked from OfficeDev/script-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-pipeline-template.yml
121 lines (104 loc) · 3.3 KB
/
package-pipeline-template.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
parameters:
- name: PackageDirectory
displayName: Directory of the package where the package.json is
type: string
- name: PackageName
displayName: Name of the package to be built
type: string
- name: SiteName
displayName: Name of Azure Site
type: string
steps:
- checkout: self
persistCredentials: true
- task: NodeTool@0
displayName: Node install
inputs:
versionSpec: '^16.0.0'
- script: npm ci
displayName: npm install
- script: npm run pre-ci
displayName: Pre-CI Script
- script: npm run postinstall
displayName: Post Install Script
env:
BRANCH: '$(Build.SourceBranchName)'
- task: PowerShell@2
displayName: 'Check diff on post install'
inputs:
targetType: 'inline'
script: |
# This makes sure that someone ran "npm install" after merging their PR, and that the postinstall doesn't produce any diffs, which are annoying/confusing
$diffs=$(git --no-pager diff HEAD --exit-code)
if([string]::IsNullOrEmpty($diffs)){
Write-Host "No diffs found"
exit 0
}
else {
Write-Host "Diffs were found"
exit 1
}
- script: npm run style-check
displayName: Style
- script: npm run lint
displayName: Lint
workingDirectory: ${{ parameters.PackageDirectory }}
- script: npm run citest
displayName: Test
workingDirectory: ${{ parameters.PackageDirectory }}
- script: cd ${{ parameters.PackageDirectory }} && npm run cibuild
displayName: 'Build'
env:
COMMIT_MESSAGE: '$(Build.SourceVersionMessage)'
- task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0
displayName: 'Generation Task'
inputs:
BuildDropPath: '${{ parameters.PackageDirectory }}/build'
- task: Bash@3
displayName: 'Get slot name'
inputs:
targetType: 'inline'
script: |
#!/bin/bash
branch=$(echo $BRANCH)
echo $branch
case "$branch" in
"master")
slot="alpha"
;;
"beta")
slot="beta"
;;
"production")
slot="staging"
;;
*)
slot="NULL"
;;
esac
echo $slot
echo "##vso[task.setvariable variable=SLOT]$slot"
env:
BRANCH: '$(Build.SourceBranchName)'
- task: ArchiveFiles@2
displayName: 'Archive build'
condition: and(succeeded(), ne(variables.SLOT, 'NULL'), eq(variables.isPR, false))
inputs:
rootFolderOrFile: '${{ parameters.PackageDirectory }}/build'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
verbose: true
- task: AzureWebApp@1
displayName: 'Deploy'
condition: and(succeeded(), ne(variables.SLOT, 'NULL'), eq(variables.isPR, false))
inputs:
azureSubscription: 'CALC - OFFICE DevEd - 1(3decf8b3-4173-4999-98ee-c636e852d4ac)'
appType: 'webApp'
appName: '${{ parameters.SiteName}}'
deployToSlotOrASE: true
resourceGroupName: 'ScriptLabReact'
slotName: $(SLOT)
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
deploymentMethod: 'auto'