-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines-build.yml
181 lines (159 loc) · 6.5 KB
/
azure-pipelines-build.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
# @format
steps:
- template: azure-pipelines-select-branch.yml
- task: JavaToolInstaller@0
inputs:
versionSpec: '17'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
displayName: Install JDK17
- checkout: self
clean: true
persistCredentials: true
displayName: Checkout Repository
- script: |
## Validate Repo is Current
# Fetch origin branches
git fetch --all
## leave detached head mode
git checkout origin/$(HEADBRANCH)
git reset --hard origin/$(HEADBRANCH)
echo "##vso[task.setvariable variable=sfdxExitCode;]0"
npm i
npm run setup-server-token --sourcebranch=$(SourcedBranch) --headbranch=$(HEADBRANCH) --account=$(ACCOUNT) --authid=$(AUTHID) --tokenid=$ENV_TOKENID --tokensecret=$ENV_TOKENSECRET --releaserun=$(RELEASE_RUN) --flatobjects=NO --validaterun=YES
### Adding git credentials
git config user.email "YOUR@EMAIL_HERE.com"
git config user.name "Azure Pipeline"
## Committing all changes temporarily, these won't be pushed
git add -A && git commit -m "🔮 Clearing Changes for Validation Testing"
npm run validate-repo-current
displayName: Validate Repo Current
env:
ENV_TOKENSECRET: $(TOKENSECRET)
ENV_TOKENID: $(TOKENID)
NPM_TOKEN: $(NPM_TOKEN)
failOnStandardError: false
continueOnError: false
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$exitCode = $(sfdxExitCode)
$forceRelease = "$(FORCERELEASE)"
if ($exitCode -ne 0) {
Write-Host "Force Release: $forceRelease"
if ($forceRelease -ne "YES" ) {
Write-Error "Failing task since return code was {0} while expected 0."
Write-Host "##vso[task.logissue type=error]Changes Detected...STOPPING RELEASE!"
exit($exitCode)
} else {
Write-Host "##vso[task.logissue type=warning;code=100;]Changes Detected...continuing -- Forced Release"
}
} else {
Write-Host "No Changes Detected...continuing"
}
failOnStderr: false
displayName: Validate Repo is Clean
- script: |
## Reset RELEASE_BUILD variable in case this is just docs or CI changes
echo "##vso[task.setvariable variable=RELEASE_BUILD]false"
## Fetch origin branches
git fetch --all --prune
## leave detached head mode
git checkout $(SourcedBranch) --force
git reset --hard origin/$(SourcedBranch)
displayName: Initialize Repository
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- script: |
OBJECTS_BUILD_PATH=$(BUILD_DIR)/$(OBJECTS_PATH)
## Cleanup build dir if exists
rm -rf $(BUILD_DIR)
mkdir $(BUILD_DIR)
## Copy files to build directory
find . ! -path "*$(BUILD_DIR)*" | cpio -pdm ./$(BUILD_DIR)
## Clean out objects directory
rm -rf $OBJECTS_BUILD_PATH
mkdir $OBJECTS_BUILD_PATH
## Copy object definitions to build dir without subpath tree
displayName: Initialize Build Directory
- task: Bash@3
inputs:
filePath: './.ci/scripts/flattenObjectPaths.sh'
arguments: '$(BUILD_DIR)/$(OBJECTS_PATH) $(HEADBRANCH) $(SourcedBranch)'
failOnStandardError: true
displayName: Flatten Object Trees
- script: |
## Switch to build directory to continue deployment
cd $(BUILD_DIR)
# Fetch origin branches
git fetch --all --prune
## leave detached head mode
git checkout $(SourcedBranch)
npm i
npm run setup-server --sourcebranch=$(SourcedBranch) --headbranch=$(HEADBRANCH) --account=$(ACCOUNT) --authid=$(AUTHID) --tokenid=$ENV_TOKENID --tokensecret=$ENV_TOKENSECRET --releaserun=$(RELEASE_RUN) --flatobjects=YES --validaterun=NO
### Commenting out because this is moving to release workflow
# npm run deploy-pipeline --verbose
# SourcedBranch
npm run test
displayName: Run Tests
env:
# NPM Token variable if using private NPM repository for packages
# NPM_TOKEN: $(NPM_TOKEN) #uncomment to use
# NetSuite Secret Token within Azure Library/Variables
ENV_TOKENSECRET: $(TOKENSECRET)
ENV_TOKENID: $(TOKENID)
# NetSuite Secret Token ID within Azure Library/Variables
NPM_TOKEN: $(NPM_TOKEN)
failTaskOnFailedTests: true
# - task: PublishTestResults@2
# inputs:
# testResultsFormat: 'JUnit'
# testResultsFiles: '**/test-report*.xml'
# testRunTitle: 'NetSuite Repo Tests'
# displayName: Publish Test Results
# condition: always()
# - task: CopyFiles@2
# inputs:
# contents: |
# **/.build/**
# !**/node_modules/**
# !**/.vscode/**
# !**/docs/**
# !**/resources/**
# !**/__tests__/**
# targetFolder: $(Build.ArtifactStagingDirectory)
# displayName: Stage Build Artifact
# - task: PublishBuildArtifacts@1
# inputs:
# pathToPublish: $(Build.ArtifactStagingDirectory)
# artifactName: Build-$(BuildLabel)
# displayName: Publish Build Artifact
# - script: |
# echo "##vso[build.addbuildtag]$(BuildLabel)"
# displayName: Add Build Tag
# condition: and(succeeded(), eq(variables['RELEASE_BUILD'], 'true'))
# env:
# SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
## Update Project Release Version based on projects package.json version
$VERSION = "$(cat package.json | grep 'version' | cut -d ':' -f 2 )"
$SAVE_VERSION = $VERSION -replace '"|,',''
$VariableGroupId = GROUP_ID_NUMBER
$NewValue = $SAVE_VERSION
$VariableName = NetSuite_version"
Write-Host "NewValue : $NewValue"
$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/distributedtask/variablegroups/$($VariableGroupId)?api-version=5.1-preview.1"
Write-Host "URL: $url"
$authHeader = @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
$definition = Invoke-RestMethod -Uri $url -Headers $authHeader
Write-Host "Pipeline = $($definition | ConvertTo-Json -Depth 100)"
$definition.variables.$VariableName.Value = "$($NewValue)"
$definitionJson = $definition | ConvertTo-Json -Depth 100 -Compress
Invoke-RestMethod -Method Put -Uri $url -Headers $authHeader -ContentType "application/json" -Body ([System.Text.Encoding]::UTF8.GetBytes($definitionJson)) | Out-Null
displayName: Update Project Version
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)