add support for loading release body from a path. fixes: #2
This commit is contained in:
parent
cf33f83220
commit
2dfad92b71
37
README.md
37
README.md
@ -42,6 +42,8 @@ A common case for GitHub releases is to upload your binary after its been valida
|
|||||||
Use the `with.files` input to declare a comma-separated list of glob expressions matching the files
|
Use the `with.files` input to declare a comma-separated list of glob expressions matching the files
|
||||||
you wish to upload to GitHub releases. If you'd like you can just list the files by name directly.
|
you wish to upload to GitHub releases. If you'd like you can just list the files by name directly.
|
||||||
|
|
||||||
|
Below is an example of uploading a single asset named `Release.txt`
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: Main
|
name: Main
|
||||||
|
|
||||||
@ -66,6 +68,34 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 📝 External release notes
|
||||||
|
|
||||||
|
Many systems exist that can help generate release notes for you. This action supports
|
||||||
|
loading release notes from a path in your repository's build to allow for the flexibility
|
||||||
|
of using any changelog generator for your releases, including a human 👩💻
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: Main
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Generate Changeload
|
||||||
|
run: echo "# Good things have arrived" > ${{ github.workflow }}-CHANGELOG.txt
|
||||||
|
- name: Release
|
||||||
|
uses: docker://softprops/action-gh-release
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
body_path: ${{ github.workflow }}-CHANGELOG.txt
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
### 💅 Customizing
|
### 💅 Customizing
|
||||||
|
|
||||||
#### inputs
|
#### inputs
|
||||||
@ -73,12 +103,15 @@ jobs:
|
|||||||
The following are optional as `step.with` keys
|
The following are optional as `step.with` keys
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|---------|---------|---------------------------------------------------------------|
|
|-------------|---------|-----------------------------------------------------------------|
|
||||||
| `body` | String | Text communicating notable changes in this release |
|
| `body` | String | Text communicating notable changes in this release |
|
||||||
|
| `body_path` | String | Path to load text communicating notable changes in this release |
|
||||||
| `draft` | Boolean | Indicator of whether or not this release is a draft |
|
| `draft` | Boolean | Indicator of whether or not this release is a draft |
|
||||||
| `files` | String | Comma-delimited globs of paths to assets to upload for release|
|
| `files` | String | Comma-delimited globs of paths to assets to upload for release |
|
||||||
| `name` | String | Name of the release. defaults to tag name |
|
| `name` | String | Name of the release. defaults to tag name |
|
||||||
|
|
||||||
|
💡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.
|
||||||
|
|
||||||
#### environment variables
|
#### environment variables
|
||||||
|
|
||||||
The following are *required* as `step.env` keys
|
The following are *required* as `step.env` keys
|
||||||
|
@ -7,6 +7,10 @@ inputs:
|
|||||||
description: 'Note-worthy description of changes in release'
|
description: 'Note-worthy description of changes in release'
|
||||||
required: false
|
required: false
|
||||||
default: 'empty'
|
default: 'empty'
|
||||||
|
body-path:
|
||||||
|
description: 'Path to load note-worthy description of changes in release from'
|
||||||
|
required: false
|
||||||
|
default: 'empty'
|
||||||
name:
|
name:
|
||||||
description: 'Gives the release a custom name'
|
description: 'Gives the release a custom name'
|
||||||
required: false
|
required: false
|
||||||
|
25
src/main.rs
25
src/main.rs
@ -7,7 +7,7 @@ use serde::Deserialize;
|
|||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
fs::File,
|
fs::{read_to_string, File},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -22,6 +22,7 @@ struct Config {
|
|||||||
// user provided
|
// user provided
|
||||||
input_name: Option<String>,
|
input_name: Option<String>,
|
||||||
input_body: Option<String>,
|
input_body: Option<String>,
|
||||||
|
input_body_path: Option<PathBuf>,
|
||||||
input_files: Option<Vec<String>>,
|
input_files: Option<Vec<String>>,
|
||||||
input_draft: Option<bool>,
|
input_draft: Option<bool>,
|
||||||
}
|
}
|
||||||
@ -32,16 +33,20 @@ impl Into<Release> for Config {
|
|||||||
github_ref,
|
github_ref,
|
||||||
input_name,
|
input_name,
|
||||||
input_body,
|
input_body,
|
||||||
|
input_body_path,
|
||||||
input_draft,
|
input_draft,
|
||||||
..
|
..
|
||||||
} = self;
|
} = self;
|
||||||
let tag_name = github_ref.trim_start_matches("refs/tags/").to_string();
|
let tag_name = github_ref.trim_start_matches("refs/tags/").to_string();
|
||||||
let name = input_name.clone().or_else(|| Some(tag_name.clone()));
|
let name = input_name.clone().or_else(|| Some(tag_name.clone()));
|
||||||
let draft = input_draft;
|
let draft = input_draft;
|
||||||
|
let body = input_body_path
|
||||||
|
.and_then(|path| read_to_string(path).ok())
|
||||||
|
.or_else(|| input_body.clone());
|
||||||
Release {
|
Release {
|
||||||
tag_name,
|
tag_name,
|
||||||
name,
|
name,
|
||||||
body: input_body.clone(),
|
body,
|
||||||
draft,
|
draft,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,6 +168,20 @@ mod tests {
|
|||||||
..Release::default()
|
..Release::default()
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
Config {
|
||||||
|
github_ref: "refs/tags/v1.0.0".into(),
|
||||||
|
input_body: Some("fallback".into()),
|
||||||
|
input_body_path: Some("tests/data/foo/bar.txt".into()),
|
||||||
|
..Config::default()
|
||||||
|
},
|
||||||
|
Release {
|
||||||
|
tag_name: "v1.0.0".into(),
|
||||||
|
name: Some("v1.0.0".into()),
|
||||||
|
body: Some("release me".into()),
|
||||||
|
..Release::default()
|
||||||
|
},
|
||||||
|
),
|
||||||
] {
|
] {
|
||||||
assert_eq!(expect, conf.into());
|
assert_eq!(expect, conf.into());
|
||||||
}
|
}
|
||||||
@ -193,6 +212,7 @@ mod tests {
|
|||||||
("INPUT_BODY".into(), ":)".into()),
|
("INPUT_BODY".into(), ":)".into()),
|
||||||
("INPUT_FILES".into(), "*.md".into()),
|
("INPUT_FILES".into(), "*.md".into()),
|
||||||
("INPUT_DRAFT".into(), "true".into()),
|
("INPUT_DRAFT".into(), "true".into()),
|
||||||
|
("INPUT_BODY_PATH".into(), "tests/data/foo/bar.txt".into()),
|
||||||
],
|
],
|
||||||
Config {
|
Config {
|
||||||
github_token: "123".into(),
|
github_token: "123".into(),
|
||||||
@ -200,6 +220,7 @@ mod tests {
|
|||||||
github_repository: "foo/bar".into(),
|
github_repository: "foo/bar".into(),
|
||||||
input_name: Some("test release".into()),
|
input_name: Some("test release".into()),
|
||||||
input_body: Some(":)".into()),
|
input_body: Some(":)".into()),
|
||||||
|
input_body_path: Some("tests/data/foo/bar.txt".into()),
|
||||||
input_files: Some(vec!["*.md".into()]),
|
input_files: Some(vec!["*.md".into()]),
|
||||||
input_draft: Some(true),
|
input_draft: Some(true),
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user