@@ -807,36 +807,45 @@ pipeline {
807807 }
808808 options{
809809 lock(" ${ env.JOB_NAME} " )
810- // This has to be do "checkout scm" anyways to get the hash so there is no reason the check it out twice
811- skipDefaultCheckout true
812810 }
813811 steps{
814- unstash ' PYTHON_PACKAGES'
815812 script {
816- def scmVars = checkout scm
817813 def projectMetadata = readTOML( file : ' pyproject.toml' )[' project' ]
818- writeFile(
819- file : ' body.md' ,
820- text : " ${ projectMetadata.name} Version ${ projectMetadata.version} Release"
821-
822- )
823- createGitHubRelease(
824- credentialId : " ${ GITHUB_CREDENTIALS_ID} " ,
825- repository : env. GITHUB_REPO ,
826- tag : env. BRANCH_NAME ,
827- commitish : scmVars. GIT_COMMIT ,
828- bodyFile : ' body.md' ,
829- )
830- def assets = []
831- findFiles(glob : ' dist/*' ). each{
832- assets << [filePath : " ${ it.path} " ]
814+ withCredentials([string(credentialsId : GITHUB_CREDENTIALS_ID , variable : ' GITHUB_TOKEN' )]) {
815+ def requestBody = JsonOutput . toJson([
816+ tag_name : env. BRANCH_NAME ,
817+ name : " Version ${ projectMetadata.version} " ,
818+ generate_release_notes : false ,
819+ draft : false ,
820+ prerelease : false
821+ ])
822+ def createReleaseResponse = httpRequest(
823+ httpMode : ' POST' ,
824+ contentType : ' APPLICATION_JSON' ,
825+ url : " https://api.github.com/repos/UIUCLibrary/tripwire/releases" ,
826+ customHeaders : [
827+ [name : ' Authorization' , value : " token ${ GITHUB_TOKEN} " ]
828+ ],
829+ requestBody : requestBody,
830+ validResponseCodes : ' 201' // Expect a 201 Created status code
831+ )
832+ unstash ' PYTHON_PACKAGES'
833+ def releaseData = readJSON text : createReleaseResponse. content
834+ findFiles(glob : ' dist/*' ). each{
835+ def uploadResponse = httpRequest(
836+ url : " ${ releaseData.upload_url.replace('{?name,label}', '')} ?name=${ it.name} " ,
837+ httpMode : ' POST' ,
838+ uploadFile : it. path,
839+ customHeaders : [[name : ' Authorization' , value : " token ${ GITHUB_TOKEN} " ]],
840+ wrapAsMultipart : false
841+ )
842+ if (uploadResponse. status >= 200 && uploadResponse. status < 300 ) {
843+ echo " File uploaded successfully to GitHub release."
844+ } else {
845+ error " Failed to upload file: ${ uploadResponse.status} - ${ uploadResponse.content} "
846+ }
847+ }
833848 }
834- uploadGithubReleaseAsset(
835- credentialId : " ${ GITHUB_CREDENTIALS_ID} " ,
836- repository : env. GITHUB_REPO ,
837- tagName : env. BRANCH_NAME ,
838- uploadAssets : assets
839- )
840849 }
841850 }
842851 post{
0 commit comments