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.
This commit is contained in:
parent
674bcd2d67
commit
2934fce629
6 changed files with 95 additions and 41 deletions
|
@ -163,7 +163,7 @@ 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 |
|
||||
|
@ -172,6 +172,7 @@ The following are optional as `step.with` keys
|
|||
| `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. |
|
||||
| `token` | String | Secret GitHub Personal Access Token. Defaults to `${{ github.token }}` |
|
||||
|
||||
💡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.
|
||||
|
|
|
@ -37,7 +37,8 @@ describe("util", () => {
|
|||
input_prerelease: false,
|
||||
input_files: [],
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined
|
||||
input_tag_name: undefined,
|
||||
input_target_commitish: undefined
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -54,7 +55,8 @@ describe("util", () => {
|
|||
input_prerelease: false,
|
||||
input_files: [],
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined
|
||||
input_tag_name: undefined,
|
||||
input_target_commitish: undefined
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -71,7 +73,8 @@ describe("util", () => {
|
|||
input_prerelease: false,
|
||||
input_files: [],
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined
|
||||
input_tag_name: undefined,
|
||||
input_target_commitish: undefined
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -89,10 +92,34 @@ describe("util", () => {
|
|||
input_files: [],
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false
|
||||
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: false,
|
||||
input_prerelease: false,
|
||||
input_files: [],
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: "affa18ef97bc9db20076945705aba8c516139abd"
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("isTag", () => {
|
||||
it("returns true for tags", async () => {
|
||||
assert.equal(isTag("refs/tags/foo"), true);
|
||||
|
|
45
action.yml
45
action.yml
|
@ -1,51 +1,54 @@
|
|||
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
|
||||
name: 'GH Release'
|
||||
description: 'Github Action for creating Github Releases'
|
||||
author: 'softprops'
|
||||
name: "GH Release"
|
||||
description: "Github Action for creating Github Releases"
|
||||
author: "softprops"
|
||||
inputs:
|
||||
body:
|
||||
description: 'Note-worthy description of changes in release'
|
||||
description: "Note-worthy description of changes in release"
|
||||
required: false
|
||||
body_path:
|
||||
description: 'Path to load note-worthy description of changes in release from'
|
||||
description: "Path to load note-worthy description of changes in release from"
|
||||
required: false
|
||||
name:
|
||||
description: 'Gives the release a custom name. Defaults to tag 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'
|
||||
description: "Gives a tag name. Defaults to github.GITHUB_REF"
|
||||
required: false
|
||||
draft:
|
||||
description: 'Creates a draft release. Defaults to false'
|
||||
description: "Creates a draft release. Defaults to false"
|
||||
required: false
|
||||
prerelease:
|
||||
description: 'Identify the release as a prerelease. Defaults to false'
|
||||
description: "Identify the release as a prerelease. Defaults to false"
|
||||
required: false
|
||||
files:
|
||||
description: 'Newline-delimited list of path globs for asset files to upload'
|
||||
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'
|
||||
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'
|
||||
description: "Repository to make releases against, in <owner>/<repo> format"
|
||||
required: false
|
||||
token:
|
||||
description: 'Authorized secret GitHub Personal Access Token. Defaults to github.token'
|
||||
description: "Authorized secret GitHub Personal Access Token. Defaults to github.token"
|
||||
required: false
|
||||
default: ${{ github.token }}
|
||||
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'
|
||||
"GITHUB_TOKEN": "As provided by Github Actions"
|
||||
outputs:
|
||||
url:
|
||||
description: 'URL to the Release HTML Page'
|
||||
description: "URL to the Release HTML Page"
|
||||
id:
|
||||
description: 'Release ID'
|
||||
description: "Release ID"
|
||||
upload_url:
|
||||
description: 'URL for uploading assets to the release'
|
||||
description: "URL for uploading assets to the release"
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
using: "node12"
|
||||
main: "dist/index.js"
|
||||
branding:
|
||||
color: 'green'
|
||||
icon: 'package'
|
||||
color: "green"
|
||||
icon: "package"
|
||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -35,6 +35,7 @@ export interface Releaser {
|
|||
body: string | undefined;
|
||||
draft: boolean | undefined;
|
||||
prerelease: boolean | undefined;
|
||||
target_commitish: string | undefined;
|
||||
}): Promise<{ data: Release }>;
|
||||
|
||||
updateRelease(params: {
|
||||
|
@ -77,6 +78,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);
|
||||
}
|
||||
|
@ -165,7 +167,18 @@ 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)}`;
|
||||
|
@ -191,7 +204,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,
|
||||
|
@ -200,7 +220,8 @@ export const release = async (
|
|||
name,
|
||||
body,
|
||||
draft,
|
||||
prerelease
|
||||
prerelease,
|
||||
target_commitish
|
||||
});
|
||||
return release.data;
|
||||
} catch (error) {
|
||||
|
|
|
@ -16,6 +16,7 @@ export interface Config {
|
|||
input_draft?: boolean;
|
||||
input_prerelease?: boolean;
|
||||
input_fail_on_unmatched_files?: boolean;
|
||||
input_target_commitish?: string;
|
||||
}
|
||||
|
||||
export const releaseBody = (config: Config): string | undefined => {
|
||||
|
@ -51,7 +52,8 @@ export const parseConfig = (env: Env): Config => {
|
|||
input_files: parseInputFiles(env.INPUT_FILES || ""),
|
||||
input_draft: env.INPUT_DRAFT === "true",
|
||||
input_prerelease: env.INPUT_PRERELEASE == "true",
|
||||
input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true"
|
||||
input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true",
|
||||
input_target_commitish: env.INPUT_TARGET_COMMITISH
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue