Compare commits

...

8 Commits

Author SHA1 Message Date
2984051a42 update readme 2019-09-17 23:33:44 +09:00
a95bad53b2 add support for prereleases. fixes #17 2019-09-17 23:30:36 +09:00
bd839f3b8f Merge pull request #18 from softprops/newline-delimited-assets
add support for multi-line delimited assets
2019-09-17 23:23:56 +09:00
e812c4aca6 tabs to spaces 2019-09-17 23:22:34 +09:00
615fb448a2 changelog 2019-09-17 23:21:28 +09:00
77f9a4f575 update inputs.files.description 2019-09-17 23:16:32 +09:00
3af8783d41 support multi-line delimited assets. fixes #15 2019-09-17 23:14:30 +09:00
a6281eb824 Merge pull request #16 from softprops/draft-merger
Draft merger
2019-09-17 19:39:58 +09:00
8 changed files with 119 additions and 11 deletions

View File

@ -5,6 +5,25 @@
GitHub's api doesn't explicitly have a way of fetching a draft release by tag name which caused draft releases to appear as separate releases when used in a build matrix. GitHub's api doesn't explicitly have a way of fetching a draft release by tag name which caused draft releases to appear as separate releases when used in a build matrix.
This is now fixed. This is now fixed.
* Add support for newline-delimited asset list [#18](https://github.com/softprops/action-gh-release/pull/18)
GitHub actions inputs don't inherently support lists of things and one might like to append a list of files to include in a release. Previously this was possible using a comma-delimited list of asset path patterns to upload. You can now provide these as a newline delimieted list for better readability
```yaml
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
filea.txt
fileb.txt
filec.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
* Add support for prerelease annotated GitHub releases with the new input field `with.prerelease: true`
--- ---
## 0.1.1 ## 0.1.1

View File

@ -65,7 +65,7 @@ You can can configure a number of options for your
GitHub release and all are optional. GitHub release and all are optional.
A common case for GitHub releases is to upload your binary after its been validated and packaged. A common case for GitHub releases is to upload your binary after its been validated and packaged.
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 newline-delimited 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` Below is an example of uploading a single asset named `Release.txt`
@ -94,6 +94,36 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
``` ```
Below is an example of uploading more than one asset with a GitHub release
```yaml
name: Main
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Build
run: echo ${{ github.sha }} > Release.txt
- name: Test
run: cat Release.txt
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
Release.txt
LICENSE
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
> **⚠️ Note:** Notice the `|` in the yaml syntax above ☝️. That let's you effectively declare a multi-line yaml string. You can learn more about multi-line yaml syntax [here](https://yaml-multiline.info)
### 📝 External release notes ### 📝 External release notes
Many systems exist that can help generate release notes for you. This action supports Many systems exist that can help generate release notes for you. This action supports
@ -133,7 +163,8 @@ The following are optional as `step.with` keys
| `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 | | `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 | | `prerelease`| Boolean | Indicator of whether or not is a prerelease |
| `files` | String | Newline-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. 💡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.

View File

@ -1,7 +1,36 @@
import { isTag, paths } from "../src/util"; import { isTag, paths, parseConfig, parseInputFiles } from "../src/util";
import * as assert from "assert"; import * as assert from "assert";
describe("util", () => { describe("util", () => {
describe("parseInputFiles", () => {
it("parses empty strings", () => {
assert.deepStrictEqual(parseInputFiles(""), []);
});
it("parses comma-delimited strings", () => {
assert.deepStrictEqual(parseInputFiles("foo,bar"), ["foo", "bar"]);
});
it("parses newline and comma-delimited (and then some)", () => {
assert.deepStrictEqual(
parseInputFiles("foo,bar\nbaz,boom,\n\ndoom,loom "),
["foo", "bar", "baz", "boom", "doom", "loom"]
);
});
});
describe("parseConfig", () => {
it("parses basic config", () => {
assert.deepStrictEqual(parseConfig({}), {
github_ref: "",
github_repository: "",
github_token: "",
input_body: undefined,
input_body_path: undefined,
input_draft: false,
input_prerelease: false,
input_files: [],
input_name: undefined
});
});
});
describe("isTag", () => { describe("isTag", () => {
it("returns true for tags", async () => { it("returns true for tags", async () => {
assert.equal(isTag("refs/tags/foo"), true); assert.equal(isTag("refs/tags/foo"), true);

View File

@ -13,10 +13,13 @@ inputs:
description: 'Gives the release a custom name. Defaults to tag name' description: 'Gives the release a custom name. Defaults to tag name'
required: false required: false
draft: draft:
description: 'Creates a draft release' description: 'Creates a draft release. Defaults to false'
required: false
prerelease:
description: 'Identify the release as a prerelease. Defaults to false'
required: false required: false
files: files:
description: 'Comma-delimited list of path globs for asset files to upload' description: 'Newline-delimited list of path globs for asset files to upload'
required: false required: false
env: env:
'GITHUB_TOKEN': 'As provided by Github Actions' 'GITHUB_TOKEN': 'As provided by Github Actions'

View File

@ -100,6 +100,7 @@ exports.release = (config, releaser) => __awaiter(void 0, void 0, void 0, functi
const name = config.input_name || tag; const name = config.input_name || tag;
const body = config.input_body; const body = config.input_body;
const draft = config.input_draft; const draft = config.input_draft;
const prerelease = config.input_prerelease;
console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`); console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`);
let release = yield releaser.createRelease({ let release = yield releaser.createRelease({
owner, owner,
@ -107,7 +108,8 @@ exports.release = (config, releaser) => __awaiter(void 0, void 0, void 0, functi
tag_name, tag_name,
name, name,
body, body,
draft draft,
prerelease
}); });
return release.data; return release.data;
} }

View File

@ -9,6 +9,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const glob = __importStar(require("glob")); const glob = __importStar(require("glob"));
const fs_1 = require("fs"); const fs_1 = require("fs");
exports.parseInputFiles = (files) => {
return files.split(/\r?\n/).reduce((acc, line) => acc
.concat(line.split(","))
.filter(pat => pat)
.map(pat => pat.trim()), []);
};
exports.parseConfig = (env) => { exports.parseConfig = (env) => {
return { return {
github_token: env.GITHUB_TOKEN || "", github_token: env.GITHUB_TOKEN || "",
@ -17,8 +23,9 @@ exports.parseConfig = (env) => {
input_name: env.INPUT_NAME, input_name: env.INPUT_NAME,
input_body: env.INPUT_BODY, input_body: env.INPUT_BODY,
input_body_path: env.INPUT_BODY_PATH, input_body_path: env.INPUT_BODY_PATH,
input_files: (env.INPUT_FILES || "").split(","), input_files: exports.parseInputFiles(env.INPUT_FILES || ""),
input_draft: env.INPUT_DRAFT === "true" input_draft: env.INPUT_DRAFT === "true",
input_prerelease: env.INPUT_PRERELEASE == "true"
}; };
}; };
exports.paths = (patterns) => { exports.paths = (patterns) => {

View File

@ -31,6 +31,7 @@ export interface Releaser {
name: string; name: string;
body: string | undefined; body: string | undefined;
draft: boolean | undefined; draft: boolean | undefined;
prerelease: boolean | undefined;
}): Promise<{ data: Release }>; }): Promise<{ data: Release }>;
allReleases(params: { allReleases(params: {
@ -60,6 +61,7 @@ export class GitHubReleaser implements Releaser {
name: string; name: string;
body: string | undefined; body: string | undefined;
draft: boolean | undefined; draft: boolean | undefined;
prerelease: boolean | undefined;
}): Promise<{ data: Release }> { }): Promise<{ data: Release }> {
return this.github.repos.createRelease(params); return this.github.repos.createRelease(params);
} }
@ -138,6 +140,7 @@ export const release = async (
const name = config.input_name || tag; const name = config.input_name || tag;
const body = config.input_body; const body = config.input_body;
const draft = config.input_draft; const draft = config.input_draft;
const prerelease = config.input_prerelease;
console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`); console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`);
let release = await releaser.createRelease({ let release = await releaser.createRelease({
owner, owner,
@ -145,7 +148,8 @@ export const release = async (
tag_name, tag_name,
name, name,
body, body,
draft draft,
prerelease
}); });
return release.data; return release.data;
} catch (error) { } catch (error) {

View File

@ -11,10 +11,22 @@ export interface Config {
input_body_path?: string; input_body_path?: string;
input_files?: string[]; input_files?: string[];
input_draft?: boolean; input_draft?: boolean;
input_prerelease?: boolean;
} }
type Env = { [key: string]: string | undefined }; type Env = { [key: string]: string | undefined };
export const parseInputFiles = (files: string): string[] => {
return files.split(/\r?\n/).reduce<string[]>(
(acc, line) =>
acc
.concat(line.split(","))
.filter(pat => pat)
.map(pat => pat.trim()),
[]
);
};
export const parseConfig = (env: Env): Config => { export const parseConfig = (env: Env): Config => {
return { return {
github_token: env.GITHUB_TOKEN || "", github_token: env.GITHUB_TOKEN || "",
@ -23,8 +35,9 @@ export const parseConfig = (env: Env): Config => {
input_name: env.INPUT_NAME, input_name: env.INPUT_NAME,
input_body: env.INPUT_BODY, input_body: env.INPUT_BODY,
input_body_path: env.INPUT_BODY_PATH, input_body_path: env.INPUT_BODY_PATH,
input_files: (env.INPUT_FILES || "").split(","), input_files: parseInputFiles(env.INPUT_FILES || ""),
input_draft: env.INPUT_DRAFT === "true" input_draft: env.INPUT_DRAFT === "true",
input_prerelease: env.INPUT_PRERELEASE == "true"
}; };
}; };