diff --git a/README.md b/README.md index ab767ad..450790e 100644 --- a/README.md +++ b/README.md @@ -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 `master`). - `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). diff --git a/action.yml b/action.yml index 7fd9e88..3763217 100644 --- a/action.yml +++ b/action.yml @@ -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 `master`).' 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: diff --git a/dist/index.js b/dist/index.js index 08f0c03..e33f950 100644 --- a/dist/index.js +++ b/dist/index.js @@ -51,7 +51,7 @@ 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 +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 (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 })); + 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 +167,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) { diff --git a/src/main.ts b/src/main.ts index f0a077a..2477109 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,7 +33,8 @@ async function get_release_by_tag( body: string, octokit: Octokit, overwrite: boolean, - promote: boolean + promote: boolean, + target_commit: string ): Promise { let release: ReleaseByTagResp try { @@ -54,7 +55,8 @@ async function get_release_by_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 +196,7 @@ async function run(): Promise { 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 +212,8 @@ async function run(): Promise { body, octokit, overwrite, - promote + promote, + target_commit ) if (file_glob) {