From 122f5de70c6f09a3615a5657a68180978de54c7e Mon Sep 17 00:00:00 2001 From: Roman-Shchukin <111063382+Roman-Shchukin@users.noreply.github.com> Date: Mon, 23 Jan 2023 14:57:09 +0100 Subject: [PATCH] cherry-pick RHEL6 skip/release only --- .azure-pipelines/pipeline.yml | 17 ++++---- .vsts.ci.yml | 4 ++ .vsts.release.yml | 5 +++ release/createAdoPrs.js | 24 +++++++++++- release/fillReleaseNotesTemplate.js | 61 +++++++++++++++++++++++++++-- 5 files changed, 99 insertions(+), 12 deletions(-) diff --git a/.azure-pipelines/pipeline.yml b/.azure-pipelines/pipeline.yml index 4e4f3eec41..b4d31a9d52 100644 --- a/.azure-pipelines/pipeline.yml +++ b/.azure-pipelines/pipeline.yml @@ -26,6 +26,9 @@ parameters: - name: skipRhelRelease type: boolean default: true +- name: releaseRhelOnly + type: boolean + default: false # Targets - name: win_x64 @@ -66,7 +69,7 @@ stages: jobs: # Windows (x64) - - ${{ if parameters.win_x64 }}: + - ${{ if and(parameters.win_x64, not(parameters.releaseRhelOnly)) }}: - template: build-jobs.yml parameters: jobName: build_windows_x64 @@ -86,7 +89,7 @@ stages: buildAlternatePackage: ${{ parameters.buildAlternatePackage }} # Windows (x86) - - ${{ if parameters.win_x86 }}: + - ${{ if and(parameters.win_x86, not(parameters.releaseRhelOnly)) }}: - template: build-jobs.yml parameters: jobName: build_windows_x86 @@ -104,7 +107,7 @@ stages: buildAlternatePackage: ${{ parameters.buildAlternatePackage }} # Linux (x64) - - ${{ if parameters.linux_x64 }}: + - ${{ if and(parameters.linux_x64, not(parameters.releaseRhelOnly)) }}: - template: build-jobs.yml parameters: jobName: build_linux_x64 @@ -122,7 +125,7 @@ stages: buildAlternatePackage: ${{ parameters.buildAlternatePackage }} # Linux (ARM) - - ${{ if parameters.linux_arm }}: + - ${{ if and(parameters.linux_arm, not(parameters.releaseRhelOnly)) }}: - template: build-jobs.yml parameters: jobName: build_linux_arm @@ -141,7 +144,7 @@ stages: buildAlternatePackage: ${{ parameters.buildAlternatePackage }} # Linux (ARM64) - - ${{ if parameters.linux_arm64 }}: + - ${{ if and(parameters.linux_arm64, not(parameters.releaseRhelOnly)) }}: - template: build-jobs.yml parameters: jobName: build_linux_arm64 @@ -161,7 +164,7 @@ stages: buildAlternatePackage: ${{ parameters.buildAlternatePackage }} # RHEL6 (x64) - - ${{ if and(parameters.rhel6_x64, not(skipRhelRelease)) }}: + - ${{ if and(parameters.rhel6_x64, not(parameters.skipRhelRelease), parameters.releaseRhelOnly) }}: - template: build-jobs.yml parameters: jobName: build_rhel6_x64 @@ -180,7 +183,7 @@ stages: buildAlternatePackage: ${{ parameters.buildAlternatePackage }} # macOS x64 - - ${{ if parameters.macOS_x64 }}: + - ${{ if and(parameters.macOS_x64, not(parameters.releaseRhelOnly)) }}: - template: build-jobs.yml parameters: jobName: build_osx diff --git a/.vsts.ci.yml b/.vsts.ci.yml index ce8894e6ce..a7e3c7d5ae 100644 --- a/.vsts.ci.yml +++ b/.vsts.ci.yml @@ -27,6 +27,9 @@ parameters: type: boolean displayName: macOS (x64) default: true +- name: skipRhelRelease + type: boolean + default: true pr: branches: @@ -42,6 +45,7 @@ extends: componentDetection: ${{ eq(variables['Build.Reason'], 'PullRequest') }} publishArtifacts: ${{ ne(variables['Build.Reason'], 'PullRequest') }} buildAlternatePackage: false + skipRhelRelease: ${{ parameters.skipRhelRelease }} win_x64: ${{ parameters.win_x64 }} win_x86: ${{ parameters.win_x86 }} linux_x64: ${{ parameters.linux_x64 }} diff --git a/.vsts.release.yml b/.vsts.release.yml index bbd3b831a2..3b660cabbd 100644 --- a/.vsts.release.yml +++ b/.vsts.release.yml @@ -20,6 +20,10 @@ parameters: type: boolean default: true displayName: Skip RHEL Release +- name: releaseRhelOnly + type: boolean + default: false + displayName: Release RHEL Only - name: onlyGitHubRelease type: boolean @@ -38,6 +42,7 @@ extends: sign: true publishArtifacts: true skipRhelRelease: ${{ parameters.skipRhelRelease }} + releaseRhelOnly: ${{ parameters.releaseRhelOnly }} preBuildStages: - ${{ if and(not(parameters.buildStageOnly), eq(variables['Build.SourceBranch'], 'refs/heads/master')) }}: diff --git a/release/createAdoPrs.js b/release/createAdoPrs.js index 0015739b7a..4905ae0595 100644 --- a/release/createAdoPrs.js +++ b/release/createAdoPrs.js @@ -30,17 +30,37 @@ const connection = new azdev.WebApi('https://dev.azure.com/mseng', authHandler); */ function createIntegrationFiles(newRelease) { + const xmlFilePath = path.join(INTEGRATION_DIR, 'InstallAgentPackage.xml') fs.mkdirSync(INTEGRATION_DIR, { recursive: true }); util.fillAgentParameters( path.join(__dirname, '..', 'src', 'Misc', 'InstallAgentPackage.template.xml'), - path.join(INTEGRATION_DIR, 'InstallAgentPackage.xml'), + xmlFilePath, newRelease ); + clearEmptyHashValueLine(xmlFilePath); + clearEmptyXmlNodes(xmlFilePath); + + const publishScriptFilePath = path.join(INTEGRATION_DIR, 'Publish.ps1') util.fillAgentParameters( path.join(__dirname, '..', 'src', 'Misc', 'Publish.template.ps1'), - path.join(INTEGRATION_DIR, 'Publish.ps1'), + publishScriptFilePath, newRelease ); + clearEmptyHashValueLine(publishScriptFilePath); +} + +function clearEmptyXmlNodes(filePath) { + var xmlFile = fs.readFileSync(filePath, 'utf-8'); + while (xmlFile.length != (xmlFile = xmlFile.replace(/\s*<[\w\s="]+>\n*\s*<\/[\w\s="]+>/g, "")).length) { + } + fs.writeFileSync(filePath, xmlFile); +} + +function clearEmptyHashValueLine(filePath) { + const text = fs.readFileSync(filePath, 'utf-8'); + const lines = text.split('\n'); + const modifiedLines = lines.filter((line) => !line.includes('')); + fs.writeFileSync(filePath, modifiedLines.join('\n').replace(/\n\r(\n\r)+/g, '\n\r')); } function commitAndPush(directory, release, branch) diff --git a/release/fillReleaseNotesTemplate.js b/release/fillReleaseNotesTemplate.js index b2a49775d4..42c2325e42 100644 --- a/release/fillReleaseNotesTemplate.js +++ b/release/fillReleaseNotesTemplate.js @@ -21,12 +21,66 @@ function addHashesToReleaseNotes(releaseNotes) { // Inside package column, we have the package name inside the square brackets const packageName = packageColumn.substring(packageColumn.indexOf('[') + 1, packageColumn.indexOf(']')); - return line.replace('', hashes[packageName]); + if (hashes[packageName]) + return line.replace('', hashes[packageName]); + else + return line; }); return modifiedLines.join('\n'); } +/** + * + * @param {*} releaseNotes Release notes template text content + * @returns Release notes where not filling in lines is removed + */ +function removeMissingBuild(releaseNotes) { + var buildNames = []; + var buildDescriptionIndexes = []; + + const lines = releaseNotes.split('\n'); + lines.forEach((line) => { + if (line.includes('')) { + buildNames.push(line.substring(line.indexOf('|') + 1, line.indexOf('|', line.indexOf('|') + 1)).trim()); + } + }); + + for (var i = 0; i < lines.length; i++) { + if (containBuildDescriptionHeader(lines[i], buildNames) !== -1) { + var endIndex = -1; + var numberOfOccurrences = 0; + buildDescriptionIndexes.push(i - 1); // add empty string before description index + buildDescriptionIndexes.push(i); + while (i < lines.length && endIndex === -1) + { + i++; + buildDescriptionIndexes.push(i); + if (lines[i].indexOf('```') !== -1) { + numberOfOccurrences++; + if (numberOfOccurrences === 2) { + endIndex = i; + } + } + } + } + } + + return lines + .filter((line, idx) => line.indexOf('') === -1 && buildDescriptionIndexes.indexOf(idx) === -1) + .join('\n'); +} + +/** + * + * @param {*} line Line of release notes + * @param {*} buildNames List of build names + * @returns index of buildescription header + */ +function containBuildDescriptionHeader(line, buildNames) { + return buildNames.findIndex(bn => line.indexOf('## ' + bn) >= 0); +} + /** * @param {string} releaseNotes Release notes template text content * @param {string} agentVersion Agent version, e.g. 2.193.0 @@ -51,8 +105,9 @@ function main() { const releaseNotes = fs.readFileSync(releaseNotesPath, 'utf-8'); const releaseNotesWithAgentVersion = addAgentVersionToReleaseNotes(releaseNotes, agentVersion); - const filledReleaseNotes = addHashesToReleaseNotes(releaseNotesWithAgentVersion); - fs.writeFileSync(releaseNotesPath, filledReleaseNotes); + const filledReleaseNotes = addHashesToReleaseNotes(releaseNotesWithAgentVersion); + const cleanedReleaseNotes = removeMissingBuild(filledReleaseNotes); + fs.writeFileSync(releaseNotesPath, cleanedReleaseNotes); } main();