diff --git a/README.md b/README.md index befc903..fd82b37 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ Fetches and creates versioned GitHub resources. body: path/to/body/file globs: - paths/to/files/to/upload-*.tgz + generate_release_notes: true ``` To get a specific version of a release: @@ -180,6 +181,11 @@ prepended with this string. This is useful for adding v in front of version numb * `globs`: *Optional.* A list of globs for files that will be uploaded alongside the created release. +* `generate_release_notes`: *Optional.* Causes GitHub to autogenerate the release notes + when creating a new release, based on the commits since the last release. + If `body` is specified, the body will be pre-pended to the automatically generated + notes. Has no effect when updating an existing release. Defaults to `false`. + ## Development ### Prerequisites @@ -200,7 +206,7 @@ Run the tests with the following commands for both `alpine` and `ubuntu` images: ```sh docker build -t github-release-resource -f dockerfiles/alpine/Dockerfile . -docker build -t github-release-resource -f dockerfiles/ubuntu/Dockerfile . +docker build -t github-release-resource -f dockerfiles/ubuntu/Dockerfile --build-arg base_image=ubuntu:latest . ``` ### Contributing diff --git a/dockerfiles/ubuntu/Dockerfile b/dockerfiles/ubuntu/Dockerfile index 02046e1..bc244b2 100644 --- a/dockerfiles/ubuntu/Dockerfile +++ b/dockerfiles/ubuntu/Dockerfile @@ -1,7 +1,7 @@ ARG base_image ARG builder_image=concourse/golang-builder -FROM ${builder_image} as builder +FROM ${builder_image} AS builder COPY . $GOPATH/src/github.com/concourse/github-release-resource ENV CGO_ENABLED 0 WORKDIR $GOPATH/src/github.com/concourse/github-release-resource diff --git a/go.mod b/go.mod index c597db9..64821c4 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/Masterminds/semver v1.5.0 github.com/cppforlife/go-semi-semantic v0.0.0-20160921010311-576b6af77ae4 github.com/golang/protobuf v1.5.2 // indirect - github.com/google/go-github/v39 v39.0.0 + github.com/google/go-github/v39 v39.2.0 github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db github.com/nxadm/tail v1.4.5 // indirect github.com/onsi/ginkgo v1.14.2 diff --git a/go.sum b/go.sum index 4d72298..9dd6874 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,8 @@ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github/v39 v39.0.0 h1:pygGA5ySwxEez1N39GnDauD0PaWWuGgayudyZAc941s= github.com/google/go-github/v39 v39.0.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE= +github.com/google/go-github/v39 v39.2.0 h1:rNNM311XtPOz5rDdsJXAp2o8F67X9FnROXTvto3aSnQ= +github.com/google/go-github/v39 v39.2.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= diff --git a/out_command.go b/out_command.go index f757249..5bf1ef1 100644 --- a/out_command.go +++ b/out_command.go @@ -63,13 +63,16 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err prerelease = request.Source.PreRelease } + generateReleaseNotes := request.Params.GenerateReleaseNotes + release := &github.RepositoryRelease{ - Name: github.String(name), - TagName: github.String(tag), - Body: github.String(body), - Draft: github.Bool(draft), - Prerelease: github.Bool(prerelease), - TargetCommitish: github.String(targetCommitish), + Name: github.String(name), + TagName: github.String(tag), + Body: github.String(body), + Draft: github.Bool(draft), + Prerelease: github.Bool(prerelease), + TargetCommitish: github.String(targetCommitish), + GenerateReleaseNotes: github.Bool(generateReleaseNotes), } existingReleases, err := c.github.ListReleases() diff --git a/out_command_test.go b/out_command_test.go index 8551ed8..67ed931 100644 --- a/out_command_test.go +++ b/out_command_test.go @@ -217,6 +217,24 @@ var _ = Describe("Out Command", func() { Ω(updatedRelease.TargetCommitish).Should(Equal(github.String("1z22f1"))) }) }) + + Context("when set to autogenerate release notes", func() { + BeforeEach(func() { + request.Params.GenerateReleaseNotes = true + }) + // See https://github.com/google/go-github/issues/2444 + It("has no effect on updating the existing release", func() { + _, err := command.Run(sourcesDir, request) + Ω(err).ShouldNot(HaveOccurred()) + + Ω(githubClient.UpdateReleaseCallCount()).Should(Equal(1)) + + updatedRelease := githubClient.UpdateReleaseArgsForCall(0) + Ω(*updatedRelease.Name).Should(Equal("v0.3.12")) + Ω(*updatedRelease.Body).Should(Equal("this is a great release")) + Ω(updatedRelease.GenerateReleaseNotes).Should(BeNil()) + }) + }) }) Context("when the release has not already been created", func() { @@ -585,5 +603,37 @@ var _ = Describe("Out Command", func() { Ω(*release.TagName).Should(Equal("version-0.3.12")) }) }) + + Context("with generate_release_notes set to false", func() { + BeforeEach(func() { + request.Params.GenerateReleaseNotes = false + }) + + It("creates a release on GitHub without autogenerated release notes", func() { + _, err := command.Run(sourcesDir, request) + Ω(err).ShouldNot(HaveOccurred()) + + Ω(githubClient.CreateReleaseCallCount()).Should(Equal(1)) + release := githubClient.CreateReleaseArgsForCall(0) + + Ω(release.GenerateReleaseNotes).Should(Equal(github.Bool(false))) + }) + }) + + Context("with generate_release_notes set to true", func() { + BeforeEach(func() { + request.Params.GenerateReleaseNotes = true + }) + + It("creates a release on GitHub with autogenerated release notes", func() { + _, err := command.Run(sourcesDir, request) + Ω(err).ShouldNot(HaveOccurred()) + + Ω(githubClient.CreateReleaseCallCount()).Should(Equal(1)) + release := githubClient.CreateReleaseArgsForCall(0) + + Ω(release.GenerateReleaseNotes).Should(Equal(github.Bool(true))) + }) + }) }) }) diff --git a/resources.go b/resources.go index d91764a..936cf33 100644 --- a/resources.go +++ b/resources.go @@ -71,11 +71,12 @@ type OutRequest struct { } type OutParams struct { - NamePath string `json:"name"` - BodyPath string `json:"body"` - TagPath string `json:"tag"` - CommitishPath string `json:"commitish"` - TagPrefix string `json:"tag_prefix"` + NamePath string `json:"name"` + BodyPath string `json:"body"` + TagPath string `json:"tag"` + CommitishPath string `json:"commitish"` + TagPrefix string `json:"tag_prefix"` + GenerateReleaseNotes bool `json:"generate_release_notes"` Globs []string `json:"globs"` }