From aee9ceabeee36fba1b662a6ce0ab6e07a692697a Mon Sep 17 00:00:00 2001 From: claeis Date: Mon, 23 Jan 2023 11:00:01 +0100 Subject: [PATCH] flag git tags as github release (#330) --- build.gradle | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/build.gradle b/build.gradle index 031e11a..b84b171 100644 --- a/build.gradle +++ b/build.gradle @@ -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" @@ -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)' @@ -193,5 +246,6 @@ task uploadBin(dependsOn: bindist) { include(name: releaseFile.name) } } + createGithubReleaseFunc() } } \ No newline at end of file