Skip to content

Commit

Permalink
Test branch cleanup for release pipeline (#4894)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aleksandrlevochkin authored Jul 29, 2024
1 parent 842df8d commit 85c4030
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 18 deletions.
52 changes: 46 additions & 6 deletions .vsts.release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# This Yaml Document has been converted by ESAI Yaml Pipeline Conversion Tool.

trigger:
branches:
include:
- '*'
paths:
include:
- release
- .azure-pipelines
- .vsts.release.yml

pr:
branches:
include:
- '*'
paths:
include:
- release
Expand Down Expand Up @@ -344,15 +356,43 @@ extends:
displayName: Delete test agent release from Github
condition: and(succeeded(), eq(variables.IsTestRun, 'True'))
# Clean up test release branch
- stage: Cleanup_Release_Branch
displayName: Cleanup Release Branch
dependsOn:
- Verify_release
- Create_Release_Branch
- Release
condition: always()
jobs:
- job: Delete_Release_Branch
displayName: Delete Release Branch
variables:
IsTestRun: $[ stageDependencies.Verify_release.Set_variables.outputs['SetReleaseVariables.isTestRun'] ]
condition: eq(variables.IsTestRun, 'True')

pool:
name: 1ES-ABTT-Shared-Pool
image: abtt-ubuntu-2204
os: linux
steps:
- checkout: self

- powershell: |
git config --global user.email "[email protected]"
git config --global user.name "azure-pipelines-bot"
git status
git -c credential.helper='!f() { echo "username=pat"; echo "password=$(GithubToken)"; };f' push origin --delete $(ReleaseBranch)
git push --delete origin v$(AgentVersion)
$testBranch = "releases/3.000.999"
$testTag = "v3.000.999"
if (git ls-remote --heads origin $testBranch) {
git -c credential.helper='!f() { echo "username=pat"; echo "password=$(GithubToken)"; };f' push origin --delete $testBranch
}
if (git ls-remote --tags origin $testTag) {
git -c credential.helper='!f() { echo "username=pat"; echo "password=$(GithubToken)"; };f' push --delete origin $testTag
}
displayName: Clean up test release branch
condition: and(succeeded(), eq(variables.IsTestRun, 'True'))
- stage: CreatePRs
dependsOn:
Expand Down Expand Up @@ -395,7 +435,7 @@ extends:
cd release
npm install
ls
node createAdoPrs.js $(AgentVersion) --dryrun=$(IsTestRun)
node createAdoPrs.js $(AgentVersion) --dryrun="$(IsTestRun)"
name: s_CreateAdoPrs
displayName: Create PRs in AzureDevOps and ConfigChange
env:
Expand Down
31 changes: 19 additions & 12 deletions release/createAdoPrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ function clearEmptyHashValueLine(filePath) {
* @param {string} description pull reqest description
* @param {string[]} targetsToCommit files to add in pull request
*/
async function openPR(repo, project, sourceBranch, targetBranch, commitMessage, title, description, targetsToCommit) {
async function openPR(repo, project, sourceBranch, targetBranch, commitMessage, title, description, targetsToCommit, dryrun = false) {
console.log(`Creating PR from "${sourceBranch}" into "${targetBranch}" in the "${project}/${repo}" repo`);

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

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

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

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

for (const targetToCommit of targetsToCommit) {
util.execInForeground(`${GIT} add ${targetToCommit}`, repoPath, opt.options.dryrun);
util.execInForeground(`${GIT} add ${targetToCommit}`, repoPath, dryrun);
}

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

const prefix = 'refs/heads/';

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

if (PR) {
console.log('PR already exists');
} else if (opt.options.dryrun) {
} else if (dryrun) {
return [-1, 'test']; // return without creating PR for test runs
} else {
console.log('PR does not exist; creating PR');
Expand Down Expand Up @@ -169,8 +169,13 @@ async function main() {
util.verifyMinimumNodeVersion();
util.verifyMinimumGitVersion();
createIntegrationFiles(agentVersion);
util.execInForeground(`${GIT} config --global user.email "${process.env.USEREMAIL}"`, null, opt.options.dryrun);
util.execInForeground(`${GIT} config --global user.name "${process.env.USERNAME}"`, null, opt.options.dryrun);

const dryrun = (opt.options.dryrun.toString().toLowerCase() === "true");

console.log(`Dry run: ${dryrun}`);

util.execInForeground(`${GIT} config --global user.email "${process.env.USEREMAIL}"`, null, dryrun);
util.execInForeground(`${GIT} config --global user.name "${process.env.USERNAME}"`, null, dryrun);

const sprint = await getCurrentSprint();

Expand All @@ -191,7 +196,8 @@ async function main() {
path.join(
'DistributedTask', 'Service', 'Servicing', 'Host', 'Deployment', 'Groups', 'UpdateAgentPackage.xml'
),
]
],
dryrun
);

const [ccPrId, ccPrLink] = await openPR(
Expand All @@ -202,7 +208,8 @@ async function main() {
path.join(
'tfs', `m${sprint}`, 'PipelinesAgentRelease', agentVersion, 'Publish.ps1'
)
]
],
dryrun
);

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

0 comments on commit 85c4030

Please sign in to comment.