Skip to content

Commit 8fb2f43

Browse files
authored
🔀 pull request #7 from devnetkc:ciUpdates
👷 Ci/CD Updates
2 parents 578484b + 29b79cc commit 8fb2f43

13 files changed

Lines changed: 278 additions & 108 deletions

.ci/scripts/createDeployment.sh

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,94 @@
11
#!/bin/bash
2-
#>testFile.txt
32
## Reset Manifest
43
cp ./.ci/templates/manifest.tpl.xml src/manifest.xml
4+
5+
## Store branch name for release
6+
echo "$2" >./.ci/.branch
7+
8+
## Declare variables
9+
### Create xml schema variables
510
endOfLine="</path>\n"
11+
12+
### Create regex strings to test with
613
srcRegex='src\/.*'
714
attributesRegex='.*\.attributes.*'
815
fileRegex='src\/FileCabinet\/SuiteScripts.*'
916
objectRegex='src\/Objects\/.*'
1017
objectScriptPathRegex='.*scriptfile.*'
18+
19+
### Output strings for File and Object lines
20+
#### Add more here if using other branches of deploy.xml schema
1121
FILELINE=
1222
OBJECTLINE=
23+
## Read git log for files impacted since origin headbranch -- reverts are also in the log
1324
while read line; do
14-
# We only want to update src files in deployment
25+
### We only want to update src files in deployment
1526
if [[ "$line" =~ $srcRegex ]]; then
16-
# Setup what the new line will look like
27+
### Test if file exists, if not we can skip it and import as dependency later
28+
if ! test -f "$line"; then
29+
continue
30+
fi
1731

32+
### Setup what the new line will look like
1833
newLine=$(echo "$line" | sed "s/src\//\t<path>~\//")"$endOfLine"
19-
# Is a src file
20-
# Separate Files & Objects to build deploy.xml
21-
#echo "$line"
34+
35+
### Skip duplicates -- lines which are already prepped to go in to deploy.xml
36+
if [[ $OBJECTLINE == *"$newLine"* || $FILELINE == *"$newLine"* ]]; then
37+
continue
38+
fi
39+
40+
### Separate Files & Objects to build deploy.xml
2241
if [[ "$line" =~ $fileRegex ]]; then
2342
if [[ "$line" =~ $attributesRegex ]]; then
2443
continue
25-
elif ! test -f "$line"; then
26-
continue
2744
fi
28-
#echo "file regex match"
29-
# Is a file update
45+
#### Is a file update
3046
FILELINE+="\t${newLine}"
31-
# echo $FILELINE
3247
elif [[ "$line" =~ $objectRegex ]]; then
33-
# Test line to see if the object needs a file path added
48+
### Test line to see if the object needs a file path dependency added
3449
while read OBJLINE; do
3550
if [[ "$OBJLINE" =~ $objectScriptPathRegex ]]; then
36-
#regexStr=".*${OBJLINE}.*"
37-
#echo $OBJLINE
51+
#### Modify line to deploy.xml schema
3852
SCRIPTPATH=$(echo "$OBJLINE" | sed "s/<scriptfile>\[/\/src/")
3953
SCRIPTPATH=$(echo "${SCRIPTPATH}" | sed "s/\]<\/scriptfile>//")
4054
depLine=$(echo "${SCRIPTPATH}" | sed "s/\/src\//\t<path>~\/FileCabinet\//")"$endOfLine"
4155
CLEANPATH=$(echo "$SCRIPTPATH" | sed "s/src\///")
4256
regexLineStr=".*$CLEANPATH"
57+
58+
#### Check if dependency file is already in file paths list
4359
if [[ "$FILELINE" =~ $regexLineStr ]]; then
4460
continue
4561
fi
62+
63+
##### Add to dependency to file list
4664
FILELINE+="\t${depLine}"
4765
fi
4866
done < <(cat "./${line}")
49-
#echo "object regex match"
50-
# Is an object file update
67+
68+
#### Is an object file update
5169
OBJECTLINE+="\t${newLine}"
52-
#echo $OBJECTLINE
5370
fi
5471
fi
72+
### Clear line variable
5573
line=""
56-
done < <(git diff origin/$1 $2 --name-only)
74+
done < <(git log --oneline --stat origin/$1..$2 --name-only)
5775

76+
## Generate deploy.xml file
77+
### Define output string variable
5878
OUTPUTLINES=""
79+
80+
### If file path entries is > 0 add files to deploy.xml
5981
if [[ $FILELINE ]]; then
6082
OUTPUTLINES="<files>\n${FILELINE}\t</files>"
6183
fi
84+
85+
### If object path entries is > 0 add objects to deploy.xml
6286
if [[ $OBJECTLINE ]]; then
6387
OUTPUTLINES="${OUTPUTLINES}\n\t<objects>\n${OBJECTLINE}\t</objects>"
6488
fi
89+
90+
### Print output to custom updated deploy.xml
91+
# shellcheck disable=SC2059
6592
printf "<deploy>
6693
<configuration>
6794
<path>~/AccountConfiguration/*</path>
@@ -70,4 +97,7 @@ printf "<deploy>
7097
<translationimports>
7198
<path>~/Translations/*</path>
7299
</translationimports>
73-
</deploy>" >src/deploy.xml | cat src/deploy.xml
100+
</deploy>" >src/deploy.xml
101+
102+
## Echo output for logging
103+
cat src/deploy.xml

.ci/workflows/azure-pipelines-build-deploy.yml

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# @format
2+
3+
# https://aka.ms/yaml
4+
5+
trigger: none
6+
7+
pr: none
8+
9+
parameters:
10+
- name: cancelPriorDeployments
11+
displayName: Cancel prior deployments
12+
type: boolean
13+
default: true
14+
15+
variables:
16+
- group: Base-NS-Deploy-Vars
17+
- group: prod-deploy-acct
18+
- group: NPM-PKG-Token
19+
- name: cancelPriorDeployments
20+
value: '${{ parameters.cancelPriorDeployments }}'
21+
- name: TestList
22+
value: '[Modules-Query]=Modules/Query,[Modules-Record]=Modules/Record,[Modules-Task]=Modules/Task,[Modules-Utility]=Modules/Utility,[Modules-Validate]=Modules/Validate'
23+
- name: SourcedBranch
24+
value: $(SOURCEBRANCH)
25+
26+
stages:
27+
- stage: CancelPriorDeploymentsStage
28+
displayName: Cancel prior deployments
29+
jobs:
30+
- job: CancelPriorDeploymentsJob
31+
displayName: List builds, cancel prior in progress
32+
pool:
33+
vmImage: 'windows-latest'
34+
steps:
35+
- checkout: none
36+
- task: PowerShell@2
37+
displayName: Powershell AzDO Invoke-RestMethod
38+
env:
39+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
40+
inputs:
41+
targetType: inline
42+
script: |
43+
$header = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
44+
$buildsUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=$(devOpsApiVersion)"
45+
Write-Host "GET $buildsUrl"
46+
$builds = Invoke-RestMethod -Uri $buildsUrl -Method Get -Header $header
47+
$buildsToStop = $builds.value.Where({ ($_.status -eq 'inProgress') -and ($_.definition.name -eq "$(Build.DefinitionName)") -and ($_.id -lt $(Build.BuildId)) })
48+
ForEach($build in $buildsToStop)
49+
{
50+
$urlToCancel = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$($build.id)?api-version=$(devOpsApiVersion)"
51+
$body = @{ status = "cancelling" } | ConvertTo-Json
52+
Write-Host "PATCH $urlToCancel"
53+
Invoke-RestMethod -Uri $urlToCancel -Method Patch -Header $header -ContentType application/json -Body $body
54+
}
55+
condition: eq(variables.cancelPriorDeployments, 'true')
56+
- stage: BuildProject
57+
displayName: Deploy Branch
58+
jobs:
59+
- job: BuildRelease
60+
steps:
61+
- template: azure-pipelines-build.yml
62+
- stage: SetBuildTagStage
63+
displayName: Add Build Tags
64+
jobs:
65+
- job: SetBuildTagJob
66+
displayName: Add Build Tag via PR Tag
67+
pool:
68+
vmImage: 'windows-latest'
69+
steps:
70+
- checkout: none
71+
- task: PowerShell@2
72+
displayName: 'Add Build Tag'
73+
condition: succeeded() # Only when all previous tasks have succeeded
74+
env:
75+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
76+
inputs:
77+
targetType: inline
78+
script: |
79+
Write-Host "##vso[build.addbuildtag]$env:buildLabel"
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# @format
2+
# https://aka.ms/yaml
3+
4+
trigger: none
5+
6+
pr: none
7+
8+
parameters:
9+
- name: cancelPriorDeployments
10+
displayName: Cancel prior deployments
11+
type: boolean
12+
default: true
13+
14+
variables:
15+
- group: Base-NS-Deploy-Vars
16+
- group: sb-deploy-acct
17+
- group: NPM-PKG-Token
18+
- name: cancelPriorDeployments
19+
value: '${{ parameters.cancelPriorDeployments }}'
20+
- name: TestList
21+
value: '[Modules-Query]=Modules/Query,[Modules-Record]=Modules/Record,[Modules-Task]=Modules/Task,[Modules-Utility]=Modules/Utility,[Modules-Validate]=Modules/Validate'
22+
- name: SourcedBranch
23+
value: $(SOURCEBRANCH)
24+
25+
stages:
26+
- stage: CancelPriorDeploymentsStage
27+
displayName: Cancel prior deployments
28+
jobs:
29+
- job: CancelPriorDeploymentsJob
30+
displayName: List builds, cancel prior in progress
31+
pool:
32+
vmImage: 'windows-latest'
33+
steps:
34+
- checkout: none
35+
- task: PowerShell@2
36+
displayName: Powershell AzDO Invoke-RestMethod
37+
env:
38+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
39+
inputs:
40+
targetType: inline
41+
script: |
42+
$header = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
43+
$buildsUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=$(devOpsApiVersion)"
44+
Write-Host "GET $buildsUrl"
45+
$builds = Invoke-RestMethod -Uri $buildsUrl -Method Get -Header $header
46+
$buildsToStop = $builds.value.Where({ ($_.status -eq 'inProgress') -and ($_.definition.name -eq "$(Build.DefinitionName)") -and ($_.id -lt $(Build.BuildId)) })
47+
ForEach($build in $buildsToStop)
48+
{
49+
$urlToCancel = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$($build.id)?api-version=$(devOpsApiVersion)"
50+
$body = @{ status = "cancelling" } | ConvertTo-Json
51+
Write-Host "PATCH $urlToCancel"
52+
Invoke-RestMethod -Uri $urlToCancel -Method Patch -Header $header -ContentType application/json -Body $body
53+
}
54+
condition: eq(variables.cancelPriorDeployments, 'true')
55+
- stage: BuildProject
56+
displayName: Deploy Update
57+
jobs:
58+
- job: BuildRelease
59+
steps:
60+
- template: azure-pipelines-build.yml
61+
- stage: SetBuildTagStage
62+
displayName: Add Build Tags
63+
jobs:
64+
- job: SetBuildTagJob
65+
displayName: Add Build Tag via PR Tag
66+
pool:
67+
vmImage: 'windows-latest'
68+
steps:
69+
- checkout: none
70+
- task: PowerShell@2
71+
displayName: 'Add Build Tag'
72+
condition: succeeded() # Only when all previous tasks have succeeded
73+
env:
74+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
75+
inputs:
76+
targetType: inline
77+
script: |
78+
Write-Host "##vso[build.addbuildtag]$env:buildLabel"

0 commit comments

Comments
 (0)