Skip to content

Commit eb4ced4

Browse files
authored
CI - upload build artifacts to GitHub (#20)
* upload bistreams to GitHub for tags * fix credentialsId * fix credentialsId / 2 * fix credentialsId / 3 * fix credentialsId / 4 * fix credentialsId / 5 * fix credentialsId / 6 * fix credentialsId / 7 * fix credentialsId / 8 * fix credentialsId / 9 * fix credentialsId / 10 * fix credentialsId / 11 * fix credentialsId / 12 * fix credentialsId / 13 * fix credentialsId / 14 * fix credentialsId / 15
1 parent 354d8c1 commit eb4ced4

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

Jenkinsfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ pipeline {
6363
sh("cp firmware/FT0/*/build/*_logs.tar.gz ${TARGET_DIR}")
6464
}
6565
}
66+
stage('Upload release to GitHub') {
67+
steps {
68+
withCredentials([usernamePassword(credentialsId: '0b0ce405-9ce8-4ffb-b200-0cfe67114fa6',
69+
usernameVariable: 'GITHUB_APP',
70+
passwordVariable: 'GITHUB_ACCESS_TOKEN')]) {
71+
sh('./software/ci/make_release.sh')
72+
}
73+
}
74+
}
6675
stage('Update latest') {
6776
when {
6877
branch 'master'
@@ -71,5 +80,5 @@ pipeline {
7180
sh('cd ${BITSTREAMS_DIR} && ln -sfn ${BUILD_DIR} latest && cd -')
7281
}
7382
}
74-
}
83+
}
7584
}

software/ci/make_release.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
set -x
4+
set -e
5+
6+
# adapted from https://medium.com/@systemglitch/continuous-integration-with-jenkins-and-github-release-814904e20776
7+
8+
9+
# Publish on github
10+
echo "Publishing on Github..."
11+
token=${GITHUB_ACCESS_TOKEN}
12+
13+
git fetch --tags
14+
15+
# Get the last tag name
16+
tag=$(git describe --tags)
17+
18+
if [ X$tag == X ]; then
19+
echo "no tags found"
20+
exit
21+
fi
22+
23+
# Get the full message associated with this tag
24+
message="$(git for-each-ref refs/tags/$tag --format='%(contents)')"
25+
26+
# Get the title and the description as separated variables
27+
name=$(echo "$message" | head -n1)
28+
description=$(echo "$message" | tail -n +3)
29+
description=$(echo "$description" | sed -z 's/\n/\\n/g') # Escape line breaks to prevent json parsing problems
30+
31+
# Create a release
32+
release=$(curl -XPOST -H "Authorization:token $token" \
33+
--data "{\"tag_name\": \"$tag\", \"target_commitish\": \"master\", \"name\": \"$name\", \"body\": \"$description\", \"draft\": false, \"prerelease\": true}" \
34+
https://api.github.com/repos/AliceO2Group/alice-fit-fpga/releases)
35+
36+
# Extract the id of the release from the creation response
37+
id=$(echo "$release" | sed -n -e 's/"id":\ \([0-9]\+\),/\1/p' | head -n 1 | sed 's/[[:blank:]]//g')
38+
39+
# create the build artifact to be uploaded to GitHub
40+
cd ${BITSTREAMS_DIR}
41+
ARTIFACT=${BUILD_DIR}.tar.bz2
42+
rm -f ${ARTIFACT} && tar cvf - ${BUILD_DIR} | bzip2 -9 - > ${ARTIFACT}
43+
44+
# Upload the artifact
45+
curl -XPOST -H "Authorization:token $token" \
46+
-H "Content-Type:application/octet-stream" \
47+
--data-binary @${ARTIFACT} https://uploads.github.com/repos/AliceO2Group/alice-fit-fpga/releases/$id/assets?name=${ARTIFACT}

0 commit comments

Comments
 (0)