From 3af8783d41cf66bc8ff6769b76e0ccadba51110e Mon Sep 17 00:00:00 2001 From: softprops Date: Tue, 17 Sep 2019 23:14:30 +0900 Subject: [PATCH 1/4] support multi-line delimited assets. fixes #15 --- README.md | 34 ++++++++++++++++++++++++++++++++-- __tests__/util.test.ts | 30 +++++++++++++++++++++++++++++- lib/util.js | 8 +++++++- src/util.ts | 13 ++++++++++++- 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c3e069e07..0719dd9b0 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. + +```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 7a1f4d4fc..3833d41b7 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/lib/util.js b/lib/util.js index 60886db22..3ab6d49f3 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 1bd7c137c..d7682de5c 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" }; }; From 77f9a4f575ca4c65eac0f835b85c48350ed4b9df Mon Sep 17 00:00:00 2001 From: softprops Date: Tue, 17 Sep 2019 23:16:32 +0900 Subject: [PATCH 2/4] update inputs.files.description --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ce5898331..d7462e45b 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' From 615fb448a25a998af88b454f11e21fd9f5413e32 Mon Sep 17 00:00:00 2001 From: softprops Date: Tue, 17 Sep 2019 23:21:28 +0900 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 17 +++++++++++++++++ README.md | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ff364c1d..625371ef7 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 0719dd9b0..413028398 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` -Below is an example of uploading more than one asset. +Below is an example of uploading more than one asset with a GitHub release ```yaml name: Main @@ -115,7 +115,7 @@ jobs: uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: - files: |- + files: | Release.txt LICENSE env: From e812c4aca6ad34f17df295a7993e135cfd1c5232 Mon Sep 17 00:00:00 2001 From: softprops Date: Tue, 17 Sep 2019 23:22:34 +0900 Subject: [PATCH 4/4] tabs to spaces --- CHANGELOG.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 625371ef7..e21b80f53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,16 +10,16 @@ This is now fixed. 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 }} + - 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 }} ``` ---