Skip to content

Commit

Permalink
feat(summary): Add support for Github's Generate Release Notes
Browse files Browse the repository at this point in the history
  • Loading branch information
rymndhng committed Oct 29, 2021
1 parent fa96946 commit 10ad153
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 14 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,35 @@ jobs:
release_body: "When set, adds extra text to body!"
```

### Can I use Github's Generated Release Notes?

Yes you can, by setting `use-github-release-notes` to `true`. For more information, see [Automatic Release Notes](https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes).

Note, if enabling this feature:
- If you have set `release_body`, the `release_body` will be prepended to the Generated Release Notes
- Enabling this will disable the commit summary generated by this project

Example:

``` yaml
on:
push:
branches:
- master
jobs:
release-on-push:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: rymndhng/release-on-push-action@master
with:
bump_version_scheme: minor
use_github_release_notes: true
```


### Can I change the prefix `v` from the Git Tags?

Yes, you can customize this by changing the `tag_prefix`. Here's an example of
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ inputs:
description: "Maximum number of commits to add to release body"
required: false
default: 50
use_github_release_notes:
description: "When set to 'true', uses Github's Generated Release Notes instead of this plugin's release notes"
required: false
default: "false"
outputs:
tag_name:
description: 'Tag of released version'
Expand Down
37 changes: 23 additions & 14 deletions src/release_on_push_action/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
:input/max-commits (Integer/parseInt (getenv-or-throw "INPUT_MAX_COMMITS"))
:input/release-body (System/getenv "INPUT_RELEASE_BODY")
:input/tag-prefix (System/getenv "INPUT_TAG_PREFIX") ;defaults to "v", see default in action.yml
:input/use-github-release-notes (Boolean/parseBoolean (System/getenv "INPUT_USE_GITHUB_RELEASE_NOTES"))
:bump-version-scheme (assert-valid-bump-version-scheme
(try
(getenv-or-throw "INPUT_BUMP_VERSION_SCHEME")
Expand Down Expand Up @@ -99,21 +100,29 @@
next-version (semver-bump current-version bump-version-scheme)
base-commit (get-in related-data [:latest-release :target_commitish])

summary-since-last-release (->> (github/list-commits-to-base context base-commit)
;; this is a lazy sequence
commits-since-last-release (->> (github/list-commits-to-base context base-commit)
(take (:input/max-commits context))
(map github/commit-summary)
(str/join "\n"))]
{:tag_name (str (:input/tag-prefix context) next-version)
:target_commitish (:sha context)
:name (str (:input/tag-prefix context) next-version)
:body (with-out-str
(printf "Version %s\n\n" next-version)
(when-let [body (:input/release-body context)]
(println body))
(printf "### Commits\n\n")
(println summary-since-last-release))
:draft false
:prerelease false}))
(map github/commit-summary))

body (with-out-str
(printf "Version %s\n\n" next-version)
(when-let [body (:input/release-body context)]
(println body))

;; Do not include our custom commit summary if using Github Release Notes
(when-not (:input/use-github-release-notes context)
(printf "### Commits\n\n")
(doseq [commit commits-since-last-release]
(println commit))))]

{:tag_name (str (:input/tag-prefix context) next-version)
:target_commitish (:sha context)
:name (str (:input/tag-prefix context) next-version)
:body body
:draft false
:prerelease false
:generate_release_notes (:input/use-github-release-notes context)}))

(defn create-new-release! [context new-release-data]
;; Use a file because the release data may be too large for an inline curl arg
Expand Down
10 changes: 10 additions & 0 deletions test/release_on_push_action/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
:input/max-commits 5
:input/release-body ""
:input/tag-prefix ""
:input/use-github-release-notes false
:bump-version-scheme "minor"
:dry-run true})

Expand Down Expand Up @@ -211,3 +212,12 @@ Hello World
11 "- [74ffa7bf] Commit 7"
100 "- [74ffa7bf] Commit 7" ;larger number than what's available
)))))

(deftest ^:integration generate-new-release-data-with-github-generated-release-notes
(let [[ctx related-data] @fixture-project-with-release
ctx (assoc ctx :input/use-github-release-notes true)
release-data (sut/generate-new-release-data ctx related-data)]

(testing "sets options to enable Github Generated Release Notes"
(is (= true (:generate_release_notes release-data)))
(is (= "Version 0.2.0\n\n" (:body release-data))))))

0 comments on commit 10ad153

Please sign in to comment.