Allow setting an explicit target_commitish

This commit is contained in:
Spikatrix 2023-06-01 04:55:54 +00:00
parent a724093295
commit 3cff01dd32
4 changed files with 14 additions and 6 deletions

View File

@ -21,6 +21,7 @@ Optional Arguments
- `prerelease`: Mark the release as a pre-release (Default: `false`). - `prerelease`: Mark the release as a pre-release (Default: `false`).
- `make_latest`: Mark the release as the latest release for the repository (Default: `true`). - `make_latest`: Mark the release as the latest release for the repository (Default: `true`).
- `release_name`: Explicitly set a release name. (Defaults: implicitly same as `tag` via GitHub API). - `release_name`: Explicitly set a release name. (Defaults: implicitly same as `tag` via GitHub API).
- `target_commit`: Sets the commit hash or branch for the tag to be based on (Default: the default branch, usually `master`).
- `body`: Content of the release text (Default: `""`). - `body`: Content of the release text (Default: `""`).
- `repo_name`: Specify the name of the GitHub repository in which the GitHub release will be created, edited, and deleted. If the repository is other than the current, it is required to create a personal access token with `repo`, `user`, `admin:repo_hook` scopes to the foreign repository and add it as a secret. (Default: current repository). - `repo_name`: Specify the name of the GitHub repository in which the GitHub release will be created, edited, and deleted. If the repository is other than the current, it is required to create a personal access token with `repo`, `user`, `admin:repo_hook` scopes to the foreign repository and add it as a secret. (Default: current repository).

View File

@ -32,6 +32,8 @@ inputs:
description: 'Explicitly set a release name. Defaults to empty which will cause the release to take the tag as name on GitHub.' description: 'Explicitly set a release name. Defaults to empty which will cause the release to take the tag as name on GitHub.'
body: body:
description: 'Content of the release text. Empty by default.' description: 'Content of the release text. Empty by default.'
target_commit:
description: 'Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository"s default branch (usually `master`).'
repo_name: repo_name:
description: 'Specify the name of the GitHub repository in which the GitHub release will be created, edited, and deleted. If the repository is other than the current, it is required to create a personal access token with `repo`, `user`, `admin:repo_hook` scopes to the foreign repository and add it as a secret. Defaults to the current repository' description: 'Specify the name of the GitHub repository in which the GitHub release will be created, edited, and deleted. If the repository is other than the current, it is required to create a personal access token with `repo`, `user`, `admin:repo_hook` scopes to the foreign repository and add it as a secret. Defaults to the current repository'
outputs: outputs:

7
dist/index.js vendored
View File

@ -51,7 +51,7 @@ const updateRelease = 'PATCH /repos/{owner}/{repo}/releases/{release_id}';
const repoAssets = 'GET /repos/{owner}/{repo}/releases/{release_id}/assets'; const repoAssets = 'GET /repos/{owner}/{repo}/releases/{release_id}/assets';
const uploadAssets = 'POST {origin}/repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}'; const uploadAssets = 'POST {origin}/repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}';
const deleteAssets = 'DELETE /repos/{owner}/{repo}/releases/assets/{asset_id}'; const deleteAssets = 'DELETE /repos/{owner}/{repo}/releases/assets/{asset_id}';
function get_release_by_tag(tag, prerelease, make_latest, release_name, body, octokit, overwrite, promote) { function get_release_by_tag(tag, prerelease, make_latest, release_name, body, octokit, overwrite, promote, target_commit) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let release; let release;
try { try {
@ -62,7 +62,7 @@ function get_release_by_tag(tag, prerelease, make_latest, release_name, body, oc
// If this returns 404, we need to create the release first. // If this returns 404, we need to create the release first.
if (error.status === 404) { if (error.status === 404) {
core.debug(`Release for tag ${tag} doesn't exist yet so we'll create it now.`); core.debug(`Release for tag ${tag} doesn't exist yet so we'll create it now.`);
return yield octokit.request(createRelease, Object.assign(Object.assign({}, repo()), { tag_name: tag, prerelease: prerelease, make_latest: make_latest ? 'true' : 'false', name: release_name, body: body })); return yield octokit.request(createRelease, Object.assign(Object.assign({}, repo()), { tag_name: tag, prerelease: prerelease, make_latest: make_latest ? 'true' : 'false', name: release_name, body: body, target_commitish: target_commit }));
} }
else { else {
throw error; throw error;
@ -167,13 +167,14 @@ function run() {
const prerelease = core.getInput('prerelease') == 'true' ? true : false; const prerelease = core.getInput('prerelease') == 'true' ? true : false;
const make_latest = core.getInput('make_latest') != 'false' ? true : false; const make_latest = core.getInput('make_latest') != 'false' ? true : false;
const release_name = core.getInput('release_name'); const release_name = core.getInput('release_name');
const target_commit = core.getInput('target_commit');
const body = core const body = core
.getInput('body') .getInput('body')
.replace(/%0A/gi, '\n') .replace(/%0A/gi, '\n')
.replace(/%0D/gi, '\r') .replace(/%0D/gi, '\r')
.replace(/%25/g, '%'); .replace(/%25/g, '%');
const octokit = github.getOctokit(token); const octokit = github.getOctokit(token);
const release = yield get_release_by_tag(tag, prerelease, make_latest, release_name, body, octokit, overwrite, promote); const release = yield get_release_by_tag(tag, prerelease, make_latest, release_name, body, octokit, overwrite, promote, target_commit);
if (file_glob) { if (file_glob) {
const files = glob.sync(file); const files = glob.sync(file);
if (files.length > 0) { if (files.length > 0) {

View File

@ -33,7 +33,8 @@ async function get_release_by_tag(
body: string, body: string,
octokit: Octokit, octokit: Octokit,
overwrite: boolean, overwrite: boolean,
promote: boolean promote: boolean,
target_commit: string
): Promise<ReleaseByTagResp | CreateReleaseResp | UpdateReleaseResp> { ): Promise<ReleaseByTagResp | CreateReleaseResp | UpdateReleaseResp> {
let release: ReleaseByTagResp let release: ReleaseByTagResp
try { try {
@ -54,7 +55,8 @@ async function get_release_by_tag(
prerelease: prerelease, prerelease: prerelease,
make_latest: make_latest ? 'true' : 'false', make_latest: make_latest ? 'true' : 'false',
name: release_name, name: release_name,
body: body body: body,
target_commitish: target_commit
}) })
} else { } else {
throw error throw error
@ -194,6 +196,7 @@ async function run(): Promise<void> {
const prerelease = core.getInput('prerelease') == 'true' ? true : false const prerelease = core.getInput('prerelease') == 'true' ? true : false
const make_latest = core.getInput('make_latest') != 'false' ? true : false const make_latest = core.getInput('make_latest') != 'false' ? true : false
const release_name = core.getInput('release_name') const release_name = core.getInput('release_name')
const target_commit = core.getInput('target_commit')
const body = core const body = core
.getInput('body') .getInput('body')
.replace(/%0A/gi, '\n') .replace(/%0A/gi, '\n')
@ -209,7 +212,8 @@ async function run(): Promise<void> {
body, body,
octokit, octokit,
overwrite, overwrite,
promote promote,
target_commit
) )
if (file_glob) { if (file_glob) {