Skip to content

Commit

Permalink
Add release notes to release command
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Dec 6, 2017
1 parent 6658598 commit 9e77568
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
6 changes: 4 additions & 2 deletions go/bzl/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bzl

import (
"fmt"
"github.com/urfave/cli"
"github.com/bzl-io/bzl/bazel"
"github.com/bzl-io/bzl/command/install"
Expand All @@ -11,6 +12,7 @@ import (

// Will be replaced at link time to `git rev-parse HEAD`
var BUILD_SCM_REVISION = "0000000000000000000000000000000000000000"
var BUILD_SCM_DATE = "0000-00-00"

// App embeds an urfave/cli.App
type App struct {
Expand All @@ -25,8 +27,8 @@ func New() *App {
// Create Cli inner app
app := cli.NewApp()
app.EnableBashCompletion = true
app.Usage = "A candy wrapper for the Bazel build tool"
app.Version = BUILD_SCM_REVISION
app.Usage = "A wrapper for the Bazel build tool"
app.Version = fmt.Sprintf("%s (%s)", BUILD_SCM_REVISION, BUILD_SCM_DATE)

// Global flags for bzl app
app.Flags = []cli.Flag{
Expand Down
25 changes: 24 additions & 1 deletion go/bzl/command/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/golang/sync/errgroup"
"github.com/davecgh/go-spew/spew"
"io"
"io/ioutil"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -47,6 +48,10 @@ var Command = &cli.Command{
Name: "tag",
Usage: "Tag name for the release",
},
cli.StringFlag{
Name: "notes",
Usage: "Release notes filename (a path to markdown file)",
},
cli.StringFlag{
Name: "commit",
Usage: "Commit ID for the release",
Expand Down Expand Up @@ -240,19 +245,34 @@ func uploadRelease(c *cli.Context, files []string) (*github.RepositoryRelease, e
if commit == "" {
return nil, errors.New("--commit is required when publishing a release")
}

notes, err := getReleaseNotes(c.String("notes"))
if err != nil {
return nil, err
}
fmt.Println("Uploading assets for release", tag, "...")

client := gh.Client()

req := &github.RepositoryRelease{
TagName: &tag,
TargetCommitish: &commit,
Body: &notes,
}

release, err := createRelease(c, client, req, files)
return release, err
}

// Read the given filename into a string. Return err if any io error
// occured.
func getReleaseNotes(filename string) (string, error) {
bytes, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
return string(bytes), nil
}

func createRelease(c *cli.Context, client *github.Client, req *github.RepositoryRelease, files []string) (*github.RepositoryRelease, error) {
ctx := context.Background()
if c.Bool("dry_run") {
Expand All @@ -264,6 +284,9 @@ func createRelease(c *cli.Context, client *github.Client, req *github.Repository
if res.StatusCode == 404 {
fmt.Fprintf(os.Stderr, "Github responded with 404 for %s/%s; this may represent an authentication error. Confirm that the env vars BZL_GH_USERNAME and BZL_GH_PASSWORD are set with PUSH access to this repository (https://developer.github.com/v3/troubleshooting/).\n", c.String("owner"), c.String("repo"))
}
if res.StatusCode == 422 {
fmt.Fprintf(os.Stderr, "Github responded with 422 (validation Failed). This can occur for multiple reasons, but one thing to check is that the target --commit actually exists at the remote repository.\n")
}
return nil, cli.NewExitError(fmt.Sprintf("Create release failed: %v", err), 1)
}

Expand Down
7 changes: 7 additions & 0 deletions tools/get_workspace_status
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ then
fi
echo "BUILD_SCM_REVISION ${git_rev}"

git_date=$(git log -1 --date=short --pretty=format:%cd)
if [[ $? != 0 ]];
then
exit 1
fi
echo "BUILD_SCM_DATE ${git_date}"

# Check whether there are any uncommited changes
git diff-index --quiet HEAD --
if [[ $? == 0 ]];
Expand Down

0 comments on commit 9e77568

Please sign in to comment.