Skip to content

Commit 2dfad92

Browse files
committed
add support for loading release body from a path. fixes: #2
1 parent cf33f83 commit 2dfad92

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ A common case for GitHub releases is to upload your binary after its been valida
4242
Use the `with.files` input to declare a comma-separated list of glob expressions matching the files
4343
you wish to upload to GitHub releases. If you'd like you can just list the files by name directly.
4444

45+
Below is an example of uploading a single asset named `Release.txt`
46+
4547
```yaml
4648
name: Main
4749
@@ -66,18 +68,49 @@ jobs:
6668
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6769
```
6870

71+
### 📝 External release notes
72+
73+
Many systems exist that can help generate release notes for you. This action supports
74+
loading release notes from a path in your repository's build to allow for the flexibility
75+
of using any changelog generator for your releases, including a human 👩‍💻
76+
77+
```yaml
78+
name: Main
79+
80+
on: push
81+
82+
jobs:
83+
build:
84+
runs-on: ubuntu-latest
85+
steps:
86+
- name: Checkout
87+
uses: actions/checkout@master
88+
- name: Generate Changeload
89+
run: echo "# Good things have arrived" > ${{ github.workflow }}-CHANGELOG.txt
90+
- name: Release
91+
uses: docker://softprops/action-gh-release
92+
if: startsWith(github.ref, 'refs/tags/')
93+
with:
94+
body_path: ${{ github.workflow }}-CHANGELOG.txt
95+
env:
96+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
```
98+
6999
### 💅 Customizing
70100

71101
#### inputs
72102

73103
The following are optional as `step.with` keys
74104

75-
| Name | Type | Description |
76-
|---------|---------|---------------------------------------------------------------|
77-
| `body` | String | Text communicating notable changes in this release |
78-
| `draft` | Boolean | Indicator of whether or not this release is a draft |
79-
| `files` | String | Comma-delimited globs of paths to assets to upload for release|
80-
| `name` | String | Name of the release. defaults to tag name |
105+
| Name | Type | Description |
106+
|-------------|---------|-----------------------------------------------------------------|
107+
| `body` | String | Text communicating notable changes in this release |
108+
| `body_path` | String | Path to load text communicating notable changes in this release |
109+
| `draft` | Boolean | Indicator of whether or not this release is a draft |
110+
| `files` | String | Comma-delimited globs of paths to assets to upload for release |
111+
| `name` | String | Name of the release. defaults to tag name |
112+
113+
💡When providing a `body` and `body_path` at the same time, `body_path` will be attempted first, then falling back on `body` if the path can not be read from.
81114

82115
#### environment variables
83116

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ inputs:
77
description: 'Note-worthy description of changes in release'
88
required: false
99
default: 'empty'
10+
body-path:
11+
description: 'Path to load note-worthy description of changes in release from'
12+
required: false
13+
default: 'empty'
1014
name:
1115
description: 'Gives the release a custom name'
1216
required: false

src/main.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde::Deserialize;
77
use std::{
88
error::Error,
99
ffi::OsStr,
10-
fs::File,
10+
fs::{read_to_string, File},
1111
path::{Path, PathBuf},
1212
};
1313

@@ -22,6 +22,7 @@ struct Config {
2222
// user provided
2323
input_name: Option<String>,
2424
input_body: Option<String>,
25+
input_body_path: Option<PathBuf>,
2526
input_files: Option<Vec<String>>,
2627
input_draft: Option<bool>,
2728
}
@@ -32,16 +33,20 @@ impl Into<Release> for Config {
3233
github_ref,
3334
input_name,
3435
input_body,
36+
input_body_path,
3537
input_draft,
3638
..
3739
} = self;
3840
let tag_name = github_ref.trim_start_matches("refs/tags/").to_string();
3941
let name = input_name.clone().or_else(|| Some(tag_name.clone()));
4042
let draft = input_draft;
43+
let body = input_body_path
44+
.and_then(|path| read_to_string(path).ok())
45+
.or_else(|| input_body.clone());
4146
Release {
4247
tag_name,
4348
name,
44-
body: input_body.clone(),
49+
body,
4550
draft,
4651
}
4752
}
@@ -163,6 +168,20 @@ mod tests {
163168
..Release::default()
164169
},
165170
),
171+
(
172+
Config {
173+
github_ref: "refs/tags/v1.0.0".into(),
174+
input_body: Some("fallback".into()),
175+
input_body_path: Some("tests/data/foo/bar.txt".into()),
176+
..Config::default()
177+
},
178+
Release {
179+
tag_name: "v1.0.0".into(),
180+
name: Some("v1.0.0".into()),
181+
body: Some("release me".into()),
182+
..Release::default()
183+
},
184+
),
166185
] {
167186
assert_eq!(expect, conf.into());
168187
}
@@ -193,13 +212,15 @@ mod tests {
193212
("INPUT_BODY".into(), ":)".into()),
194213
("INPUT_FILES".into(), "*.md".into()),
195214
("INPUT_DRAFT".into(), "true".into()),
215+
("INPUT_BODY_PATH".into(), "tests/data/foo/bar.txt".into()),
196216
],
197217
Config {
198218
github_token: "123".into(),
199219
github_ref: "refs/tags/v1.0.0".into(),
200220
github_repository: "foo/bar".into(),
201221
input_name: Some("test release".into()),
202222
input_body: Some(":)".into()),
223+
input_body_path: Some("tests/data/foo/bar.txt".into()),
203224
input_files: Some(vec!["*.md".into()]),
204225
input_draft: Some(true),
205226
},

0 commit comments

Comments
 (0)