release-tool: automate multi-version constants into release process (#47636)

Closes [#46399](https://github.com/sourcegraph/sourcegraph/issues/46399)
Automate the MVU upgrade. Stacked on
https://github.com/sourcegraph/sourcegraph/pull/47620

I tried a few approaches, ultimately it was simplest to just have it
re-run the command for each branch. The trick is that:
1. The release branch must exist
2. We need to land this change on both main and the release branch
3. We want to land this before any subsequent commits on the release
branch that may contain migrations

## Test plan

I ran the command with some fake branch names and generated the
following PRs:
https://github.com/sourcegraph/sourcegraph/pull/47632
https://github.com/sourcegraph/sourcegraph/pull/47633

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
This commit is contained in:
coury-clark 2023-02-15 10:45:48 -07:00 committed by GitHub
parent f830b2d682
commit f489bccd77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 2 deletions

View File

@ -63,6 +63,7 @@ export type StepID =
| 'release:finalize'
| 'release:announce'
| 'release:close'
| 'release:multi-version-bake'
// util
| 'util:clear-cache'
// testing
@ -893,6 +894,53 @@ ${patchRequestIssues.map(issue => `* #${issue.number}`).join('\n')}`
await closeTrackingIssue(release)
},
},
{
id: 'release:multi-version-bake',
description:
'Bake stitched migration files into the build for a release version. Only required for minor / major versions.',
run: async config => {
const { upcoming } = await releaseVersions(config)
const releaseBranch = `${upcoming.major}.${upcoming.minor}`
const version = upcoming.version
ensureReleaseBranchUpToDate(releaseBranch)
const prConfig = {
edits: [
`git remote set-branches --add origin '${releaseBranch}'`,
`git fetch --depth 1 origin ${releaseBranch}`,
`comby -in-place 'const maxVersionString = ":[1]"' "const maxVersionString = \\"${version}\\"" internal/database/migration/shared/data/cmd/generator/consts.go`,
'cd internal/database/migration/shared && go run ./data/cmd/generator --write-frozen=false',
],
repo: 'sourcegraph',
owner: 'sourcegraph',
body: 'Update the multi version upgrade constants',
title: `${version} multi version upgrade constants`,
commitMessage: `baking multi version upgrade files for version ${version}`,
}
const sets = await createChangesets({
requiredCommands: ['comby', 'go'],
changes: [
{
...prConfig,
base: 'main',
head: `${version}-update-multi-version-upgrade`,
},
{
...prConfig,
base: releaseBranch,
head: `${version}-update-multi-version-upgrade-rb`,
},
],
dryRun: false,
})
console.log('Merge the following pull requests:\n')
for (const set of sets) {
console.log(set.pullRequestURL)
}
},
},
{
id: 'util:clear-cache',
description: 'Clear release tool cache',

View File

@ -53,7 +53,11 @@ Do the [branch cut](./index.md#release-branches) for the release:
pnpm run release release:branch-cut
```
- [ ] To support the multi-version upgrade utility, update [the `maxVersionString` constant](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24%40main+file:data/cmd/generator/consts.go+const+maxVersionString&patternType=lucky) to `$MAJOR.$MINOR.0` on the `main` branch, then cherry-pick this change into the `$MAJOR.$MINOR` branch. Bumping this version will require the `$MAJOR.$MINOR` branch to exist, and `go generate` will need to be invoked ([example](https://github.com/sourcegraph/sourcegraph/pull/43152)).
- [ ] To support the multi-version upgrade utility use the command below to bake the stitched migration files into the release branch. This requires the release branch exists (should be automated above).
```shell
pnpm run release release:multi-version-bake
```
- [ ] Merge the resulting pull requests for the multi version bake generated by the command above
Upon branch cut, create and test release candidates:

View File

@ -7,7 +7,7 @@ import (
)
// NOTE: This should be kept up-to-date with cmd/migrator/build.sh so that we "bake in"
// fallback schemas everything we support migrating to.
// fallback schemas everything we support migrating to. The release tool automates this upgrade, so don't touch this :)
const maxVersionString = "4.4.0"
// MaxVersion is the highest known released version at the time the migrator was built.