mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-05-10 18:44:19 +00:00
use target_commitish to determine how to create tag rather than GITHUB_SHA
This commit is contained in:
parent
eb679c5bfa
commit
9985acca94
3 changed files with 37 additions and 5 deletions
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -79,6 +79,12 @@ export interface Releaser {
|
||||||
repo: string;
|
repo: string;
|
||||||
ref: string;
|
ref: string;
|
||||||
}) : Promise<any>;
|
}) : Promise<any>;
|
||||||
|
|
||||||
|
getRef(params: {
|
||||||
|
owner: string;
|
||||||
|
repo: string;
|
||||||
|
ref: string;
|
||||||
|
}) : Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GitHubReleaser implements Releaser {
|
export class GitHubReleaser implements Releaser {
|
||||||
|
@ -168,6 +174,14 @@ export class GitHubReleaser implements Releaser {
|
||||||
}) : Promise<any> {
|
}) : Promise<any> {
|
||||||
return this.github.rest.git.deleteRef(params);
|
return this.github.rest.git.deleteRef(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRef(params: {
|
||||||
|
owner: string;
|
||||||
|
repo: string;
|
||||||
|
ref: string;
|
||||||
|
}) : Promise<any> {
|
||||||
|
return this.github.rest.git.getRef(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const asset = (path: string): ReleaseAsset => {
|
export const asset = (path: string): ReleaseAsset => {
|
||||||
|
@ -328,6 +342,9 @@ export const release = async (
|
||||||
const make_latest = config.input_make_latest;
|
const make_latest = config.input_make_latest;
|
||||||
|
|
||||||
if(config.input_update_tag){
|
if(config.input_update_tag){
|
||||||
|
|
||||||
|
let newCommitSha = await getTargetCommit(target_commitish, releaser, owner, repo);
|
||||||
|
|
||||||
await releaser.deleteRef({
|
await releaser.deleteRef({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
|
@ -337,10 +354,10 @@ export const release = async (
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
ref: "refs/tags/"+existingRelease.tag_name,
|
ref: "refs/tags/"+existingRelease.tag_name,
|
||||||
sha: config.github_sha
|
sha: newCommitSha
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(`Updated ref/tags/${existingRelease.tag_name} to ${config.github_sha}`);
|
console.log(`Updated ref/tags/${existingRelease.tag_name} to ${newCommitSha}`);
|
||||||
|
|
||||||
// give github the time to draft the release before updating it
|
// 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
|
// Else, I think we would have a race condition with github to update the release
|
||||||
|
@ -448,6 +465,23 @@ async function createRelease(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getTargetCommit(target_commitish: string, releaser: Releaser, owner: string, repo: string) : Promise<string> {
|
||||||
|
if (target_commitish.length == 40) { // sha1 size
|
||||||
|
return target_commitish;
|
||||||
|
} else {
|
||||||
|
// assume it is a branch
|
||||||
|
let resp = await releaser.getRef({
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
ref: "heads/"+target_commitish,
|
||||||
|
})
|
||||||
|
if (resp.status == 404) {
|
||||||
|
throw new Error(`Branch ${target_commitish} not found`);
|
||||||
|
}
|
||||||
|
return resp.data.object.sha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { statSync, readFileSync } from "fs";
|
||||||
export interface Config {
|
export interface Config {
|
||||||
github_token: string;
|
github_token: string;
|
||||||
github_ref: string;
|
github_ref: string;
|
||||||
github_sha: string;
|
|
||||||
github_repository: string;
|
github_repository: string;
|
||||||
// user provided
|
// user provided
|
||||||
input_name?: string;
|
input_name?: string;
|
||||||
|
@ -57,7 +56,6 @@ export const parseConfig = (env: Env): Config => {
|
||||||
return {
|
return {
|
||||||
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || "",
|
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || "",
|
||||||
github_ref: env.GITHUB_REF || "",
|
github_ref: env.GITHUB_REF || "",
|
||||||
github_sha: env.GITHUB_SHA || "",
|
|
||||||
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || "",
|
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || "",
|
||||||
input_name: env.INPUT_NAME,
|
input_name: env.INPUT_NAME,
|
||||||
input_tag_name: env.INPUT_TAG_NAME?.trim(),
|
input_tag_name: env.INPUT_TAG_NAME?.trim(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue