Skip to content

Commit 85c4030

Browse files
Test branch cleanup for release pipeline (#4894)
* Fix paths filter. Add stage for test release branch cleanup * Fix condition * Fix cleanup stage * Disable sign param temporarily * Move stage earlier in the pipeline * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Small tweak * Fix * Fix * Re-enable sign parameter * Fix dryrun * Fix dryrun * Remove logs
1 parent 842df8d commit 85c4030

File tree

2 files changed

+65
-18
lines changed

2 files changed

+65
-18
lines changed

.vsts.release.yml

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# This Yaml Document has been converted by ESAI Yaml Pipeline Conversion Tool.
2-
32
trigger:
3+
branches:
4+
include:
5+
- '*'
6+
paths:
7+
include:
8+
- release
9+
- .azure-pipelines
10+
- .vsts.release.yml
11+
12+
pr:
13+
branches:
14+
include:
15+
- '*'
416
paths:
517
include:
618
- release
@@ -344,15 +356,43 @@ extends:
344356
displayName: Delete test agent release from Github
345357
condition: and(succeeded(), eq(variables.IsTestRun, 'True'))
346358
347-
# Clean up test release branch
359+
- stage: Cleanup_Release_Branch
360+
displayName: Cleanup Release Branch
361+
dependsOn:
362+
- Verify_release
363+
- Create_Release_Branch
364+
- Release
365+
condition: always()
366+
jobs:
367+
- job: Delete_Release_Branch
368+
displayName: Delete Release Branch
369+
variables:
370+
IsTestRun: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.isTestRun'] ]
371+
condition: eq(variables.IsTestRun, 'True')
372+
373+
pool:
374+
name: 1ES-ABTT-Shared-Pool
375+
image: abtt-ubuntu-2204
376+
os: linux
377+
steps:
378+
- checkout: self
379+
348380
- powershell: |
349381
git config --global user.email "[email protected]"
350382
git config --global user.name "azure-pipelines-bot"
351383
git status
352-
git -c credential.helper='!f() { echo "username=pat"; echo "password=$(GithubToken)"; };f' push origin --delete $(ReleaseBranch)
353-
git push --delete origin v$(AgentVersion)
384+
385+
$testBranch = "releases/3.000.999"
386+
$testTag = "v3.000.999"
387+
388+
if (git ls-remote --heads origin $testBranch) {
389+
git -c credential.helper='!f() { echo "username=pat"; echo "password=$(GithubToken)"; };f' push origin --delete $testBranch
390+
}
391+
392+
if (git ls-remote --tags origin $testTag) {
393+
git -c credential.helper='!f() { echo "username=pat"; echo "password=$(GithubToken)"; };f' push --delete origin $testTag
394+
}
354395
displayName: Clean up test release branch
355-
condition: and(succeeded(), eq(variables.IsTestRun, 'True'))
356396
357397
- stage: CreatePRs
358398
dependsOn:
@@ -395,7 +435,7 @@ extends:
395435
cd release
396436
npm install
397437
ls
398-
node createAdoPrs.js $(AgentVersion) --dryrun=$(IsTestRun)
438+
node createAdoPrs.js $(AgentVersion) --dryrun="$(IsTestRun)"
399439
name: s_CreateAdoPrs
400440
displayName: Create PRs in AzureDevOps and ConfigChange
401441
env:

release/createAdoPrs.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ function clearEmptyHashValueLine(filePath) {
7878
* @param {string} description pull reqest description
7979
* @param {string[]} targetsToCommit files to add in pull request
8080
*/
81-
async function openPR(repo, project, sourceBranch, targetBranch, commitMessage, title, description, targetsToCommit) {
81+
async function openPR(repo, project, sourceBranch, targetBranch, commitMessage, title, description, targetsToCommit, dryrun = false) {
8282
console.log(`Creating PR from "${sourceBranch}" into "${targetBranch}" in the "${project}/${repo}" repo`);
8383

8484
const repoPath = path.join(INTEGRATION_DIR, repo);
8585

8686
if (!fs.existsSync(repoPath)) {
8787
const gitUrl = `https://${process.env.PAT}@${orgUrl}/${project}/_git/${repo}`;
88-
util.execInForeground(`${GIT} clone --depth 1 ${gitUrl} ${repoPath}`, null, opt.options.dryrun);
88+
util.execInForeground(`${GIT} clone --depth 1 ${gitUrl} ${repoPath}`, null, dryrun);
8989
}
9090

9191
for (const targetToCommit of targetsToCommit) {
@@ -95,7 +95,7 @@ async function openPR(repo, project, sourceBranch, targetBranch, commitMessage,
9595
const sourceFile = path.join(INTEGRATION_DIR, fileName);
9696
const targetFile = path.join(fullPath, fileName);
9797

98-
if (opt.options.dryrun) {
98+
if (dryrun) {
9999
console.log(`Fake copy file from ${sourceFile} to ${targetFile}`);
100100
} else {
101101
console.log(`Copy file from ${sourceFile} to ${targetFile}`);
@@ -105,12 +105,12 @@ async function openPR(repo, project, sourceBranch, targetBranch, commitMessage,
105105
}
106106

107107
for (const targetToCommit of targetsToCommit) {
108-
util.execInForeground(`${GIT} add ${targetToCommit}`, repoPath, opt.options.dryrun);
108+
util.execInForeground(`${GIT} add ${targetToCommit}`, repoPath, dryrun);
109109
}
110110

111-
util.execInForeground(`${GIT} checkout -b ${sourceBranch}`, repoPath, opt.options.dryrun);
112-
util.execInForeground(`${GIT} commit -m "${commitMessage}"`, repoPath, opt.options.dryrun);
113-
util.execInForeground(`${GIT} push --force origin ${sourceBranch}`, repoPath, opt.options.dryrun);
111+
util.execInForeground(`${GIT} checkout -b ${sourceBranch}`, repoPath, dryrun);
112+
util.execInForeground(`${GIT} commit -m "${commitMessage}"`, repoPath, dryrun);
113+
util.execInForeground(`${GIT} push --force origin ${sourceBranch}`, repoPath, dryrun);
114114

115115
const prefix = 'refs/heads/';
116116

@@ -129,7 +129,7 @@ async function openPR(repo, project, sourceBranch, targetBranch, commitMessage,
129129

130130
if (PR) {
131131
console.log('PR already exists');
132-
} else if (opt.options.dryrun) {
132+
} else if (dryrun) {
133133
return [-1, 'test']; // return without creating PR for test runs
134134
} else {
135135
console.log('PR does not exist; creating PR');
@@ -169,8 +169,13 @@ async function main() {
169169
util.verifyMinimumNodeVersion();
170170
util.verifyMinimumGitVersion();
171171
createIntegrationFiles(agentVersion);
172-
util.execInForeground(`${GIT} config --global user.email "${process.env.USEREMAIL}"`, null, opt.options.dryrun);
173-
util.execInForeground(`${GIT} config --global user.name "${process.env.USERNAME}"`, null, opt.options.dryrun);
172+
173+
const dryrun = (opt.options.dryrun.toString().toLowerCase() === "true");
174+
175+
console.log(`Dry run: ${dryrun}`);
176+
177+
util.execInForeground(`${GIT} config --global user.email "${process.env.USEREMAIL}"`, null, dryrun);
178+
util.execInForeground(`${GIT} config --global user.name "${process.env.USERNAME}"`, null, dryrun);
174179

175180
const sprint = await getCurrentSprint();
176181

@@ -191,7 +196,8 @@ async function main() {
191196
path.join(
192197
'DistributedTask', 'Service', 'Servicing', 'Host', 'Deployment', 'Groups', 'UpdateAgentPackage.xml'
193198
),
194-
]
199+
],
200+
dryrun
195201
);
196202

197203
const [ccPrId, ccPrLink] = await openPR(
@@ -202,7 +208,8 @@ async function main() {
202208
path.join(
203209
'tfs', `m${sprint}`, 'PipelinesAgentRelease', agentVersion, 'Publish.ps1'
204210
)
205-
]
211+
],
212+
dryrun
206213
);
207214

208215
console.log(`##vso[task.setvariable variable=AdoPrId;isOutput=true]${adoPrId}`);

0 commit comments

Comments
 (0)