-
-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add 'update_tag' option #293
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,25 @@ 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>; | ||
|
||
getRef(params: { | ||
owner: string; | ||
repo: string; | ||
ref: string; | ||
}) : Promise<any>; | ||
} | ||
|
||
export class GitHubReleaser implements Releaser { | ||
|
@@ -138,6 +157,31 @@ 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); | ||
} | ||
|
||
getRef(params: { | ||
owner: string; | ||
repo: string; | ||
ref: string; | ||
}) : Promise<any> { | ||
return this.github.rest.git.getRef(params); | ||
} | ||
} | ||
|
||
export const asset = (path: string): ReleaseAsset => { | ||
|
@@ -224,18 +268,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 +341,29 @@ export const release = async ( | |
|
||
const make_latest = config.input_make_latest; | ||
|
||
if(config.input_update_tag){ | ||
|
||
let newCommitSha = await getTargetCommit(target_commitish, releaser, owner, repo); | ||
|
||
await releaser.deleteRef({ | ||
owner, | ||
repo, | ||
ref: "tags/"+existingRelease.tag_name, | ||
}); | ||
await releaser.createRef({ | ||
owner, | ||
repo, | ||
ref: "refs/tags/"+existingRelease.tag_name, | ||
sha: newCommitSha | ||
}) | ||
|
||
console.log(`Updated ref/tags/${existingRelease.tag_name} to ${newCommitSha}`); | ||
|
||
// 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is something inherently unreliable and inefficient about relying on time as a synchronization primitive It’s possible that sleeping 2 seconds isn’t long enough resulting in a noneffective approach and it is also possible that is is way to long resulting in wasted gh action time. Is it possible to restructure this without so that it’s not time dependent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fully understand why sleeping is not a perfect solution. Another solution that could work would be to make a request to the github API every second to check if the draft was done yet. Would you prefer this ? |
||
} | ||
|
||
const release = await releaser.updateRelease({ | ||
owner, | ||
repo, | ||
|
@@ -397,3 +464,24 @@ async function createRelease( | |
return release(config, releaser, maxRetries - 1); | ||
} | ||
} | ||
|
||
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) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some reservations about this. Action gh release is an action for managing GitHub releases, the product feature
the concern is that with these changes the scope is increasing to also include managing git state something that feels possible with git itself external to this action.
Would it be possible to do that as a separate workflow step or possibly trigger that then triggers the workflow that manages gh release data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would definitively be possible to do this in another step, and I understand why this may be preferable to extending the scope of this action.
So at this point, it may be better to just use the solution described here : #171 (comment)