Skip to content

Commit

Permalink
Automate release publishing (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVeprev authored May 3, 2022
1 parent 5e64339 commit c2c8229
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
33 changes: 33 additions & 0 deletions jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,38 @@ pipeline {
}
}
}
stage('Release') {
agent any
when {
buildingTag()
}
steps {
unstash 'linux_build'
// Groovy variant of jenkins/make_release.sh
// TODO: implement in shared library
script {
response = httpRequest \
httpMode: 'POST', \
url: GIT_URL.replace(".git", "/releases").replace("github.com", "api.github.com/repos"), \
authentication: "token_github_releases", \
requestBody: "{\"tag_name\":\"${TAG_NAME}\",\"name\":\"${TAG_NAME}\"}", \
consoleLogResponseBody: true

def parsed_response = readJSON text: response.content
def release_id = parsed_response.id

def asset = findFiles(glob: '**/*.deb')[0]

httpRequest \
httpMode: 'POST', \
url: GIT_URL.replace(".git", "/releases/").replace("github.com", "uploads.github.com/repos") + release_id + "/assets?name=" + asset.name, \
authentication: "token_github_releases", \
uploadFile: asset.path, \
multipartName: asset.name, \
timeout: 900, \
consoleLogResponseBody: true
}
}
}
}
}
39 changes: 39 additions & 0 deletions jenkins/make_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# Bash variant was implemented as PoC and kept for reference, Groovy variant is actually used (see Jenkinsfile).
set -e -x

REPO=$1
TAG=$2
ASSET=$3

# Create release
curl \
-o release.json \
-w "%{http_code}" \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$REPO/releases \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"$TAG\"}" > http_code

cat release.json
echo "http_code: $(cat http_code)"
grep 201 http_code


# Attach asset
release_id=$(jq -r '.id' release.json)

curl \
-o release_asset.json \
-w "%{http_code}" \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: $(file -b --mime-type $ASSET)" \
--data-binary @$ASSET \
"https://uploads.github.com/repos/$REPO/releases/$release_id/assets?name=$(basename $ASSET)" > http_code

cat release_asset.json
echo "http_code: $(cat http_code)"
grep 201 http_code

0 comments on commit c2c8229

Please sign in to comment.