diff --git a/packages/publisher/github/src/Config.ts b/packages/publisher/github/src/Config.ts index d54745caba..acd2b1ed91 100644 --- a/packages/publisher/github/src/Config.ts +++ b/packages/publisher/github/src/Config.ts @@ -43,4 +43,8 @@ export interface PublisherGitHubConfig { * Prepended to the package version to determine the release name (default "v") */ tagPrefix?: string; + /** + * Re-upload the new asset if you upload an asset with the same filename as existing asset + */ + force?: boolean; } diff --git a/packages/publisher/github/src/PublisherGithub.ts b/packages/publisher/github/src/PublisherGithub.ts index e7f8207962..ddfbebf00f 100644 --- a/packages/publisher/github/src/PublisherGithub.ts +++ b/packages/publisher/github/src/PublisherGithub.ts @@ -1,5 +1,3 @@ -import path from 'path'; - import { PublisherBase, PublisherOptions } from '@electron-forge/publisher-base'; import { ForgeMakeResult } from '@electron-forge/shared-types'; import { GetResponseDataTypeFromEndpointMethod } from '@octokit/types'; @@ -98,10 +96,19 @@ export default class PublisherGithub extends PublisherBase asset.name === artifactName)) { - return done(); + const asset = release!.assets.find((item: OctokitReleaseAsset) => item.name === artifactName); + if (asset !== undefined) { + if (config.force === true) { + await github.getGitHub().repos.deleteReleaseAsset({ + owner: config.repository.owner, + repo: config.repository.name, + asset_id: asset.id, + }); + } else { + return done(); + } } await github.getGitHub().repos.uploadReleaseAsset({ owner: config.repository.owner, @@ -116,7 +123,7 @@ export default class PublisherGithub extends PublisherBase { }).to.throw('Please set GITHUB_TOKEN in your environment to access these features'); }); }); + + describe('sanitizeName', () => { + it('should remove leading and trailing periods from the basename', () => { + expect(GitHub.sanitizeName('path/to/.foo.')).to.equal('foo'); + }); + + it('should remove multiple periods in a row', () => { + expect(GitHub.sanitizeName('path/to/foo..bar')).to.equal('foo.bar'); + }); + + it('should replace non-alphanumeric, non-hyphen characters with hyphens', () => { + expect(GitHub.sanitizeName('path/to/foo%$bar baz.')).to.equal('foo-bar-baz'); + }); + }); });