Skip to content

Commit bb71621

Browse files
committed
feat(publisher): Check that tag name starts with "v" #340
1 parent 65650ea commit bb71621

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/gitHubPublisher.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ export class GitHubPublisher implements Publisher {
4040
return this._releasePromise
4141
}
4242

43-
constructor(private owner: string, private repo: string, version: string, private options: PublishOptions, private isPublishOptionGuessed: boolean = false) {
43+
constructor(private owner: string, private repo: string, private version: string, private options: PublishOptions, private isPublishOptionGuessed: boolean = false) {
4444
if (isEmptyOrSpaces(options.githubToken)) {
4545
throw new Error("GitHub Personal Access Token is not specified")
4646
}
4747

4848
this.token = options.githubToken!
49-
this.policy = options.publish!
49+
this.policy = options.publish || "always"
5050

51-
this.tag = "v" + version
51+
if (version.startsWith("v")) {
52+
throw new Error(`Version must not starts with "v": ${version}`)
53+
}
54+
55+
this.tag = `v${version}`
5256
this._releasePromise = <BluebirdPromise<Release>>this.init()
5357
}
5458

@@ -75,6 +79,9 @@ export class GitHubPublisher implements Publisher {
7579
}
7680
return null
7781
}
82+
else if (release.tag_name === this.version) {
83+
throw new Error(`Tag name must starts with "v": ${release.tag_name}`)
84+
}
7885
}
7986

8087
if (createReleaseIfNotExists) {

src/targets/nsis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default class NsisTarget extends Target {
8484
defines.MUI_HEADERIMAGE_BITMAP = installerHeader
8585
}
8686

87-
const headerIcon = oneClick ? await this.getResource(this.options.installerHeader, "headerIcon.ico") : null
87+
const headerIcon = oneClick ? await this.getResource(this.options.headerIcon, "headerIcon.ico") : null
8888
if (headerIcon != null) {
8989
defines.HEADER_ICO = headerIcon
9090
}

test/src/ArtifactPublisherTest.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,28 @@ testAndIgnoreApiRate("prerelease", async () => {
7979
}
8080
})
8181

82+
testAndIgnoreApiRate("incorrect tag name", async () => {
83+
const publisher = new GitHubPublisher("actperepo", "ecb2", "5.0", {
84+
githubToken: token,
85+
draft: false,
86+
prerelease: true,
87+
publish: "onTagOrDraft",
88+
})
89+
try {
90+
await publisher.releasePromise
91+
//noinspection ExceptionCaughtLocallyJS
92+
throw new Error("No expected error")
93+
}
94+
catch (e) {
95+
if (e.message !== 'Tag name must starts with "v": 5.0') {
96+
throw e
97+
}
98+
}
99+
finally {
100+
await publisher.deleteRelease()
101+
}
102+
})
103+
82104
testAndIgnoreApiRate("GitHub upload org", async () => {
83105
//noinspection SpellCheckingInspection
84106
const publisher = new GitHubPublisher("builder-gh-test", "darpa", versionNumber(), {

0 commit comments

Comments
 (0)