@@ -7,55 +7,175 @@ steps:
77 versionSpec : ' 17'
88 jdkArchitectureOption : ' x64'
99 jdkSourceOption : ' PreInstalled'
10+ displayName : Install JDK17
1011 - checkout : self
1112 clean : true
1213 persistCredentials : true
14+ displayName : Checkout Repository
1315 - script : |
16+ ## Validate Repo is Current
1417 # Fetch origin branches
18+ git fetch --all
19+ ## leave detached head mode
20+ git checkout origin/$(HEADBRANCH)
21+ git reset --hard origin/$(HEADBRANCH)
22+ echo "##vso[task.setvariable variable=sfdxExitCode;]0"
23+ npm i
24+ 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
25+ ### Adding git credentials
26+ git config user.email "YOUR@EMAIL_HERE.com"
27+ git config user.name "Azure Pipeline"
28+ ## Committing all changes temporarily, these won't be pushed
29+ git add -A && git commit -m "🔮 Clearing Changes for Validation Testing"
30+ npm run validate-repo-current
31+ displayName: Validate Repo Current
32+ env:
33+ ENV_TOKENSECRET: $(TOKENSECRET)
34+ ENV_TOKENID: $(TOKENID)
35+ NPM_TOKEN: $(NPM_TOKEN)
36+ failOnStandardError: false
37+ continueOnError: false
38+
39+ - task : PowerShell@2
40+ inputs :
41+ targetType : ' inline'
42+ script : |
43+ $exitCode = $(sfdxExitCode)
44+ $forceRelease = "$(FORCERELEASE)"
45+ if ($exitCode -ne 0) {
46+ Write-Host "Force Release: $forceRelease"
47+ if ($forceRelease -ne "YES" ) {
48+ Write-Error "Failing task since return code was {0} while expected 0."
49+ Write-Host "##vso[task.logissue type=error]Changes Detected...STOPPING RELEASE!"
50+ exit($exitCode)
51+ } else {
52+ Write-Host "##vso[task.logissue type=warning;code=100;]Changes Detected...continuing -- Forced Release"
53+ }
54+ } else {
55+ Write-Host "No Changes Detected...continuing"
56+ }
57+ failOnStderr : false
58+ displayName : Validate Repo is Clean
59+
60+ - script : |
61+ ## Reset RELEASE_BUILD variable in case this is just docs or CI changes
62+ echo "##vso[task.setvariable variable=RELEASE_BUILD]false"
63+
64+
65+ ## Fetch origin branches
1566 git fetch --all --prune
67+ ## leave detached head mode
68+ git checkout $(SourcedBranch) --force
69+ git reset --hard origin/$(SourcedBranch)
70+ displayName: Initialize Repository
71+ env:
72+ SYSTEM_ACCESSTOKEN: $(System.AccessToken)
73+ - script : |
74+ OBJECTS_BUILD_PATH=$(BUILD_DIR)/$(OBJECTS_PATH)
75+ ## Cleanup build dir if exists
76+ rm -rf $(BUILD_DIR)
77+ mkdir $(BUILD_DIR)
78+ ## Copy files to build directory
79+ find . ! -path "*$(BUILD_DIR)*" | cpio -pdm ./$(BUILD_DIR)
80+ ## Clean out objects directory
81+ rm -rf $OBJECTS_BUILD_PATH
82+ mkdir $OBJECTS_BUILD_PATH
83+ ## Copy object definitions to build dir without subpath tree
84+ displayName: Initialize Build Directory
85+
86+ - task : Bash@3
87+ inputs :
88+ filePath : ' ./.ci/scripts/flattenObjectPaths.sh'
89+ arguments : ' $(BUILD_DIR)/$(OBJECTS_PATH) $(HEADBRANCH) $(SourcedBranch)'
90+ failOnStandardError : true
91+ displayName : Flatten Object Trees
1692
93+ - script : |
94+ ## Switch to build directory to continue deployment
95+ cd $(BUILD_DIR)
96+ # Fetch origin branches
97+ git fetch --all --prune
1798 ## leave detached head mode
1899 git checkout $(SourcedBranch)
19-
20- # Install NetSuite SDF
21100 npm i
22- npm run setup-server --sourcebranch=$(SourcedBranch) --headbranch=$(HEADBRANCH) --account=$(ACCOUNT) --authid=$(AUTHID) --tokenid=$ENV_TOKENID --tokensecret=$ENV_TOKENSECRET
23-
24- ## Uncomment if not using Azure DevOps Releases to deploy changes to NetSuite
101+ 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
102+ ### Commenting out because this is moving to release workflow
25103 # npm run deploy-pipeline --verbose
26-
27- ## Run Jest tests
104+ # SourcedBranch
28105 npm run test
106+ displayName: Run Tests
29107 env:
30108 # NPM Token variable if using private NPM repository for packages
31109 # NPM_TOKEN: $(NPM_TOKEN) #uncomment to use
32110 # NetSuite Secret Token within Azure Library/Variables
33111 ENV_TOKENSECRET: $(TOKENSECRET)
112+ ENV_TOKENID: $(TOKENID)
34113 # NetSuite Secret Token ID within Azure Library/Variables
35- ENV_TOKENID:
36- $(TOKENID)
37-
38- # Publish test results to Azure
39- # - task: PublishTestResults@2
40- # inputs:
41- # testResultsFormat: 'JUnit'
42- # testResultsFiles: '**/test-report*.xml'
43- # failTaskOnFailedTests: true
44- # testRunTitle: 'NetSuite Module Deployment Tests'
45-
46- # # Publish artifact to Azure for use in Release pipeline
47- # Alternative would be to deploy in RunNPMScripts step
48- # - task: CopyFiles@2
49- # inputs:
50- # contents: |
51- # **
52- # !**/node_modules/**
53- # !**/.vscode/**
54- # !**/docs/**
55- # !**/resources/**
56- # !**/__tests__/**
57- # targetFolder: $(Build.ArtifactStagingDirectory)
58- # - task: PublishBuildArtifacts@1
59- # inputs:
60- # pathToPublish: $(Build.ArtifactStagingDirectory)
61- # artifactName: Build-$(buildLabel)
114+ NPM_TOKEN: $(NPM_TOKEN)
115+ failTaskOnFailedTests: true
116+
117+ # - task: PublishTestResults@2
118+ # inputs:
119+ # testResultsFormat: 'JUnit'
120+ # testResultsFiles: '**/test-report*.xml'
121+ # testRunTitle: 'NetSuite Repo Tests'
122+ # displayName: Publish Test Results
123+ # condition: always()
124+
125+ # - task: CopyFiles@2
126+ # inputs:
127+ # contents: |
128+ # **/.build/**
129+ # !**/node_modules/**
130+ # !**/.vscode/**
131+ # !**/docs/**
132+ # !**/resources/**
133+ # !**/__tests__/**
134+ # targetFolder: $(Build.ArtifactStagingDirectory)
135+ # displayName: Stage Build Artifact
136+
137+ # - task: PublishBuildArtifacts@1
138+ # inputs:
139+ # pathToPublish: $(Build.ArtifactStagingDirectory)
140+ # artifactName: Build-$(BuildLabel)
141+ # displayName: Publish Build Artifact
142+
143+ # - script: |
144+ # echo "##vso[build.addbuildtag]$(BuildLabel)"
145+ # displayName: Add Build Tag
146+ # condition: and(succeeded(), eq(variables['RELEASE_BUILD'], 'true'))
147+ # env:
148+ # SYSTEM_ACCESSTOKEN: $(System.AccessToken)
149+
150+ - task : PowerShell@2
151+ inputs :
152+ targetType : ' inline'
153+ script : |
154+
155+ ## Update Project Release Version based on projects package.json version
156+ $VERSION = "$(cat package.json | grep 'version' | cut -d ':' -f 2 )"
157+ $SAVE_VERSION = $VERSION -replace '"|,',''
158+ $VariableGroupId = GROUP_ID_NUMBER
159+ $NewValue = $SAVE_VERSION
160+ $VariableName = NetSuite_version"
161+
162+ Write-Host "NewValue : $NewValue"
163+
164+ $url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/distributedtask/variablegroups/$($VariableGroupId)?api-version=5.1-preview.1"
165+
166+ Write-Host "URL: $url"
167+
168+ $authHeader = @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
169+
170+ $definition = Invoke-RestMethod -Uri $url -Headers $authHeader
171+
172+ Write-Host "Pipeline = $($definition | ConvertTo-Json -Depth 100)"
173+
174+ $definition.variables.$VariableName.Value = "$($NewValue)"
175+
176+ $definitionJson = $definition | ConvertTo-Json -Depth 100 -Compress
177+
178+ Invoke-RestMethod -Method Put -Uri $url -Headers $authHeader -ContentType "application/json" -Body ([System.Text.Encoding]::UTF8.GetBytes($definitionJson)) | Out-Null
179+ displayName : Update Project Version
180+ env :
181+ SYSTEM_ACCESSTOKEN : $(System.AccessToken)
0 commit comments