diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b2e6728 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,93 @@ +language: rust +cache: cargo +matrix: + include: + # Stable channel. + - os: linux + rust: stable + env: TARGET=x86_64-unknown-linux-gnu + - os: linux + rust: stable + env: TARGET=x86_64-unknown-linux-musl + - os: linux + rust: stable + env: TARGET=i686-unknown-linux-gnu + - os: linux + rust: stable + env: TARGET=i686-unknown-linux-musl + - os: osx + rust: stable + env: TARGET=x86_64-apple-darwin + + # Minimum Rust supported channel. + - os: linux + rust: 1.20.0 + env: TARGET=x86_64-unknown-linux-gnu + - os: linux + rust: 1.20.0 + env: TARGET=x86_64-unknown-linux-musl + - os: linux + rust: 1.20.0 + env: TARGET=i686-unknown-linux-gnu + - os: linux + rust: 1.20.0 + env: TARGET=i686-unknown-linux-musl + - os: osx + rust: 1.20.0 + env: TARGET=x86_64-apple-darwin + +addons: + apt: + packages: + # needed for i686-unknown-linux-gnu target + - gcc-multilib + +env: + global: + # Default target on travis-ci. + # Used as conditional check in the install stage + - HOST=x86_64-unknown-linux-gnu + # Used on the deployment script + - PROJECT_NAME=hyperfine + +install: + # prevent target re-add error from rustup + - if [[ $TRAVIS_OS_NAME = linux && $HOST != $TARGET ]]; then rustup target add $TARGET; fi + +script: + # Incorporate TARGET env var to the build and test process + - cargo build --target $TARGET --verbose + - cargo test --target $TARGET --verbose + +before_deploy: + - bash ci/before_deploy.bash + +deploy: + provider: releases + # NOTE updating the `api_key.secure` + # - go to: https://github.com/settings/tokens/new + # - generate new token using `public_repo` scope + # - encrypt it using: `travis encrypt API_KEY_HERE` + # - paste the output below + api_key: + secure: "RyFdh2lpDmaNhPar7ezsb18Xz+6XFM40y7cZCDRML+Sk+eYK1xtDNfEhDRJU5Qo1ReVsByds/QJTSXr2KmZPk3lXwG3SiN7UtrLUxCxFr6qrcM/iujlKTf5UxeRklkzPXxnH95DEyEgxvgbVhWTGVDWoyMnrVQXZKDy6z1iAiYB5h2Zl1rs+MRb/Enlt5q6XIKAlG0ppGtl8CfYudq5ZiqfJaMWTt9SWm2YskC8FeMc0S3IM6/EhTvaNYLdaarFqVWQEVql+6oCuL3ayPzmGyxLdxM37tIMNQ0f97zxqWodacXTG5ULdRD8if1l/SmTujrtjbZ0KWRjsjOq4vBtxBJKGdprcSiB0xH/hToqqtTSO0z5FPXi5cB8UlK6YLDDHcP3kXNer8CYMLI1VPaUDLTF57/0/RPi2DZiiGfZsIAS6PsICbHdTQVzxQckM4lN1vnAGgkhXIMbztml21pv+QrGy98OZJ0ubf5ztgQhpT0WPH4JXT8M6htsoo8dZf8lQ5aLfmW9RKePJDqixQwPqmimPIkrlxRDTDGII0ZAZws7l779eOLmEcM2tH2HbsUKUCZIG/pRHLSlP45Jn2bULGzuXZ2daq70z6zvIbom0CUzSXIvdTXEZI2AM5RBvPYGGaKI8YlxgRdQvJp3h0BzPdFOXI3RAxscCY7PJpa/RdIg=" + # for uploading multiple files + file_glob: true + # NOTE explanation on each env variable + # - PROJECT_NAME: name of the project, set on the `env.global` above + # - TRAVIS_TAG: tag name that the build is being deployed for, usually the version number + # - TARGET: target triple of the build + file: + - $PROJECT_NAME-$TRAVIS_TAG-$TARGET.* + - $PROJECT_NAME*.deb + # don't delete artifacts from previous stage + skip_cleanup: true + on: + # deploy only if we push a tag + tags: true + # deploy only on stable channel that has TARGET env variable sets + condition: $TRAVIS_RUST_VERSION = stable && $TARGET != "" + +notifications: + email: + on_success: never diff --git a/ci/before_deploy.bash b/ci/before_deploy.bash new file mode 100755 index 0000000..c072ab0 --- /dev/null +++ b/ci/before_deploy.bash @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# Building and packaging for release + +set -ex + +build() { + cargo build --target "$TARGET" --release --verbose +} + +pack() { + local tempdir + local out_dir + local package_name + + tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp) + out_dir=$(pwd) + package_name="$PROJECT_NAME-$TRAVIS_TAG-$TARGET" + + # create a "staging" directory + mkdir "$tempdir/$package_name" + + # copying the main binary + cp "target/$TARGET/release/$PROJECT_NAME" "$tempdir/$package_name/" + strip "$tempdir/$package_name/$PROJECT_NAME" + + # readme and license + cp README.md "$tempdir/$package_name" + cp LICENSE-MIT "$tempdir/$package_name" + cp LICENSE-APACHE "$tempdir/$package_name" + + # archiving + pushd "$tempdir" + tar czf "$out_dir/$package_name.tar.gz" "$package_name"/* + popd + rm -r "$tempdir" +} + +make_deb() { + local tempdir + local architecture + local version + local dpkgname + local conflictname + + case $TARGET in + x86_64*) + architecture=amd64 + ;; + i686*) + architecture=i386 + ;; + *) + echo "ERROR: unknown target" >&2 + return 1 + ;; + esac + version=${TRAVIS_TAG#v} + if [[ $TARGET = *musl* ]]; then + dpkgname=$PROJECT_NAME-musl + conflictname=$PROJECT_NAME + else + dpkgname=$PROJECT_NAME + conflictname=$PROJECT_NAME-musl + fi + + tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp) + + # copy the main binary + install -Dm755 "target/$TARGET/release/$PROJECT_NAME" "$tempdir/usr/bin/$PROJECT_NAME" + strip "$tempdir/usr/bin/$PROJECT_NAME" + + # readme and license + install -Dm644 README.md "$tempdir/usr/share/doc/$PROJECT_NAME/README.md" + install -Dm644 LICENSE-MIT "$tempdir/usr/share/doc/$PROJECT_NAME/LICENSE-MIT" + install -Dm644 LICENSE-APACHE "$tempdir/usr/share/doc/$PROJECT_NAME/LICENSE-APACHE" + + # Control file + mkdir "$tempdir/DEBIAN" + cat > "$tempdir/DEBIAN/control" < +Architecture: $architecture +Provides: $PROJECT_NAME +Conflicts: $conflictname +Description: A command-line benchmarking tool. +EOF + + fakeroot dpkg-deb --build "$tempdir" "${dpkgname}_${version}_${architecture}.deb" +} + + +main() { + build + pack + if [[ $TARGET = *linux* ]]; then + make_deb + fi +} + +main