Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ci): reorganize CI related code #201

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions .auto-release.sh

This file was deleted.

28 changes: 28 additions & 0 deletions .ci/general-jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Copyright 2019 The Grin Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script contains general jobs.

case "${CI_JOB}" in
"test")
for dir in ${CI_JOB_ARGS}; do
printf "executing tests in directory \`%s\`...\n" "${dir}"
cd "${dir}" && \
cargo test --release && \
cd - > /dev/null || exit 1
done
;;
esac
32 changes: 32 additions & 0 deletions .ci/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Copyright 2019 The Grin Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script contains installation related code.

# Redeclare CI and VCP specific environment variables
# to make future migration to other providers easier.
readonly OS_NAME="${TRAVIS_OS_NAME}"

case "${OS_NAME}" in
"linux")
readonly CUDA_PGK="cuda-repo-ubuntu1604_10.0.130-1_amd64.deb"
readonly CUDA_REPO="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64"
wget "${CUDA_REPO}/${CUDA_PGK}"
sudo dpkg -i "${CUDA_PGK}"
sudo apt-key adv --fetch-keys "${CUDA_REPO}/7fa2af80.pub"
sudo apt-get update
sudo apt-get install cuda
esac
122 changes: 122 additions & 0 deletions .ci/release-jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env bash

# Copyright 2019 The Grin Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script contains release-related jobs.

# Redeclare CI and VCP specific environment variables
# to make future migration to other providers easier.
readonly JOB_ID="${TRAVIS_JOB_ID}"
readonly OS_NAME="${TRAVIS_OS_NAME}"
readonly TEST_RESULT="${TRAVIS_TEST_RESULT}"
readonly VCP_AUTH_TOKEN="${GITHUB_TOKEN}"

case "${CI_JOB}" in
"release")
# The release can only be triggered after successful completion of all tests.
[[ "${TEST_RESULT}" != 0 ]] && exit 1

readonly BIN_NAME="grin-miner"
readonly REPO_TAG="$(git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD)"
readonly DEPLOY_DIR="deploy/${BIN_NAME}-${REPO_TAG}"

mkdir -p "${DEPLOY_DIR}"
cp "${BIN_NAME}.toml" "${DEPLOY_DIR}"
cp -R target/release/plugins "${DEPLOY_DIR}"

case "${OS_NAME}" in
"linux")
sed -i.bak 's/cuckoo_miner =/#cuckoo_miner =/g; s/##cuckoo_miner/cuckoo_miner/g' Cargo.toml
cargo clean && \
cargo build --release --features opencl
cp target/release/deps/libocl_cuckatoo.so "${DEPLOY_DIR}/plugins/ocl_cuckatoo.cuckooplugin"
cp target/release/deps/libocl_cuckaroo.so "${DEPLOY_DIR}/plugins/ocl_cuckaroo.cuckooplugin"
readonly ARCHIVE_CMD="tar zcf"
readonly BIN_SUFFIX=""
readonly PKG_NAME="${BIN_NAME}-${REPO_TAG}-${JOB_ID}-linux-amd64"
readonly PKG_SUFFIX=".tgz"
;;

"osx")
brew update
cargo clean && \
cargo build --release
readonly ARCHIVE_CMD="tar zcf"
readonly BIN_SUFFIX=""
readonly PKG_NAME="${BIN_NAME}-${REPO_TAG}-${JOB_ID}-osx"
readonly PKG_SUFFIX=".tgz"
;;

*)
printf "Error! Unknown \$OS_NAME: \`%s\`" "${OS_NAME}"
exit 1
esac

printf "creating package \`%s\` for the release binary...\n" "${PKG_NAME}${PKG_SUFFIX}"

cp "target/release/${BIN_NAME}" "${DEPLOY_DIR}"
cd deploy || exit 1
rm -f -- *"${PKG_SUFFIX}"
${ARCHIVE_CMD} "${PKG_NAME}${PKG_SUFFIX}" "${BIN_NAME}${BIN_SUFFIX}"
ls -ls -- *.tgz | cut -d' ' -f6-
openssl md5 "${PKG_NAME}${PKG_SUFFIX}" > "${PKG_NAME}${PKG_SUFFIX}-md5sum.txt"
ls -ls -- *-md5sum.txt | cut -d' ' -f6-
cd - > /dev/null || exit 1

printf "%s package \`%s\` generated\n" "${OS_NAME}" "${PKG_NAME}${PKG_SUFFIX}"

# Generate changelog only on the Linux platform to avoid duplication.
[[ "${OS_NAME}" != "linux" ]] && exit 0

# Generate CHANGELOG.md
readonly REPO_SLUG="mimblewimble/${BIN_NAME}"
readonly REPO_BRANCH="$(git symbolic-ref -q --short HEAD)"
readonly REPO_PREV_RELEASE_TAG="$(git describe --abbrev=0 --tags "$(git rev-list --tags --skip=0 --max-count=1)")"

gem install github_changelog_generator

# Needed by github_changelog_generator.
export CHANGELOG_GITHUB_TOKEN="${VCP_AUTH_TOKEN}"

github_changelog_generator \
--user "$(cut -d "/" -f1 <<< ${REPO_SLUG})" \
--project "$(cut -d "/" -f2 <<< ${REPO_SLUG})" \
--since-tag "${REPO_PREV_RELEASE_TAG}"

readonly CHANGELOG_CONTENT="$(<CHANGELOG.md)"

# Overwrite CHANGELOG.md with JSON data for release patch.
jq --null-input \
--arg body "${CHANGELOG_CONTENT}" \
--arg name "${REPO_TAG}" \
--arg tag_name "${REPO_TAG}" \
--arg target_commitish "${REPO_BRANCH}" \
'{
body: $body,
name: $name,
tag_name: $tag_name,
target_commitish: $target_commitish,
draft: false,
prerelease: false
}' > CHANGELOG.md

readonly HEADERS="Authorization: token ${VCP_AUTH_TOKEN}"
readonly RELEASE_URL="https://api.github.com/repos/${REPO_SLUG}/releases"

printf "updating release changelog %s for repo: %s, branch: %s\n" "${REPO_TAG}" "${REPO_SLUG}" "${REPO_BRANCH}"
curl -H "${HEADERS}" --request POST --data @CHANGELOG.md "${RELEASE_URL}"
printf "changelog uploaded.\n"
;;
esac
81 changes: 34 additions & 47 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
language: rust

git:
depth: false
# Copyright 2019 The Grin Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

dist: xenial
sudo: required

cache:
cargo: true
timeout: 240
directories:
- $HOME/.cargo
- $TRAVIS_BUILD_DIR/target

before_cache:
- rm -rf $TRAVIS_BUILD_DIR/target/tmp
language: rust

rust:
- stable

git:
depth: false

addons:
apt:
sources:
Expand All @@ -34,6 +38,14 @@ addons:
- binutils-dev
- ocl-icd-opencl-dev
- wget
- gnupg-curl

cache:
cargo: true
timeout: 240
directories:
- $HOME/.cargo
- $TRAVIS_BUILD_DIR/target

env:
global:
Expand All @@ -43,46 +55,21 @@ env:
matrix:
include:
- os: linux
env: TEST_SUITE=cuckoo-miner
env: CI_JOB="test" CI_JOB_ARGS="cuckoo-miner"
- os: linux
env: TEST_SUITE=release
env: CI_JOB="release" CI_JOB_ARGS=
- os: osx
env: TEST_SUITE=release
env: CI_JOB="release" CI_JOB_ARGS=

# install CUDA 10 on ubuntu 16.04 via DEB from directions here
# https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=debnetwork
install:
- ./.travis/install.sh

script:
- IFS=',' read -r -a DIRS <<< "$TEST_SUITE"; DIR=${DIRS[0]};
echo "start testing on folder $DIR...";
if [[ -n "$DIR" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]] && [[ "$DIR" != "release" ]]; then cd $DIR && cargo test --release && cd - > /dev/null; fi;
- IFS=',' read -r -a DIRS <<< "$TEST_SUITE"; DIR=${DIRS[1]};
if [[ -n "$DIR" ]]; then
echo "start testing on folder $DIR...";
cd $DIR && cargo test --release && cd - > /dev/null;
fi;
- IFS=',' read -r -a DIRS <<< "$TEST_SUITE"; DIR=${DIRS[2]};
if [[ -n "$DIR" ]]; then
echo "start testing on folder $DIR...";
cd $DIR && cargo test --release && cd - > /dev/null;
fi;
install: .ci/install

# NB, we won't be able to build cuckatoo 31 + CUDA plugins until travis supports
# ubuntu bionic beaver (18.04), which contains CUDA 10
# For now, we need to use xenial (16.04) which uses CUDA 7.5, sufficient to build
# cuckaroo29 using sm_35 architecture
script: .ci/general-jobs

before_cache:
- rm -rf $TRAVIS_BUILD_DIR/target/tmp

before_deploy:
- if [[ "$TEST_SUITE" == "release" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
sed -i.bak 's/cuckoo_miner =/#cuckoo_miner =/g; s/##cuckoo_miner/cuckoo_miner/g' Cargo.toml;
cargo clean; cargo build --release --features opencl && ./.auto-release.sh;
fi
- if [[ "$TEST_SUITE" == "release" ]] && [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update;
cargo clean; cargo build --release; ./.auto-release.sh;
fi
- bash .ci/release-jobs

deploy:
provider: releases
Expand Down
9 changes: 0 additions & 9 deletions .travis/install.sh

This file was deleted.