From de0179ca39ff0dfe09399207e6ceabec9675095f Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 21 Nov 2022 10:20:22 +1100 Subject: [PATCH] fix: automatically merge changes to history back to master Fixes #7351. --- resources/build/increment-version.sh | 31 +++++++++++++++++++++ resources/build/version/src/fixupHistory.ts | 4 +-- resources/build/version/src/index.ts | 8 +++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/resources/build/increment-version.sh b/resources/build/increment-version.sh index c1c152ccbc..6559bce793 100755 --- a/resources/build/increment-version.sh +++ b/resources/build/increment-version.sh @@ -156,6 +156,37 @@ if [ "$action" == "commit" ]; then git checkout "$branch" hub pull-request -f --no-edit -b $base -l auto + # + # If we are on a stable-x.y branch, then we also want to merge changes to + # HISTORY.md to master. We don't want to do this for beta or alpha builds; + # beta changes will be merged to master periodically anyway. + # + if [[ "$base" =~ ^stable-[0-9]+\.[0-9]+$ ]]; then + git switch master + + # In order to avoid potential git conflicts, we run the history collater + # again on the master HISTORY.md. Note that the script always exits 1 to + # indicate it hasn't updated VERSION.md. We could tweak that in the future. + node resources/build/version/lib/index.js history --no-write-github-comment -t "$GITHUB_TOKEN" -b "$base" || true + + # If HISTORY.md has been updated, then we want to create a branch and push + # it for review + if git status --porcelain=v1 | grep -q HISTORY.md; then + # TODO: once we are sure this is stable, rename this to + # "$branch-master-history" to get automatic merges with "auto/..." branch + # name + git switch -c "chore/version-$base-$NEWVERSION-master-history" master + git add HISTORY.md + git commit -m "$message (history cherry-pick to master)" + # TODO: once we are sure this is stable, add `-l auto` to get the "auto:" + # label + hub pull-request -f --no-edit -b master + fi + + # Return to our best working branch + git switch "$branch" + fi + # # Done # diff --git a/resources/build/version/src/fixupHistory.ts b/resources/build/version/src/fixupHistory.ts index 9c3ca32b23..2807bfd948 100644 --- a/resources/build/version/src/fixupHistory.ts +++ b/resources/build/version/src/fixupHistory.ts @@ -183,7 +183,7 @@ export const sendCommentToPullRequestAndRelatedIssues = async ( */ export const fixupHistory = async ( - octokit: GitHub, base: string, force: boolean + octokit: GitHub, base: string, force: boolean, writeGithubComment: boolean ): Promise => { // @@ -213,7 +213,7 @@ export const fixupHistory = async ( // Write a comment to GitHub for each of the pulls // - if(historyResult.pulls.length > 0) { + if(writeGithubComment && historyResult.pulls.length > 0) { await sendCommentToPullRequestAndRelatedIssues(octokit, historyResult.pulls); } diff --git a/resources/build/version/src/index.ts b/resources/build/version/src/index.ts index 4e494ff4d9..3d5f896650 100644 --- a/resources/build/version/src/index.ts +++ b/resources/build/version/src/index.ts @@ -44,6 +44,12 @@ const argv = yargs 'github-pr': { description: 'Query GitHub for Pull Request number and title instead of parsing from merge commit comments (not valid with --from, --to)', type: 'boolean' + }, + + 'write-github-comment': { + description: 'Write comment to GitHub PRs for all history entries; used only with "history" command', + type: 'boolean', + default: true } }) .help() @@ -101,7 +107,7 @@ const main = async (): Promise => { if(argv._.includes('history')) { logInfo(`# Validating history for ${version}`); - changeCount = await fixupHistory(octokit, argv.base, argv.force); + changeCount = await fixupHistory(octokit, argv.base, argv.force, argv['write-github-comment']); logInfo(`# ${changeCount} change(s) found for ${version}\n`); }