-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI release process based on rust-everywhere
See here for details: https://github.com/japaric/rust-everywhere
- Loading branch information
Showing
6 changed files
with
298 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,111 @@ | ||
language: rust | ||
|
||
# magic word to use faster/newer container-based architecture | ||
sudo: false | ||
|
||
# Cache built crates for much faster builds. | ||
cache: cargo | ||
|
||
rust: | ||
- stable | ||
- beta | ||
- nightly | ||
notifications: | ||
email: | ||
on_success: never | ||
|
||
env: | ||
global: | ||
- PROJECT_NAME=redis-throttle | ||
|
||
matrix: | ||
allow_failures: | ||
- rust: nightly | ||
|
||
before_script: (cargo install rustfmt || true) | ||
include: | ||
# Stable. | ||
- os: osx | ||
rust: stable | ||
env: TARGET=x86_64-apple-darwin | ||
- os: linux | ||
rust: stable | ||
env: TARGET=x86_64-unknown-linux-gnu | ||
- os: linux | ||
rust: stable | ||
env: TARGET=x86_64-unknown-linux-musl | ||
dist: trusty | ||
sudo: required | ||
addons: | ||
apt: | ||
packages: &musl_packages | ||
- musl | ||
- musl-dev | ||
- musl-tools | ||
|
||
# Beta. | ||
- os: osx | ||
rust: beta | ||
env: TARGET=x86_64-apple-darwin | ||
- os: linux | ||
rust: beta | ||
env: TARGET=x86_64-unknown-linux-gnu | ||
- os: linux | ||
rust: beta | ||
env: TARGET=x86_64-unknown-linux-musl | ||
dist: trusty | ||
sudo: required | ||
addons: | ||
apt: | ||
packages: *musl_packages | ||
|
||
# Nightly. | ||
- os: osx | ||
rust: nightly | ||
env: TARGET=x86_64-apple-darwin | ||
- os: linux | ||
rust: nightly | ||
env: TARGET=x86_64-unknown-linux-gnu | ||
- os: linux | ||
rust: nightly | ||
env: TARGET=x86_64-unknown-linux-musl | ||
dist: trusty | ||
sudo: required | ||
addons: | ||
apt: | ||
packages: *musl_packages | ||
|
||
before_install: | ||
- export PATH="$PATH:$HOME/.cargo/bin" | ||
|
||
install: | ||
- bash ci/install.sh | ||
|
||
before_script: | ||
# Don't fail on failure to install because it's probably because the target | ||
# already exists. | ||
- (cargo install rustfmt || true) | ||
|
||
script: | ||
- export PATH=$PATH:~/.cargo/bin && | ||
cargo fmt -- --write-mode=diff && | ||
cargo build --verbose && | ||
cargo test --verbose | ||
- bash ci/script.sh | ||
|
||
before_deploy: | ||
- bash ci/before_deploy.sh | ||
|
||
branches: | ||
only: | ||
# Pushes and pull requests to the master branch. | ||
- master | ||
|
||
# IMPORTANT Ruby regex to match tags. Required, or travis won't trigger | ||
# deploys when a new tag is pushed. This regex matches semantic versions | ||
# like v1.2.3-rc4+2016.02.22 | ||
- /^v\d+\.\d+\.\d+.*$/ | ||
|
||
deploy: | ||
provider: releases | ||
# Generated with `travis encrypt $token`. Token is scoped to `public_repo`. | ||
api_key: | ||
secure: "sK0Hy8dF1wmz+A505coJNeR8BYooD9AranRdvJagbvJcsijc1Bs7id8f0VruezSRvs2CZXt/iC9Btu/6/R+pvc7vskZyqsdXBpO1oFMUMwwzPuasz2w5DOFH8Ftg2fOl8Hjm3vzwp/itkjeUl/3beX/MTHt1emIusnFP6HcpSIx3XUvjU5c+VoAuGIj5qEu2eKGyRQf+pFiHqeR5H75cVJoFps0E8eaQbCV1XolX/sVHenaxYIaTb87xMUCV6k2VHWhAR5036+OJ02W1q9mAgChD83Ac/+j2Oq52hg2yyjYsLit0of7BJ1Rg0025yZd8dap4g9cW59/MO6jnUzOiX1uHvWXgOaAiktzrgHcw0zwZS6DyYzRkJ2AVAaYXrs/LdVQOECMAc1Flur0aS/OwaojMRK6MDLqLJ1nMjacSQl2loAu1XFhVum0RZQ37jXrdJxZK9+xj712WkbSmGoQvh1oJB631H4nPNOJxBOdvV3EL3sJ/XGVpXEWlQk28V6QPpxSCmNNDVNj3s1LuonkB+L6ZxreKixP2tWMO76a63k4zBBVaCDdkmIDCaXActDM/V3+nQbJgQBApu/v0+d0dd91P0uapWYkUOJMRVoGUVQ1xRPdCh/yaVRd6DPN4HW7TCaEUyamlcFo9mZsTiC6pTPNMv3IjpEgJfzf/3qkjryQ=" | ||
file_glob: true | ||
file: ${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.* | ||
# Don't delete the artifacts from previous phases. | ||
skip_cleanup: true | ||
# Deploy when a new tag is pushed. | ||
on: | ||
# Channel to use to produce the release artifacts. NOTE make sure you only | ||
# release *once* per target. | ||
condition: $TRAVIS_RUST_VERSION = stable | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# CI Scripts | ||
|
||
This directory contains CI scripts necessary to perform a binary release for | ||
the project. They're based on rust-everywhere: | ||
|
||
https://github.com/japaric/rust-everywhere |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# `before_deploy` phase: here we package the build artifacts | ||
|
||
set -ex | ||
|
||
. $(dirname $0)/utils.sh | ||
|
||
# Generate artifacts for release | ||
mk_artifacts() { | ||
cargo build --target $TARGET --release | ||
} | ||
|
||
mk_tarball() { | ||
# create a "staging" directory | ||
local td=$(mktempd) | ||
local out_dir=$(pwd) | ||
|
||
# Naming will be .dylib on OSX and .so elsewhere. | ||
cp target/$TARGET/release/libredis_throttle.* $td | ||
|
||
pushd $td | ||
|
||
# release tarball will look like 'rust-everywhere-v1.2.3-x86_64-unknown-linux-gnu.tar.gz' | ||
tar czf $out_dir/${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.tar.gz * | ||
|
||
popd | ||
rm -r $td | ||
} | ||
|
||
main() { | ||
mk_artifacts | ||
mk_tarball | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# `install` phase: install stuff needed for the `script` phase | ||
|
||
set -ex | ||
|
||
. $(dirname $0)/utils.sh | ||
|
||
install_c_toolchain() { | ||
case $TARGET in | ||
aarch64-unknown-linux-gnu) | ||
sudo apt-get install -y --no-install-recommends \ | ||
gcc-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross | ||
;; | ||
*) | ||
# For other targets, this is handled by addons.apt.packages in .travis.yml | ||
;; | ||
esac | ||
} | ||
|
||
install_rustup() { | ||
# uninstall the rust toolchain installed by travis, we are going to use rustup | ||
sh ~/rust/lib/rustlib/uninstall.sh | ||
|
||
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TRAVIS_RUST_VERSION | ||
|
||
rustc -V | ||
cargo -V | ||
} | ||
|
||
install_standard_crates() { | ||
if [ $(host) != "$TARGET" ]; then | ||
rustup target add $TARGET | ||
fi | ||
} | ||
|
||
configure_cargo() { | ||
local prefix=$(gcc_prefix) | ||
|
||
if [ ! -z $prefix ]; then | ||
# information about the cross compiler | ||
${prefix}gcc -v | ||
|
||
# tell cargo which linker to use for cross compilation | ||
mkdir -p .cargo | ||
cat >>.cargo/config <<EOF | ||
[target.$TARGET] | ||
linker = "${prefix}gcc" | ||
EOF | ||
fi | ||
} | ||
|
||
main() { | ||
install_c_toolchain | ||
install_rustup | ||
install_standard_crates | ||
configure_cargo | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# `script` phase: you usually build, test and generate docs in this phase | ||
|
||
set -ex | ||
|
||
. $(dirname $0)/utils.sh | ||
|
||
# PROTIP: Always pass `--target $TARGET` to cargo commands, this makes cargo | ||
# output build artifacts to target/$TARGET/{debug,release} which can reduce the | ||
# number of needed conditionals in the `before_deploy`/packaging phase. | ||
build_and_test() { | ||
case $TARGET in | ||
# configure emulation for transparent execution of foreign binaries | ||
aarch64-unknown-linux-gnu) | ||
export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu | ||
;; | ||
arm*-unknown-linux-gnueabihf) | ||
export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf | ||
;; | ||
*) | ||
;; | ||
esac | ||
|
||
if [ ! -z "$QEMU_LD_PREFIX" ]; then | ||
# Run tests on a single thread when using QEMU user emulation | ||
export RUST_TEST_THREADS=1 | ||
fi | ||
|
||
cargo fmt -- --write-mode=diff | ||
cargo build --target $TARGET --verbose | ||
cargo test --target $TARGET | ||
|
||
# Sanity check the file type. | ||
# | ||
# Naming will be .dylib on OSX and .so elsewhere. | ||
file target/$TARGET/debug/libredis_throttle.* | ||
} | ||
|
||
main() { | ||
build_and_test | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
mktempd() { | ||
echo $(mktemp -d 2>/dev/null || mktemp -d -t tmp) | ||
} | ||
|
||
host() { | ||
case "$TRAVIS_OS_NAME" in | ||
linux) | ||
echo x86_64-unknown-linux-gnu | ||
;; | ||
osx) | ||
echo x86_64-apple-darwin | ||
;; | ||
esac | ||
} | ||
|
||
gcc_prefix() { | ||
case "$TARGET" in | ||
aarch64-unknown-linux-gnu) | ||
echo aarch64-linux-gnu- | ||
;; | ||
arm*-gnueabihf) | ||
echo arm-linux-gnueabihf- | ||
;; | ||
*-musl) | ||
echo musl- | ||
;; | ||
*) | ||
return | ||
;; | ||
esac | ||
} | ||
|
||
dobin() { | ||
[ -z $MAKE_DEB ] && die 'dobin: $MAKE_DEB not set' | ||
[ $# -lt 1 ] && die "dobin: at least one argument needed" | ||
|
||
local f prefix=$(gcc_prefix) | ||
for f in "$@"; do | ||
install -m0755 $f $dtd/debian/usr/bin/ | ||
${prefix}strip -s $dtd/debian/usr/bin/$(basename $f) | ||
done | ||
} | ||
|
||
architecture() { | ||
case $1 in | ||
x86_64-unknown-linux-gnu|x86_64-unknown-linux-musl) | ||
echo amd64 | ||
;; | ||
i686-unknown-linux-gnu|i686-unknown-linux-musl) | ||
echo i386 | ||
;; | ||
arm*-unknown-linux-gnueabihf) | ||
echo armhf | ||
;; | ||
*) | ||
die "architecture: unexpected target $TARGET" | ||
;; | ||
esac | ||
} |