Merge pull request #46 from Spikatrix/master
Allow setting an explicit target_commitish
This commit is contained in:
commit
80d7a7e41c
@ -21,6 +21,7 @@ Optional Arguments
|
||||
- `prerelease`: Mark the release as a pre-release (Default: `false`).
|
||||
- `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).
|
||||
- `target_commit`: Sets the commit hash or branch for the tag to be based on (Default: the default branch, usually `main`).
|
||||
- `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).
|
||||
|
||||
|
@ -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.'
|
||||
body:
|
||||
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 `main`).'
|
||||
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'
|
||||
outputs:
|
||||
|
19
dist/index.js
vendored
19
dist/index.js
vendored
@ -45,13 +45,14 @@ const github = __importStar(__nccwpck_require__(5438));
|
||||
const path = __importStar(__nccwpck_require__(1017));
|
||||
const glob = __importStar(__nccwpck_require__(7106));
|
||||
const attempt_1 = __nccwpck_require__(6494);
|
||||
const getRef = 'GET /repos/{owner}/{repo}/git/ref/{ref}';
|
||||
const releaseByTag = 'GET /repos/{owner}/{repo}/releases/tags/{tag}';
|
||||
const createRelease = 'POST /repos/{owner}/{repo}/releases';
|
||||
const updateRelease = 'PATCH /repos/{owner}/{repo}/releases/{release_id}';
|
||||
const repoAssets = 'GET /repos/{owner}/{repo}/releases/{release_id}/assets';
|
||||
const uploadAssets = 'POST {origin}/repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}';
|
||||
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* () {
|
||||
let release;
|
||||
try {
|
||||
@ -62,7 +63,18 @@ 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 (error.status === 404) {
|
||||
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 }));
|
||||
if (target_commit) {
|
||||
try {
|
||||
yield octokit.request(getRef, Object.assign(Object.assign({}, repo()), { ref: `tags/${tag}` }));
|
||||
core.warning(`Ignoring target_commit as the tag ${tag} already exists`);
|
||||
}
|
||||
catch (tagError) {
|
||||
if (tagError.status !== 404) {
|
||||
throw tagError
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
throw error;
|
||||
@ -167,13 +179,14 @@ function run() {
|
||||
const prerelease = core.getInput('prerelease') == 'true' ? true : false;
|
||||
const make_latest = core.getInput('make_latest') != 'false' ? true : false;
|
||||
const release_name = core.getInput('release_name');
|
||||
const target_commit = core.getInput('target_commit');
|
||||
const body = core
|
||||
.getInput('body')
|
||||
.replace(/%0A/gi, '\n')
|
||||
.replace(/%0D/gi, '\r')
|
||||
.replace(/%25/g, '%');
|
||||
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) {
|
||||
const files = glob.sync(file);
|
||||
if (files.length > 0) {
|
||||
|
24
src/main.ts
24
src/main.ts
@ -7,6 +7,7 @@ import * as path from 'path'
|
||||
import * as glob from 'glob'
|
||||
import {retry} from '@lifeomic/attempt'
|
||||
|
||||
const getRef = 'GET /repos/{owner}/{repo}/git/ref/{ref}' as const
|
||||
const releaseByTag = 'GET /repos/{owner}/{repo}/releases/tags/{tag}' as const
|
||||
const createRelease = 'POST /repos/{owner}/{repo}/releases' as const
|
||||
const updateRelease =
|
||||
@ -33,7 +34,8 @@ async function get_release_by_tag(
|
||||
body: string,
|
||||
octokit: Octokit,
|
||||
overwrite: boolean,
|
||||
promote: boolean
|
||||
promote: boolean,
|
||||
target_commit: string
|
||||
): Promise<ReleaseByTagResp | CreateReleaseResp | UpdateReleaseResp> {
|
||||
let release: ReleaseByTagResp
|
||||
try {
|
||||
@ -48,13 +50,27 @@ async function get_release_by_tag(
|
||||
core.debug(
|
||||
`Release for tag ${tag} doesn't exist yet so we'll create it now.`
|
||||
)
|
||||
if (target_commit) {
|
||||
try {
|
||||
await octokit.request(getRef, {
|
||||
...repo(),
|
||||
ref: `tags/${tag}`
|
||||
})
|
||||
core.warning(`Ignoring target_commit as the tag ${tag} already exists`)
|
||||
} catch (tagError: any) {
|
||||
if (tagError.status !== 404) {
|
||||
throw tagError
|
||||
}
|
||||
}
|
||||
}
|
||||
return await octokit.request(createRelease, {
|
||||
...repo(),
|
||||
tag_name: tag,
|
||||
prerelease: prerelease,
|
||||
make_latest: make_latest ? 'true' : 'false',
|
||||
name: release_name,
|
||||
body: body
|
||||
body: body,
|
||||
target_commitish: target_commit
|
||||
})
|
||||
} else {
|
||||
throw error
|
||||
@ -194,6 +210,7 @@ async function run(): Promise<void> {
|
||||
const prerelease = core.getInput('prerelease') == 'true' ? true : false
|
||||
const make_latest = core.getInput('make_latest') != 'false' ? true : false
|
||||
const release_name = core.getInput('release_name')
|
||||
const target_commit = core.getInput('target_commit')
|
||||
const body = core
|
||||
.getInput('body')
|
||||
.replace(/%0A/gi, '\n')
|
||||
@ -209,7 +226,8 @@ async function run(): Promise<void> {
|
||||
body,
|
||||
octokit,
|
||||
overwrite,
|
||||
promote
|
||||
promote,
|
||||
target_commit
|
||||
)
|
||||
|
||||
if (file_glob) {
|
||||
|
Loading…
Reference in New Issue
Block a user