Compare commits

...

25 Commits

Author SHA1 Message Date
08e53e60c8 update changelog 2021-07-25 19:02:03 -04:00
bb2c91bef9 rebuild 2021-07-25 19:00:48 -04:00
e020468dd2 release prep for 0.1.6 (#120) 2021-07-25 18:58:47 -04:00
5e3f23f92c lint fix and build 2021-07-17 19:37:16 -04:00
104b6490a7 Retain original release info if the keys are not set (#109) 2021-07-17 19:27:42 -04:00
a544ba8d92 Update github.ts (#111) 2021-07-17 19:24:12 -04:00
9729932bfb Support custom target_commitish value (#76)
* Make target_commitish configurable

* Store compiled action for testing

* Add target_commitish to metadata

* Allow override of target_commitish for updating

* Print commit usage

* Improve message for commit usage

* Update draft releases too

* Revert "Update draft releases too"

This reverts commit ff30f8edb18fa851785a2d361b03c9713f5ac17d.

* Integrate latest changes from upstream.
2021-05-02 20:43:58 -04:00
cebd052c1e Add release id to outputs (#60)
* Add release ID to outputs

* Update README
2021-05-01 18:56:49 -04:00
35d938cf01 rebuild dist/index.js (#93)
Fixes #92
2021-04-09 00:46:38 -04:00
e99df7cd80 use spaces instead tab (#87) 2021-03-22 13:05:06 -04:00
1f8f474abe Add upload_url as action output (#75)
* Add upload_url as action output

* Update README
2021-03-21 01:59:32 -04:00
94651eb27f Update README.md (#81) 2021-03-21 01:59:06 -04:00
dac15d39e4 fix: Get the same behavior described in Docs(#71) (#85)
Now trying read body path first then falling back on body
2021-03-21 01:52:16 -04:00
affa18ef97 Add repository input (#58) (#61) 2020-12-20 14:44:30 -05:00
2cf5c66450 [Security] Bump node-fetch from 2.6.0 to 2.6.1 (#66)
Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1. **This update includes a security fix.**
- [Release notes](https://github.com/bitinn/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-11-04 13:18:49 -05:00
aabd85678e [Security] Bump @actions/core from 1.2.0 to 1.2.6 (#68)
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.0 to 1.2.6. **This update includes a security fix.**
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-11-04 13:17:46 -05:00
4fb86a77e0 Add 'fail_on_unmatched_files' input (#55) 2020-06-25 02:11:41 -04:00
9439581056 fix: Update to latest throttling plugin (#53)
In attempt to fix unintentional retries on 422 error from GitHub,

1. Update to latest `@octokit/plugin-throttling` version
2. Depend on `@octokit/plugin-retry` plugin as well

Issue: #52
2020-05-24 20:39:23 -04:00
9a89d1e63f Docs: Fix spelling mistakes (#50)
* README: Fix spelling mistakes

* README: Rename OSX to macOS

* CONTRIBUTING: Fix spelling mistakes
2020-04-11 23:43:21 -04:00
91409e712c rebuild index 2020-01-26 19:36:03 -05:00
b238fd05b1 consolidate
consolidate changelog notes
2020-01-26 19:34:13 -05:00
a0dc82a74f add belated release note for 0.1.5 2020-01-26 19:31:05 -05:00
924757492e Make "npm run fmt(check)" work on Windows (#41)
On Windows, single quotes cannot be used for quoting command line.
Use double quotes instead.
2020-01-12 16:48:37 -05:00
9993ae8534 Fix mistake in #39 (#40)
It should be `github.ref` or `GITHUB_REF`.
2020-01-09 18:32:41 -05:00
9f4852ebe6 Add tag_name option (#39)
Allow setting tag name like actions/create-release.
2020-01-09 01:06:19 -05:00
11 changed files with 319 additions and 101 deletions

View File

@ -1,29 +1,43 @@
## 0.1.4
## 0.1.6
* Added support for updating releases body [#36](https://github.com/softprops/action-gh-release/pull/36)
This is a release catch up have a hiatus. Future releases will happen more frequently
- Add 'fail_on_unmatched_files' input, useful for catching cases were your `files` input does not actually match what you expect [#55](https://github.com/softprops/action-gh-release/pull/55)
- Add `repository` input, useful for creating a release in an external repository [#61](https://github.com/softprops/action-gh-release/pull/61)
- Add release `id` to outputs, useful for refering to release in workflow steps following the step that uses this action [#60](https://github.com/softprops/action-gh-release/pull/60)
- Add `upload_url` as action output, useful for managing uploads separately [#75](https://github.com/softprops/action-gh-release/pull/75)
- Support custom `target_commitish` value, useful to customize the default [#76](https://github.com/softprops/action-gh-release/pull/76)
- fix `body_path` input first then fall back on `body` input. this was the originally documented precedence but was implemened the the opposite order! [#85](https://github.com/softprops/action-gh-release/pull/85)
- Retain original release info if the keys are not set, useful for filling in blanks for a release you've already started separately [#109](https://github.com/softprops/action-gh-release/pull/109)
- Limit number of times github api request to create a release is retried, useful for avoiding eating up your rate limit and action minutes do to either an invalid token or other circumstance causing the api call to fail [#111](https://github.com/softprops/action-gh-release/pull/111)
## 0.1.5
- Added support for specifying tag name [#39](https://github.com/softprops/action-gh-release/pull/39)
## 0.1.4
* Steps can now access the url of releases with the `url` output of this Action [#28](https://github.com/softprops/action-gh-release/pull/28)
* Added basic GitHub API retry support to manage API turbulance [#26](https://github.com/softprops/action-gh-release/pull/26)
- Added support for updating releases body [#36](https://github.com/softprops/action-gh-release/pull/36)
- Steps can now access the url of releases with the `url` output of this Action [#28](https://github.com/softprops/action-gh-release/pull/28)
- Added basic GitHub API retry support to manage API turbulance [#26](https://github.com/softprops/action-gh-release/pull/26)
## 0.1.3
* Fixed where `with: body_path` was not being used in generated GitHub releases
- Fixed where `with: body_path` was not being used in generated GitHub releases
## 0.1.2
* Add support for merging draft releases [#16](https://github.com/softprops/action-gh-release/pull/16)
- Add support for merging draft releases [#16](https://github.com/softprops/action-gh-release/pull/16)
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)
- 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
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
@ -35,13 +49,13 @@ GitHub actions inputs don't inherently support lists of things and one might lik
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
* Add support for prerelease annotated GitHub releases with the new input field `with.prerelease: true` [#19](https://github.com/softprops/action-gh-release/pull/19)
- Add support for prerelease annotated GitHub releases with the new input field `with.prerelease: true` [#19](https://github.com/softprops/action-gh-release/pull/19)
---
## 0.1.1
* Add support for publishing releases on all supported virtual hosts
- Add support for publishing releases on all supported virtual hosts
You'll need to remove `docker://` prefix and use the `@v1` action tag
@ -49,4 +63,4 @@ You'll need to remove `docker://` prefix and use the `@v1` action tag
## 0.1.0
* Initial release
- Initial release

View File

@ -2,11 +2,11 @@
This a [JavaScript](https://help.github.com/en/articles/about-actions#types-of-actions) action but uses [TypeScript](https://www.typescriptlang.org/docs/home.html) to generate that JavaScript.
You can bootstrap your envrinment with a modern version of npm and by running `npm i` at the root of this repo.
You can bootstrap your environment with a modern version of npm and by running `npm i` at the root of this repo.
## testing
Tests can be found under under `__tests__` directory and are runnable with the `npm t` command
Tests can be found under under `__tests__` directory and are runnable with the `npm t` command.
## source code
@ -14,5 +14,4 @@ Source code can be found under the `src` directory. Running `npm run build` will
## formatting
A minimal attempt at keeping a consistent code style is can be applied by running `npm run fmt`
A minimal attempt at keeping a consistent code style is can be applied by running `npm run fmt`.

View File

@ -7,7 +7,7 @@
</h1>
<p align="center">
A GitHub Action for creating GitHub Releases on Linux, Windows, and OSX virtual environments
A GitHub Action for creating GitHub Releases on Linux, Windows, and macOS virtual environments
</p>
<div align="center">
@ -29,7 +29,7 @@
Typically usage of this action involves adding a step to a build that
is gated pushes to git tags. You may find `step.if` field helpful in accomplishing this
as it maximizes the resuse value of your workflow for non-tag pushes.
as it maximizes the reuse value of your workflow for non-tag pushes.
Below is a simple example of `step.if` tag gating
@ -75,7 +75,7 @@ jobs:
### ⬆️ Uploading release assets
You can can configure a number of options for your
You 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.
@ -164,6 +164,7 @@ jobs:
body_path: ${{ github.workflow }}-CHANGELOG.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: my_gh_org/my_gh_repo
```
### 💅 Customizing
@ -173,15 +174,23 @@ jobs:
The following are optional as `step.with` keys
| Name | Type | Description |
|-------------|---------|-----------------------------------------------------------------|
|---------------------------|---------|-----------------------------------------------------------------------------------------------------|
| `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 |
| `prerelease`| Boolean | Indicator of whether or not is a prerelease |
| `files` | String | Newline-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 |
| `tag_name` | String | Name of a tag. defaults to `github.ref` |
| `fail_on_unmatched_files` | Boolean | Indicator of whether to fail if any of the `files` globs match nothing |
| `target_commitish` | String | Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. |
💡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.
💡 When the release info keys (such as `name`, `body`, `draft`, `prerelease`, etc.)
are not explicitly set and there is already an existing release for the tag, the
release will retain its original info.
#### outputs
@ -190,6 +199,8 @@ The following outputs can be accessed via `${{ steps.<step-id>.outputs }}` from
| Name | Type | Description |
|-------------|---------|-----------------------------------------------------------------|
| `url` | String | Github.com URL for the release |
| `id` | String | Release ID |
| `upload_url`| String | URL for uploading assets to the release |
#### environment variables
@ -199,8 +210,9 @@ The following are *required* as `step.env` keys
| Name | Description |
|----------------|--------------------------------------|
| `GITHUB_TOKEN` | GITHUB_TOKEN as provided by `secrets`|
| `GITHUB_REPOSITORY` | Name of a target repository in `<owner>/<repo>` format. defaults to the current repository|
> **⚠️ Note:** This action was previously implemented as a docker container, limiting its use to GitHub Actions Linux virtual environments only. With recent releases, we now support cross platform usage. You'll need to remove the `docker://` prefix in these versions
> **⚠️ Note:** This action was previously implemented as a Docker container, limiting its use to GitHub Actions Linux virtual environments only. With recent releases, we now support cross platform usage. You'll need to remove the `docker://` prefix in these versions
Doug Tangren (softprops) 2019

View File

@ -3,7 +3,8 @@ import {
isTag,
paths,
parseConfig,
parseInputFiles
parseInputFiles,
unmatchedPatterns
} from "../src/util";
import * as assert from "assert";
@ -35,7 +36,9 @@ describe("util", () => {
input_draft: false,
input_prerelease: false,
input_files: [],
input_name: undefined
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined
})
);
});
@ -51,13 +54,15 @@ describe("util", () => {
input_draft: false,
input_prerelease: false,
input_files: [],
input_name: undefined
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined
})
);
});
it("defaults to body when both body and body path are provided", () => {
it("defaults to body path when both body and body path are provided", () => {
assert.equal(
"foo",
"bar",
releaseBody({
github_ref: "",
github_repository: "",
@ -67,7 +72,9 @@ describe("util", () => {
input_draft: false,
input_prerelease: false,
input_files: [],
input_name: undefined
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined
})
);
});
@ -80,13 +87,61 @@ describe("util", () => {
github_token: "",
input_body: undefined,
input_body_path: undefined,
input_draft: false,
input_prerelease: false,
input_draft: undefined,
input_prerelease: undefined,
input_files: [],
input_name: undefined
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined
});
});
});
describe("parseConfig", () => {
it("parses basic config with commitish", () => {
assert.deepStrictEqual(
parseConfig({
INPUT_TARGET_COMMITISH: "affa18ef97bc9db20076945705aba8c516139abd"
}),
{
github_ref: "",
github_repository: "",
github_token: "",
input_body: undefined,
input_body_path: undefined,
input_draft: undefined,
input_prerelease: undefined,
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: "affa18ef97bc9db20076945705aba8c516139abd"
}
);
});
it("parses basic config with draft and prerelease", () => {
assert.deepStrictEqual(
parseConfig({
INPUT_DRAFT: "false",
INPUT_PRERELEASE: "true"
}),
{
github_ref: "",
github_repository: "",
github_token: "",
input_body: undefined,
input_body_path: undefined,
input_draft: false,
input_prerelease: true,
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined
}
);
});
});
describe("isTag", () => {
it("returns true for tags", async () => {
assert.equal(isTag("refs/tags/foo"), true);
@ -98,9 +153,19 @@ describe("util", () => {
describe("paths", () => {
it("resolves files given a set of paths", async () => {
assert.deepStrictEqual(paths(["tests/data/**/*"]), [
"tests/data/foo/bar.txt"
]);
assert.deepStrictEqual(
paths(["tests/data/**/*", "tests/data/does/not/exist/*"]),
["tests/data/foo/bar.txt"]
);
});
});
describe("unmatchedPatterns", () => {
it("returns the patterns that don't match any files", async () => {
assert.deepStrictEqual(
unmatchedPatterns(["tests/data/**/*", "tests/data/does/not/exist/*"]),
["tests/data/does/not/exist/*"]
);
});
});
});

View File

@ -12,6 +12,9 @@ inputs:
name:
description: 'Gives the release a custom name. Defaults to tag name'
required: false
tag_name:
description: 'Gives a tag name. Defaults to github.GITHUB_REF'
required: false
draft:
description: 'Creates a draft release. Defaults to false'
required: false
@ -21,11 +24,24 @@ inputs:
files:
description: 'Newline-delimited list of path globs for asset files to upload'
required: false
fail_on_unmatched_files:
description: 'Fails if any of the `files` globs match nothing. Defaults to false'
required: false
repository:
description: 'Repository to make releases against, in <owner>/<repo> format'
required: false
target_commitish:
description: 'Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA.'
required: false
env:
'GITHUB_TOKEN': 'As provided by Github Actions'
outputs:
url:
description: 'URL to the Release HTML Page'
id:
description: 'Release ID'
upload_url:
description: 'URL for uploading assets to the release'
runs:
using: 'node12'
main: 'dist/index.js'

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

52
package-lock.json generated
View File

@ -1,13 +1,13 @@
{
"name": "action-gh-release",
"version": "0.1.4",
"version": "0.1.6",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@actions/core": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz",
"integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw=="
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
},
"@actions/github": {
"version": "2.0.0",
@ -434,12 +434,42 @@
"universal-user-agent": "^4.0.0"
}
},
"@octokit/plugin-throttling": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-2.7.1.tgz",
"integrity": "sha512-08CKNFCpSpmOEAQBn6/MR8zbJgjP4+bplNUJbKlqJSNBHTO1NdsDHzBD4VeFYopOo7rBEySng4WifxNVaQ5bVw==",
"@octokit/plugin-retry": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-3.0.2.tgz",
"integrity": "sha512-k7xl2WLfLP7WirRXRHtCq5xGAIXBZHV9X3HVUJhPwe8/N8vVzxPcnnnBL5NpEep/+GQqFRdYxrkgz68VY3z2wA==",
"requires": {
"@octokit/types": "^4.0.1",
"bottleneck": "^2.15.3"
},
"dependencies": {
"@octokit/types": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-4.0.1.tgz",
"integrity": "sha512-Ho6h7w2h9y8RRE8r656hIj1oiSbwbIHJGF5r9G5FOwS2VdDPq8QLGvsG4x6pKHpvyGK7j+43sAc2cJKMiFoIJw==",
"requires": {
"@types/node": ">= 8"
}
}
}
},
"@octokit/plugin-throttling": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-3.2.1.tgz",
"integrity": "sha512-CGr3IagYZLLV3pFgpTQUthQSS5K3BkHLlG8yXK+Op3UKBkYrTf+Y9pCebrDxt60d+VTQ1oxXCx+LVLYY3IhBZQ==",
"requires": {
"@octokit/types": "^4.0.1",
"bottleneck": "^2.15.3"
},
"dependencies": {
"@octokit/types": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-4.0.1.tgz",
"integrity": "sha512-Ho6h7w2h9y8RRE8r656hIj1oiSbwbIHJGF5r9G5FOwS2VdDPq8QLGvsG4x6pKHpvyGK7j+43sAc2cJKMiFoIJw==",
"requires": {
"@types/node": ">= 8"
}
}
}
},
"@octokit/request": {
@ -3678,9 +3708,9 @@
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
},
"node-fetch": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
},
"node-int64": {
"version": "0.4.0",

View File

@ -1,14 +1,14 @@
{
"name": "action-gh-release",
"version": "0.1.5",
"version": "0.1.6",
"private": true,
"description": "GitHub Action for creating GitHub Releases",
"main": "lib/main.js",
"scripts": {
"build": "ncc build src/main.ts --minify",
"test": "jest",
"fmt": "prettier --write 'src/**/*.ts' '__tests__/**/*.ts'",
"fmtcheck": "prettier --check 'src/**/*.ts' '__tests__/**/*.ts'"
"fmt": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"",
"fmtcheck": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\""
},
"repository": {
"type": "git",
@ -20,9 +20,10 @@
"author": "softprops",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.0",
"@actions/core": "^1.2.6",
"@actions/github": "^2.0.0",
"@octokit/plugin-throttling": "^2.7.1",
"@octokit/plugin-retry": "^3.0.2",
"@octokit/plugin-throttling": "^3.2.1",
"glob": "^7.1.6",
"mime": "^2.4.4"
},

View File

@ -16,8 +16,11 @@ export interface Release {
upload_url: string;
html_url: string;
tag_name: string;
name: string;
body: string;
target_commitish: string;
draft: boolean;
prerelease: boolean;
}
export interface Releaser {
@ -35,6 +38,7 @@ export interface Releaser {
body: string | undefined;
draft: boolean | undefined;
prerelease: boolean | undefined;
target_commitish: string | undefined;
}): Promise<{ data: Release }>;
updateRelease(params: {
@ -77,6 +81,7 @@ export class GitHubReleaser implements Releaser {
body: string | undefined;
draft: boolean | undefined;
prerelease: boolean | undefined;
target_commitish: string | undefined;
}): Promise<{ data: Release }> {
return this.github.repos.createRelease(params);
}
@ -139,10 +144,17 @@ export const upload = async (
export const release = async (
config: Config,
releaser: Releaser
releaser: Releaser,
maxRetries: number = 3
): Promise<Release> => {
if (maxRetries <= 0) {
console.log(`❌ Too many retries. Aborting...`);
throw new Error("Too many retries.");
}
const [owner, repo] = config.github_repository.split("/");
const tag = config.github_ref.replace("refs/tags/", "");
const tag =
config.input_tag_name || config.github_ref.replace("refs/tags/", "");
try {
// you can't get a an existing draft by tag
// so we must find one in the list of all releases
@ -164,12 +176,36 @@ export const release = async (
});
const release_id = existingRelease.data.id;
const target_commitish = existingRelease.data.target_commitish;
let target_commitish: string;
if (
config.input_target_commitish &&
config.input_target_commitish !== existingRelease.data.target_commitish
) {
console.log(
`Updating commit from "${existingRelease.data.target_commitish}" to "${config.input_target_commitish}"`
);
target_commitish = config.input_target_commitish;
} else {
target_commitish = existingRelease.data.target_commitish;
}
const tag_name = tag;
const name = config.input_name || tag;
const body = `${existingRelease.data.body}\n${releaseBody(config)}`;
const draft = config.input_draft;
const prerelease = config.input_prerelease;
const name = config.input_name || existingRelease.data.name || tag;
let body: string = "";
if (existingRelease.data.body) body += existingRelease.data.body;
let workflowBody = releaseBody(config);
if (existingRelease.data.body && workflowBody) body += "\n";
if (workflowBody) body += workflowBody;
const draft =
config.input_draft !== undefined
? config.input_draft
: existingRelease.data.draft;
const prerelease =
config.input_prerelease !== undefined
? config.input_prerelease
: existingRelease.data.prerelease;
const release = await releaser.updateRelease({
owner,
@ -190,7 +226,14 @@ export const release = async (
const body = releaseBody(config);
const draft = config.input_draft;
const prerelease = config.input_prerelease;
console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`);
const target_commitish = config.input_target_commitish;
let commitMessage: string = "";
if (target_commitish) {
commitMessage = ` using commit "${target_commitish}"`;
}
console.log(
`👩‍🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...`
);
try {
let release = await releaser.createRelease({
owner,
@ -199,15 +242,18 @@ export const release = async (
name,
body,
draft,
prerelease
prerelease,
target_commitish
});
return release.data;
} catch (error) {
// presume a race with competing metrix runs
console.log(
`⚠️ GitHub release failed with status: ${error.status}, retrying...`
`⚠️ GitHub release failed with status: ${
error.status
}, retrying... (${maxRetries - 1} retries remaining)`
);
return release(config, releaser);
return release(config, releaser, maxRetries - 1);
}
} else {
console.log(

View File

@ -1,4 +1,4 @@
import { paths, parseConfig, isTag } from "./util";
import { paths, parseConfig, isTag, unmatchedPatterns } from "./util";
import { release, upload, GitHubReleaser } from "./github";
import { setFailed, setOutput } from "@actions/core";
import { GitHub } from "@actions/github";
@ -7,11 +7,24 @@ import { env } from "process";
async function run() {
try {
const config = parseConfig(env);
if (!isTag(config.github_ref)) {
if (!config.input_tag_name && !isTag(config.github_ref)) {
throw new Error(`⚠️ GitHub Releases requires a tag`);
}
GitHub.plugin(require("@octokit/plugin-throttling"));
if (config.input_files) {
const patterns = unmatchedPatterns(config.input_files);
patterns.forEach(pattern =>
console.warn(`🤔 Pattern '${pattern}' does not match any files.`)
);
if (patterns.length > 0 && config.input_fail_on_unmatched_files) {
throw new Error(`⚠️ There were unmatched files`);
}
}
GitHub.plugin([
require("@octokit/plugin-throttling"),
require("@octokit/plugin-retry")
]);
const gh = new GitHub(config.github_token, {
throttle: {
onRateLimit: (retryAfter, options) => {
console.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
@ -28,6 +41,7 @@ async function run() {
`Abuse detected for request ${options.method} ${options.url}`
);
}
}
});
let rel = await release(config, new GitHubReleaser(gh));
if (config.input_files) {
@ -41,6 +55,8 @@ async function run() {
}
console.log(`🎉 Release ready at ${rel.html_url}`);
setOutput("url", rel.html_url);
setOutput("id", rel.id.toString());
setOutput("upload_url", rel.upload_url);
} catch (error) {
setFailed(error.message);
}

View File

@ -7,18 +7,22 @@ export interface Config {
github_repository: string;
// user provided
input_name?: string;
input_tag_name?: string;
input_repository?: string;
input_body?: string;
input_body_path?: string;
input_files?: string[];
input_draft?: boolean;
input_prerelease?: boolean;
input_fail_on_unmatched_files?: boolean;
input_target_commitish?: string;
}
export const releaseBody = (config: Config): string | undefined => {
return (
config.input_body ||
(config.input_body_path &&
readFileSync(config.input_body_path).toString("utf8"))
readFileSync(config.input_body_path).toString("utf8")) ||
config.input_body
);
};
@ -39,13 +43,18 @@ export const parseConfig = (env: Env): Config => {
return {
github_token: env.GITHUB_TOKEN || "",
github_ref: env.GITHUB_REF || "",
github_repository: env.GITHUB_REPOSITORY || "",
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || "",
input_name: env.INPUT_NAME,
input_tag_name: env.INPUT_TAG_NAME,
input_body: env.INPUT_BODY,
input_body_path: env.INPUT_BODY_PATH,
input_files: parseInputFiles(env.INPUT_FILES || ""),
input_draft: env.INPUT_DRAFT === "true",
input_prerelease: env.INPUT_PRERELEASE == "true"
input_draft: env.INPUT_DRAFT ? env.INPUT_DRAFT === "true" : undefined,
input_prerelease: env.INPUT_PRERELEASE
? env.INPUT_PRERELEASE == "true"
: undefined,
input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true",
input_target_commitish: env.INPUT_TARGET_COMMITISH
};
};
@ -57,6 +66,16 @@ export const paths = (patterns: string[]): string[] => {
}, []);
};
export const unmatchedPatterns = (patterns: string[]): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => {
return acc.concat(
glob.sync(pattern).filter(path => lstatSync(path).isFile()).length == 0
? [pattern]
: []
);
}, []);
};
export const isTag = (ref: string): boolean => {
return ref.startsWith("refs/tags/");
};