pipeline { agent { docker { image 'rbehzadan/golang:1.22.1' } } environment { GITEA_API_TOKEN = credentials('git.behzadan.ir') } stages { stage('Build') { steps { sh 'make build' } } stage('Test') { steps { sh 'make test' } } stage('Package') { steps { sh 'make package' } } stage('Upload Release') { steps { script { def repoOwner = 'reza' def repoName = 'go-hello-world' def tagName = 'v1.0.1' def releaseTitle = 'v1.0.1' def releaseDescription = 'v1.0.1' def zipFile = 'hello-world.zip' def createReleaseResponse = sh(script: """ curl -s -X POST -H "Content-Type: application/json" -H "Authorization: token ${GITEA_API_TOKEN}" \\ -d '{ "tag_name": "${tagName}", "target_commitish": "main", "name": "${releaseTitle}", "body": "${releaseDescription}", "draft": false, "prerelease": false }' \\ "https://git.behzadan.ir/api/v1/repos/${repoOwner}/${repoName}/releases" """, returnStdout: true).trim() def parsedResponse = readJSON text: createReleaseResponse def releaseID = parsedResponse.id sh """ curl -X POST -H "Authorization: token ${GITEA_API_TOKEN}" -H "Content-Type: multipart/form-data" \\ --data-binary @${zipFile} \\ "https://git.behzadan.ir/api/v1/repos/${repoOwner}/${repoName}/releases/${releaseID}/assets?name=${zipFile}" """ } } } stage('Cleanup') { steps { sh 'make clean' } } } }