Skip to content

Commit

Permalink
delete and re-create tag
Browse files Browse the repository at this point in the history
  • Loading branch information
iTrooz committed Dec 18, 2022
1 parent 2e17c09 commit e24bc15
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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 {
Expand Down Expand Up @@ -121,6 +134,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 => {
Expand Down Expand Up @@ -309,6 +339,26 @@ export const release = async (
? config.input_prerelease
: existingRelease.prerelease;

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,
Expand All @@ -325,3 +375,7 @@ export const release = async (
return release.data;
}
};

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

0 comments on commit e24bc15

Please sign in to comment.