Skip to content

Commit

Permalink
flag git tags as github release (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
claeis committed Jan 23, 2023
1 parent 8b0b7a9 commit aee9cea
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def downloads_pwd = System.getProperty('downloads_pwd',properties.get('downloads
def downloads_usr = System.getProperty('downloads_usr',properties.get('downloads_usr','downloads_usr'))
def python= System.getProperty('python',properties.get('python','python'))
def rst2html= System.getProperty('rst2html',properties.get('rst2html','rst2html'))
def github_token= System.getProperty('github_token',properties.get('github_token','github_token'))

def generatedResources = "$buildDir/generated-resources/main"

Expand Down Expand Up @@ -107,6 +108,58 @@ task generateMyResources {
}
}

def readChangeLog = { ->
def resp=""
def skip=false
def sec=0
new File("docs/CHANGELOG.txt").eachLine { line ->
if(line.startsWith("-------")){
sec++
}else{
if(sec==1){
if(skip){
}else{
if(line.trim()==""){
skip=true
}else{
resp+=line+"\n"
}
}
}
}
}
return resp
}
task readChanges {
doLast {
logger.quiet "----"
logger.quiet readChangeLog()
logger.quiet "----"
}
}
def createGithubReleaseFunc = { ->
def body = [tag_name:"$project.name-$project.version",name:"$project.name-$project.version",body:readChangeLog(),draft:false,prerelease:false,generate_release_notes:false]
def req = new URL("https://api.github.com/repos/claeis/$project.name/releases").openConnection()
req.setRequestMethod("POST")
req.setRequestProperty("Content-Type", "application/json; charset=UTF-8")
req.setRequestProperty("Accept", "application/vnd.github+json")
req.setRequestProperty("Authorization", "Bearer $github_token")
req.setRequestProperty("X-GitHub-Api-Version", "2022-11-28")
req.setDoOutput(true)
req.getOutputStream().write(groovy.json.JsonOutput.toJson(body).getBytes("UTF-8"))
if(req.getResponseCode()!=201){
logger.quiet "Status code: ${req.getResponseCode()}" // HTTP request done on first read
def resp = new groovy.json.JsonSlurper().parseText(req.getInputStream().getText())
logger.quiet "Response: ${resp}"
}
return
}
task createGithubRelease {
doLast {
createGithubReleaseFunc()
}
}

task usrdoc(type:Exec) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = 'Builds the user documentation (html)'
Expand Down Expand Up @@ -193,5 +246,6 @@ task uploadBin(dependsOn: bindist) {
include(name: releaseFile.name)
}
}
createGithubReleaseFunc()
}
}

0 comments on commit aee9cea

Please sign in to comment.