|
| 1 | +/* |
| 2 | +Copyright 2023 The Vitess Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package release |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + "vitess.io/vitess-releaser/go/releaser" |
| 23 | + "vitess.io/vitess-releaser/go/releaser/git" |
| 24 | + "vitess.io/vitess-releaser/go/releaser/github" |
| 25 | + "vitess.io/vitess-releaser/go/releaser/logging" |
| 26 | + "vitess.io/vitess-releaser/go/releaser/pre_release" |
| 27 | +) |
| 28 | + |
| 29 | +func ReleaseNotesOnMain(state *releaser.State) (*logging.ProgressLogging, func() string) { |
| 30 | + pl := &logging.ProgressLogging{ |
| 31 | + TotalSteps: 9, |
| 32 | + } |
| 33 | + |
| 34 | + var done bool |
| 35 | + var url string |
| 36 | + return pl, func() string { |
| 37 | + defer func() { |
| 38 | + state.Issue.ReleaseNotesOnMain.Done = done |
| 39 | + state.Issue.ReleaseNotesOnMain.URL = url |
| 40 | + pl.NewStepf("Update Issue %s on GitHub", state.IssueLink) |
| 41 | + _, fn := state.UploadIssue() |
| 42 | + issueLink := fn() |
| 43 | + |
| 44 | + pl.NewStepf("Issue updated, see: %s", issueLink) |
| 45 | + }() |
| 46 | + |
| 47 | + git.CorrectCleanRepo(state.VitessRepo) |
| 48 | + nextRelease, branchName, _ := releaser.FindNextRelease(state.MajorRelease) |
| 49 | + |
| 50 | + pl.NewStepf("Fetch from git remote") |
| 51 | + remote := git.FindRemoteName(state.VitessRepo) |
| 52 | + git.ResetHard(remote, branchName) |
| 53 | + |
| 54 | + git.Checkout("main") |
| 55 | + git.ResetHard(remote, "main") |
| 56 | + |
| 57 | + prName := fmt.Sprintf("Copy `v%s` release notes on `main`", nextRelease) |
| 58 | + |
| 59 | + pl.NewStepf("Look for an existing Pull Request named '%s'", prName) |
| 60 | + if _, url = github.FindPR(state.VitessRepo, prName); url != "" { |
| 61 | + pl.TotalSteps = 5 // only 5 total steps in this situation |
| 62 | + pl.NewStepf("An opened Pull Request was found: %s", url) |
| 63 | + done = true |
| 64 | + return url |
| 65 | + } |
| 66 | + |
| 67 | + pl.NewStepf("Create new branch based on %s/main", remote) |
| 68 | + newBranchName := git.FindNewGeneratedBranch(remote, "main", "release-notes-main") |
| 69 | + |
| 70 | + pl.NewStepf("Copy release notes from %s/%s", remote, branchName) |
| 71 | + releaseNotesPath := pre_release.GetReleaseNotesDirPathForMajor(nextRelease) |
| 72 | + git.CheckoutPath(remote, branchName, releaseNotesPath) |
| 73 | + |
| 74 | + pl.NewStepf("Commit and push to branch %s", newBranchName) |
| 75 | + if git.CommitAll(fmt.Sprintf("Copy release notes from %s into main", branchName)) { |
| 76 | + pl.TotalSteps = 8 // only 8 total steps in this situation |
| 77 | + pl.NewStepf("Nothing to commit, seems like the release notes have already been copied") |
| 78 | + done = true |
| 79 | + return "" |
| 80 | + } |
| 81 | + git.Push(remote, newBranchName) |
| 82 | + |
| 83 | + pl.NewStepf("Create Pull Request") |
| 84 | + pr := github.PR{ |
| 85 | + Title: prName, |
| 86 | + Body: fmt.Sprintf("This Pull Request copies the release notes found on `%s` to keep release notes up-to-date after the `v%s` release.", branchName, nextRelease), |
| 87 | + Branch: newBranchName, |
| 88 | + Base: "main", |
| 89 | + Labels: []github.Label{{Name: "Component: General"}, {Name: "Type: Release"}}, |
| 90 | + } |
| 91 | + _, url = pr.Create(state.VitessRepo) |
| 92 | + pl.NewStepf("Pull Request created %s", url) |
| 93 | + done = true |
| 94 | + return url |
| 95 | + } |
| 96 | +} |
0 commit comments