Skip to content

Commit

Permalink
fix: Don´t throw error if Release is not a Draft and build triggered …
Browse files Browse the repository at this point in the history
…by Tag

Closes #429
  • Loading branch information
develar committed May 31, 2016
1 parent 7166580 commit 0f060c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function createPublisher(packager: Packager, options: BuildOptions,
throw new Error("Please specify 'repository' in the dev package.json ('" + packager.devPackageFile + "')")
}
else {
return new GitHubPublisher(info.user, info.project, packager.metadata.version, options.githubToken!, options.publish !== "onTagOrDraft")
return new GitHubPublisher(info.user, info.project, packager.metadata.version, options.githubToken!, options.publish!)
}
}

Expand Down
20 changes: 14 additions & 6 deletions src/gitHubPublisher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Release, Asset } from "gh-release"
import { log } from "./util"
import { log, warn } from "./util"
import { basename } from "path"
import { parse as parseUrl } from "url"
import * as mime from "mime"
Expand Down Expand Up @@ -31,7 +31,7 @@ export class GitHubPublisher implements Publisher {
return this._releasePromise
}

constructor(private owner: string, private repo: string, version: string, private token: string | null, private createReleaseIfNotExists: boolean = true) {
constructor(private owner: string, private repo: string, version: string, private token: string | null, private policy: string = "always") {
if (token == null || token.length === 0) {
throw new Error("GitHub Personal Access Token is not specified")
}
Expand All @@ -41,23 +41,31 @@ export class GitHubPublisher implements Publisher {
}

private async init(): Promise<Release | null> {
const createReleaseIfNotExists = this.policy !== "onTagOrDraft"
// we don't use "Get a release by tag name" because "tag name" means existing git tag, but we draft release and don't create git tag
const releases = await gitHubRequest<Array<Release>>(`/repos/${this.owner}/${this.repo}/releases`, this.token)
for (let release of releases) {
if (release!.tag_name === this.tag) {
if (!release!.draft) {
if (this.createReleaseIfNotExists) {
if (release.tag_name === this.tag) {
if (!release.draft) {
if (this.policy === "onTag") {
throw new Error("Release must be a draft")
}
else {
const message = `Release ${this.tag} is not a draft, artifacts will be not published`
if (this.policy === "always") {
warn(message)
}
else {
log(message)
}
return null
}
}
return release!
}
}

if (this.createReleaseIfNotExists) {
if (createReleaseIfNotExists) {
log("Release %s doesn't exists, creating one", this.tag)
return this.createRelease()
}
Expand Down
8 changes: 4 additions & 4 deletions test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ test.ifNotCiOsx("win", () => assertPack("test-app-one", signed({
})
))

test.ifNotCiOsx("win 32", () => assertPack("test-app-one", signed({
targets: Platform.WINDOWS.createTarget(null, Arch.ia32),
})
))
// test.ifNotCiOsx("win 32", () => assertPack("test-app-one", signed({
// targets: Platform.WINDOWS.createTarget(null, Arch.ia32),
// })
// ))

// very slow
test.ifWinCi("delta", () => assertPack("test-app-one", {
Expand Down

0 comments on commit 0f060c1

Please sign in to comment.