mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-05-10 18:44:19 +00:00
add 'update_tag' option
This commit is contained in:
parent
c062e08bd5
commit
eb679c5bfa
5 changed files with 69 additions and 8 deletions
|
@ -194,6 +194,7 @@ The following are optional as `step.with` keys
|
|||
| `generate_release_notes` | Boolean | Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise, a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes. See the [GitHub docs for this feature](https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes) for more information |
|
||||
| `append_body` | Boolean | Append to existing body instead of overwriting it |
|
||||
| `make_latest` | String | Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. Can be `true`, `false`, or `legacy`. Uses GitHub api defaults if not provided |
|
||||
| `update_tag` | Boolean | Update the tag of the release to the current commit. This will also update the release time. Default is false |
|
||||
|
||||
💡 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.
|
||||
|
|
|
@ -49,6 +49,8 @@ inputs:
|
|||
make_latest:
|
||||
description: "Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. Can be `true`, `false`, or `legacy`. Uses GitHub api default if not provided"
|
||||
required: false
|
||||
update_tag:
|
||||
description: "Update the tag of the release to the current commit. This will also update the release time."
|
||||
env:
|
||||
GITHUB_TOKEN: "As provided by Github Actions"
|
||||
outputs:
|
||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -66,6 +66,19 @@ export interface Releaser {
|
|||
owner: string;
|
||||
repo: string;
|
||||
}): AsyncIterableIterator<{ data: Release[] }>;
|
||||
|
||||
createRef(params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
ref: string;
|
||||
sha: string;
|
||||
}) : Promise<any>;
|
||||
|
||||
deleteRef(params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
ref: string;
|
||||
}) : Promise<any>;
|
||||
}
|
||||
|
||||
export class GitHubReleaser implements Releaser {
|
||||
|
@ -138,6 +151,23 @@ export class GitHubReleaser implements Releaser {
|
|||
this.github.rest.repos.listReleases.endpoint.merge(updatedParams),
|
||||
);
|
||||
}
|
||||
|
||||
createRef(params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
ref: string;
|
||||
sha: string;
|
||||
}) : Promise<any> {
|
||||
return this.github.rest.git.createRef(params);
|
||||
}
|
||||
|
||||
deleteRef(params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
ref: string;
|
||||
}) : Promise<any> {
|
||||
return this.github.rest.git.deleteRef(params);
|
||||
}
|
||||
}
|
||||
|
||||
export const asset = (path: string): ReleaseAsset => {
|
||||
|
@ -224,18 +254,18 @@ export const release = async (
|
|||
// so we must find one in the list of all releases
|
||||
let _release: Release | undefined = undefined;
|
||||
if (config.input_draft) {
|
||||
for await (const response of releaser.allReleases({
|
||||
owner,
|
||||
repo,
|
||||
})) {
|
||||
for await (const response of releaser.allReleases({
|
||||
owner,
|
||||
repo,
|
||||
})) {
|
||||
_release = response.data.find((release) => release.tag_name === tag);
|
||||
}
|
||||
} else {
|
||||
_release = (
|
||||
await releaser.getReleaseByTag({
|
||||
owner,
|
||||
repo,
|
||||
tag,
|
||||
owner,
|
||||
repo,
|
||||
tag,
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
@ -297,6 +327,26 @@ export const release = async (
|
|||
|
||||
const make_latest = config.input_make_latest;
|
||||
|
||||
if(config.input_update_tag){
|
||||
await releaser.deleteRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: "tags/"+existingRelease.tag_name,
|
||||
});
|
||||
await releaser.createRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: "refs/tags/"+existingRelease.tag_name,
|
||||
sha: config.github_sha
|
||||
})
|
||||
|
||||
console.log(`Updated ref/tags/${existingRelease.tag_name} to ${config.github_sha}`);
|
||||
|
||||
// give github the time to draft the release before updating it
|
||||
// Else, I think we would have a race condition with github to update the release
|
||||
await sleep(2000);
|
||||
}
|
||||
|
||||
const release = await releaser.updateRelease({
|
||||
owner,
|
||||
repo,
|
||||
|
@ -397,3 +447,7 @@ async function createRelease(
|
|||
return release(config, releaser, maxRetries - 1);
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import { statSync, readFileSync } from "fs";
|
|||
export interface Config {
|
||||
github_token: string;
|
||||
github_ref: string;
|
||||
github_sha: string;
|
||||
github_repository: string;
|
||||
// user provided
|
||||
input_name?: string;
|
||||
|
@ -20,6 +21,7 @@ export interface Config {
|
|||
input_generate_release_notes?: boolean;
|
||||
input_append_body?: boolean;
|
||||
input_make_latest: "true" | "false" | "legacy" | undefined;
|
||||
input_update_tag?: string;
|
||||
}
|
||||
|
||||
export const uploadUrl = (url: string): string => {
|
||||
|
@ -55,6 +57,7 @@ export const parseConfig = (env: Env): Config => {
|
|||
return {
|
||||
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || "",
|
||||
github_ref: env.GITHUB_REF || "",
|
||||
github_sha: env.GITHUB_SHA || "",
|
||||
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || "",
|
||||
input_name: env.INPUT_NAME,
|
||||
input_tag_name: env.INPUT_TAG_NAME?.trim(),
|
||||
|
@ -72,6 +75,7 @@ export const parseConfig = (env: Env): Config => {
|
|||
input_generate_release_notes: env.INPUT_GENERATE_RELEASE_NOTES == "true",
|
||||
input_append_body: env.INPUT_APPEND_BODY == "true",
|
||||
input_make_latest: parseMakeLatest(env.INPUT_MAKE_LATEST),
|
||||
input_update_tag: env.INPUT_UPDATE_TAG,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue