diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ff364c..e21b80f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,23 @@ 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. +* 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 }} +``` + --- ## 0.1.1 diff --git a/README.md b/README.md index c3e069e..4130283 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ You can can configure a number of options for your GitHub release and all are optional. 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. Below is an example of uploading a single asset named `Release.txt` @@ -94,6 +94,36 @@ jobs: 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 Many systems exist that can help generate release notes for you. This action supports @@ -133,7 +163,7 @@ The following are optional as `step.with` keys | `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 | -| `files` | String | Comma-delimited globs of paths to assets to upload for release | +| `files` | String | Newline-delimited globs of paths to assets to upload for release | | `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. diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index 7a1f4d4..3833d41 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -1,7 +1,35 @@ -import { isTag, paths } from "../src/util"; +import { isTag, paths, parseConfig, parseInputFiles } from "../src/util"; import * as assert from "assert"; 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_files: [], + input_name: undefined + }); + }); + }); describe("isTag", () => { it("returns true for tags", async () => { assert.equal(isTag("refs/tags/foo"), true); diff --git a/action.yml b/action.yml index ce58983..d7462e4 100644 --- a/action.yml +++ b/action.yml @@ -16,7 +16,7 @@ inputs: description: 'Creates a draft release' required: false 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 env: 'GITHUB_TOKEN': 'As provided by Github Actions' diff --git a/lib/util.js b/lib/util.js index 60886db..3ab6d49 100644 --- a/lib/util.js +++ b/lib/util.js @@ -9,6 +9,12 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const glob = __importStar(require("glob")); 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) => { return { github_token: env.GITHUB_TOKEN || "", @@ -17,7 +23,7 @@ exports.parseConfig = (env) => { input_name: env.INPUT_NAME, input_body: env.INPUT_BODY, 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" }; }; diff --git a/src/util.ts b/src/util.ts index 1bd7c13..d7682de 100644 --- a/src/util.ts +++ b/src/util.ts @@ -15,6 +15,17 @@ export interface Config { type Env = { [key: string]: string | undefined }; +export const parseInputFiles = (files: string): string[] => { + return files.split(/\r?\n/).reduce( + (acc, line) => + acc + .concat(line.split(",")) + .filter(pat => pat) + .map(pat => pat.trim()), + [] + ); +}; + export const parseConfig = (env: Env): Config => { return { github_token: env.GITHUB_TOKEN || "", @@ -23,7 +34,7 @@ export const parseConfig = (env: Env): Config => { input_name: env.INPUT_NAME, input_body: env.INPUT_BODY, 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" }; };