Skip to content

Commit

Permalink
feat: 🎸 allow specifying alternative tag prefix (#2605)
Browse files Browse the repository at this point in the history
Add configuration option `tagPrefix`, that if set, overrides the default
"v" when determining the corresponding tag name for GitHub releases.

✅ Closes: #1790
  • Loading branch information
Tyler Brandt authored Jun 9, 2022
1 parent 6977740 commit 88d9d72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/publisher/github/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ export interface PublisherGitHubConfig {
* Whether or not this release should be tagged as a draft
*/
draft?: boolean;
/**
* Prepended to the package version to determine the release name (default "v")
*/
tagPrefix?: string;
}
17 changes: 9 additions & 8 deletions packages/publisher/github/src/PublisherGithub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class PublisherGithub extends PublisherBase<PublisherGitHubConfig
const { config } = this;

const perReleaseArtifacts: {
[release: string]: ForgeMakeResult[];
[version: string]: ForgeMakeResult[];
} = {};

for (const makeResult of makeResults) {
Expand All @@ -50,9 +50,10 @@ export default class PublisherGithub extends PublisherBase<PublisherGitHubConfig
type OctokitRelease = GetResponseDataTypeFromEndpointMethod<typeof octokit.repos.getRelease>;
type OctokitReleaseAsset = GetResponseDataTypeFromEndpointMethod<typeof octokit.repos.updateReleaseAsset>;

for (const releaseName of Object.keys(perReleaseArtifacts)) {
for (const releaseVersion of Object.keys(perReleaseArtifacts)) {
let release: OctokitRelease | undefined;
const artifacts = perReleaseArtifacts[releaseName];
const artifacts = perReleaseArtifacts[releaseVersion];
const releaseName = `${config.tagPrefix ?? 'v'}${releaseVersion}`;

await asyncOra(`Searching for target release: ${releaseName}`, async () => {
try {
Expand All @@ -62,7 +63,7 @@ export default class PublisherGithub extends PublisherBase<PublisherGitHubConfig
repo: config.repository.name,
per_page: 100,
})
).data.find((testRelease: GitHubRelease) => testRelease.tag_name === `v${releaseName}`);
).data.find((testRelease: GitHubRelease) => testRelease.tag_name === releaseName);
if (!release) {
throw new NoReleaseError(404);
}
Expand All @@ -73,8 +74,8 @@ export default class PublisherGithub extends PublisherBase<PublisherGitHubConfig
await github.getGitHub().repos.createRelease({
owner: config.repository.owner,
repo: config.repository.name,
tag_name: `v${releaseName}`,
name: `v${releaseName}`,
tag_name: releaseName,
name: releaseName,
draft: config.draft !== false,
prerelease: config.prerelease === true,
})
Expand All @@ -87,9 +88,9 @@ export default class PublisherGithub extends PublisherBase<PublisherGitHubConfig
});

let uploaded = 0;
await asyncOra(`Uploading Artifacts ${uploaded}/${artifacts.length} to v${releaseName}`, async (uploadSpinner) => {
await asyncOra(`Uploading Artifacts ${uploaded}/${artifacts.length} to ${releaseName}`, async (uploadSpinner) => {
const updateSpinner = () => {
uploadSpinner.text = `Uploading Artifacts ${uploaded}/${artifacts.length} to v${releaseName}`;
uploadSpinner.text = `Uploading Artifacts ${uploaded}/${artifacts.length} to ${releaseName}`;
};

const flatArtifacts: string[] = [];
Expand Down

0 comments on commit 88d9d72

Please sign in to comment.