Skip to content

Commit

Permalink
Merge pull request #1789 from puerco/integrate-github-page
Browse files Browse the repository at this point in the history
Update the release GitHub page from krel
  • Loading branch information
k8s-ci-robot authored Nov 25, 2020
2 parents 9f7aa6e + b73f509 commit f77005b
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 52 deletions.
7 changes: 6 additions & 1 deletion pkg/anago/anago.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (r *Release) Run() error {
return errors.Wrap(err, "init log file")
}

logger := log.NewStepLogger(9)
logger := log.NewStepLogger(10)
logger.Infof("Using krel version:\n%s", version.Get().String())

logger.WithStep().Info("Validating options")
Expand Down Expand Up @@ -389,6 +389,11 @@ func (r *Release) Run() error {
return errors.Wrap(err, "create announcement")
}

logger.WithStep().Info("Updating GitHub release page")
if err := r.client.UpdateGitHubPage(); err != nil {
return errors.Wrap(err, "updating github page")
}

logger.WithStep().Info("Archiving release")
if err := r.client.Archive(); err != nil {
return errors.Wrap(err, "archive release")
Expand Down
81 changes: 65 additions & 16 deletions pkg/anago/anagofakes/fake_release_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions pkg/anago/anagofakes/fake_release_impl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions pkg/anago/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ type releaseClient interface {
// GitHub release page to contain the artifacts and their checksums.
CreateAnnouncement() error

// UpdateGitHubPage updates the GitHub release page to with the source code
// and release information.
UpdateGitHubPage() error

// Archive copies the release process logs to a bucket and sets private
// permissions on it.
Archive() error
Expand Down Expand Up @@ -137,6 +141,7 @@ type releaseImpl interface {
CreateAnnouncement(
options *announce.Options,
) error
UpdateGitHubPage(options *announce.GitHubPageOptions) error
PushTags(pusher *release.GitObjectPusher, tagList []string) error
PushBranches(pusher *release.GitObjectPusher, branchList []string) error
PushMainBranch(pusher *release.GitObjectPusher) error
Expand Down Expand Up @@ -251,6 +256,10 @@ func (d *defaultReleaseImpl) ArchiveRelease(options *release.ArchiverOptions) er
return release.NewArchiver(options).ArchiveRelease()
}

func (d *defaultReleaseImpl) UpdateGitHubPage(options *announce.GitHubPageOptions) error {
return announce.UpdateGitHubPage(options)
}

func (d *defaultReleaseImpl) PushTags(
pusher *release.GitObjectPusher, tagList []string,
) error {
Expand Down Expand Up @@ -451,6 +460,52 @@ func (d *DefaultRelease) CreateAnnouncement() error {
return nil
}

// UpdateGitHubPage Update the GitHub release page, uploading the
// source code
func (d *DefaultRelease) UpdateGitHubPage() error {
// Array of assets to be published in the release page
assetList := []string{
// Build the path to the kubernetes tar file:
filepath.Join(
gitRoot, // /workspace/src/k8s.io/kubernetes
fmt.Sprintf("%s-%s", release.BuildDir, d.state.versions.Prime()), // _output-v1.20.0-beta.3/
release.GCSStagePath, // gcs-stage/
d.state.versions.Prime(), // v1.20.0-beta.3
release.KubernetesTar, // kubernetes.tar.gz
) + ":Kubernetes Source Code",
}

// URL to the changelog:
changelogURL := fmt.Sprintf(
"https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-%d.%d.md",
d.state.semverBuildVersion.Major,
d.state.semverBuildVersion.Minor,
)

// Build the options set for the GitHub page
ghPageOpts := &announce.GitHubPageOptions{
AssetFiles: assetList,
Tag: d.state.versions.Prime(),
NoMock: d.options.NoMock,
UpdateIfReleaseExists: true,
Name: "Kubernetes " + d.state.versions.Prime(),
Draft: false,
Owner: git.DefaultGithubOrg,
Repo: git.DefaultGithubRepo,
// PageTemplate: , // If we use a custom template, define it here
Substitutions: map[string]string{
"intro": "See [kubernetes-announce@](https://groups.google.com/forum/#!forum/kubernetes-announce). " +
fmt.Sprintf("Additional binary downloads are linked in the [CHANGELOG](%s).", changelogURL),
"changelog": changelogURL,
},
}
// Update the release page (or simply output it during mock)
if err := d.impl.UpdateGitHubPage(ghPageOpts); err != nil {
return errors.Wrap(err, "updating GitHub release page")
}
return nil
}

// Archive stores the release artifact in a bucket along with
// its logs for long term conservation
func (d *DefaultRelease) Archive() error {
Expand Down
33 changes: 33 additions & 0 deletions pkg/anago/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,36 @@ func TestPushGitObjects(t *testing.T) {
}
}
}

func TestUpdateGitHubPage(t *testing.T) {
for _, tc := range []struct {
prepare func(*anagofakes.FakeReleaseImpl)
shouldError bool
}{
{ // success
prepare: func(*anagofakes.FakeReleaseImpl) {},
shouldError: false,
},
{ // Pushing list of branches fails
prepare: func(mock *anagofakes.FakeReleaseImpl) {
mock.UpdateGitHubPageReturns(err)
},
shouldError: true,
},
} {
opts := anago.DefaultReleaseOptions()
sut := anago.NewDefaultRelease(opts)
sut.SetState(
generateTestingReleaseState(&testStateParameters{versionsTag: &testVersionTag}),
)
mock := &anagofakes.FakeReleaseImpl{}
tc.prepare(mock)
sut.SetImpl(mock)
err := sut.UpdateGitHubPage()
if tc.shouldError {
require.NotNil(t, err)
} else {
require.Nil(t, err)
}
}
}
Loading

0 comments on commit f77005b

Please sign in to comment.