From d8d26e8bb817c7c559092583fee7ac2886f9a992 Mon Sep 17 00:00:00 2001 From: Kwan Koon Wa Date: Wed, 8 Aug 2018 16:54:53 +0800 Subject: [PATCH] Build with Jenkins --- Jenkinsfile | 24 ++++++++---------------- ci/centos/Dockerfile | 4 ++++ ci/debian/Dockerfile | 4 ++++ ci/release.sh | 8 ++++++-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e18cc62..3efd6ce 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,10 @@ pipeline { stage("Test and Build") { environment { CARGO = "~/.cargo/bin/cargo" + OAUTH = credentials("GitHub") + } + when { + branch 'master' } stages { stage("Debian") { @@ -22,7 +26,8 @@ pipeline { sh ''' LIBC_VERSION=$(ldd --version | head -n1 | sed -r 's/(.* )//') mkdir -p assets - tar -C target/release -czf assets/riffol-$LIBC_VERSION.tar.gz riffol + tar -C target/release -zcvf assets/riffol-libc-$LIBC_VERSION.tar.gz riffol + ci/release.sh riboseinc/riffol ''' } } @@ -42,25 +47,12 @@ pipeline { sh ''' LIBC_VERSION=$(ldd --version | head -n1 | sed -r 's/(.* )//') mkdir -p assets - tar -C target/release -czf assets/riffol-$LIBC_VERSION.tar.gz riffol + tar -C target/release -zcvf assets/riffol-libc-$LIBC_VERSION.tar.gz riffol + ci/release.sh riboseinc/riffol ''' } } } } - stage("Upload Assets") { - agent any - when { - branch 'master' - } - environment { - OAUTH = credentials("GitHub") - } - steps { - sh ''' - ci/release.sh riboseinc/riffol - ''' - } - } } } \ No newline at end of file diff --git a/ci/centos/Dockerfile b/ci/centos/Dockerfile index f3b0654..d521ec9 100644 --- a/ci/centos/Dockerfile +++ b/ci/centos/Dockerfile @@ -6,6 +6,10 @@ RUN useradd -u 1000 docker-user RUN su - docker-user -c 'curl https://sh.rustup.rs -sSf | sh -s -- -y && ~/.cargo/bin/cargo search nereon' +RUN curl -L -o/usr/bin/jq \ + https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 \ + && chmod +x /usr/bin/jq + RUN git clone https://github.com/vstakhov/libucl.git \ && cd libucl \ && ./autogen.sh \ diff --git a/ci/debian/Dockerfile b/ci/debian/Dockerfile index 6e384e7..5570ded 100644 --- a/ci/debian/Dockerfile +++ b/ci/debian/Dockerfile @@ -11,6 +11,10 @@ RUN useradd -u 1000 docker-user && \ RUN su - docker-user -c 'curl https://sh.rustup.rs -sSf | sh -s -- -y && ~/.cargo/bin/cargo search nereon' +RUN curl -L -o/usr/bin/jq \ + https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 \ + && chmod +x /usr/bin/jq + RUN git clone https://github.com/vstakhov/libucl.git \ && cd libucl \ && ./autogen.sh \ diff --git a/ci/release.sh b/ci/release.sh index 15cdc91..2e00874 100755 --- a/ci/release.sh +++ b/ci/release.sh @@ -35,7 +35,8 @@ release_id=$( # create a release if none already for this version if [ -z $release_id ]; then echo "Creating release for $version" - release_id=$(curl -s -X POST -d '{"tag_name":"$version"}' $release?access_token=$OAUTH | jq -r '"\(.id)"' 2>/dev/null) + + release_id=$(curl -s -X POST -d '{"tag_name":"'$version'"}' $release?access_token=$OAUTH | jq -r '"\(.id)"' 2>/dev/null) echo "Release ID: $release_id" @@ -50,8 +51,11 @@ fi # get upload url upload=$(curl -s $release/$release_id?access_token=$OAUTH | jq -r '"\(.upload_url)"' | cut -d'{' -f1) for i in assets/*.tar.gz; do + echo "Asset: $i" + if [ -f $i ]; then asset_name=$(basename $i) + echo "Asset name: $asset_name" asset_id=$( curl -s $release/$release_id/assets?access_token=$OAUTH \ | jq -r '.[] | "\(.name) \(.id)"' \ @@ -64,6 +68,6 @@ for i in assets/*.tar.gz; do fi # upload asset echo "Uploading $asset_name asset" - curl -s -X POST -H "Content-type: application/gzip" -d@- "$upload?name=$asset_name&access_token=$OAUTH" <$i >/dev/null + curl -X POST -H "Content-Type: application/tar+gzip" --data-binary @"$i" "$upload?name=$asset_name&access_token=$OAUTH" >/dev/null fi done