Created
September 23, 2014 11:13
-
-
Save issue2k/f70a46f13e7657003750 to your computer and use it in GitHub Desktop.
Gradle github release task with single asset upload example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.kohsuke.github.GitHub | |
import org.kohsuke.github.GHRepository | |
import org.kohsuke.github.GHOrganization | |
import org.kohsuke.github.GHReleaseBuilder | |
import org.kohsuke.github.GHRelease | |
class GithubReleaseTask extends DefaultTask { | |
@Input | |
public String authToken | |
@Input | |
public String organization | |
@Input | |
public String repository | |
protected CharSequence input | |
void setInputFile(CharSequence file) { | |
this.input = file | |
} | |
void setInputFile(File file) { | |
this.input = file.path | |
} | |
@InputFile | |
File getInputFile() { | |
return project.file(this.input) | |
} | |
@TaskAction | |
def release() { | |
Date date = new Date() | |
GitHub github = GitHub.connectUsingOAuth(authToken) | |
GHOrganization organization = github.getOrganization(organization) | |
GHRepository repository = organization.getRepository(repository) | |
GHReleaseBuilder releaseBuilder = backend.createRelease("v${->project.version}") | |
releaseBuilder.body("Release automatically created on $date") | |
releaseBuilder.draft(false) | |
releaseBuilder.name("v${->project.version}") | |
GHRelease release = releaseBuilder.create() | |
release.uploadAsset(this.getInputFile(), "application/octet-stream") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment