From a485ab1a2f4e7dcacfa96146c29709dd8d873762 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 30 Jul 2019 10:29:00 -0700 Subject: [PATCH] Set up CI with Azure Pipelines (#275) --- .travis.yml | 91 -------------------------------------- Cargo.toml | 7 --- README.md | 9 +++- azure-pipelines.yml | 63 ++++++++++++++++++++++++++ ci/azure-cross-compile.yml | 55 +++++++++++++++++++++++ ci/azure-deploy-docs.yml | 39 ++++++++++++++++ ci/azure-install-rust.yml | 33 ++++++++++++++ ci/azure-test-stable.yml | 42 ++++++++++++++++++ ci/azure-tsan.yml | 26 +++++++++++ ci/before_deploy.ps1 | 23 ---------- ci/before_deploy.sh | 33 -------------- ci/cross-patch | 22 +++++++++ ci/install.sh | 31 ------------- ci/script.sh | 18 -------- 14 files changed, 287 insertions(+), 205 deletions(-) delete mode 100644 .travis.yml create mode 100644 azure-pipelines.yml create mode 100644 ci/azure-cross-compile.yml create mode 100644 ci/azure-deploy-docs.yml create mode 100644 ci/azure-install-rust.yml create mode 100644 ci/azure-test-stable.yml create mode 100644 ci/azure-tsan.yml delete mode 100644 ci/before_deploy.ps1 delete mode 100644 ci/before_deploy.sh create mode 100644 ci/cross-patch delete mode 100644 ci/install.sh delete mode 100644 ci/script.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 38f74f1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,91 +0,0 @@ ---- -dist: trusty -language: rust -services: docker -sudo: required -rust: stable - -env: - global: - - CRATE_NAME=bytes - # Default job - - TARGET=x86_64-unknown-linux-gnu - - secure: "f17G5kb6uAQlAG9+GknFFYAmngGBqy9h+3FtNbp3mXTI0FOLltz00Ul5kGPysE4eagypm/dWOuvBkNjN01jhE6fCbekmInEsobIuanatrk6TvXT6caJqykxhPJC2cUoq8pKnMqEOuucEqPPUH6Qy6Hz4/2cRu5JV22Uv9dtS29Q=" - -matrix: - include: - # Run build on oldest supported rust version. Do not change the rust - # version without a Github issue first. - # - # This job will also build and deploy the docs to gh-pages. - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.36.0 - after_success: - - | - pip install 'travis-cargo<0.2' --user && - export PATH=$HOME/.local/bin:$PATH - - travis-cargo doc - - travis-cargo doc-upload - - # Run tests on some extra platforms - - env: TARGET=i686-unknown-linux-gnu - - env: TARGET=armv7-unknown-linux-gnueabihf - - env: RUST_TEST_THREADS=1 TARGET=powerpc-unknown-linux-gnu - - env: RUST_TEST_THREADS=1 TARGET=powerpc64-unknown-linux-gnu - - # Serde implementation - - env: EXTRA_ARGS="--features serde" - - # 128 bit numbers - - env: EXTRA_ARGS="--features i128" - - # `Either` impls - - env: EXTRA_ARGS="--features either" - - # WASM support - - rust: stable - script: - - rustup target add wasm32-unknown-unknown - - cargo build --target=wasm32-unknown-unknown - - # Sanitizers - - rust: nightly - os: linux - script: - - | - set -e - - export RUST_TEST_THREADS=1 - export ASAN_OPTIONS="detect_odr_violation=0 detect_leaks=0" - export TSAN_OPTIONS="suppressions=`pwd`/ci/tsan" - - # Run address sanitizer - RUSTFLAGS="-Z sanitizer=address" \ - cargo test --tests --target x86_64-unknown-linux-gnu - - # Run thread sanitizer - RUSTFLAGS="-Z sanitizer=thread" \ - cargo test --tests --target x86_64-unknown-linux-gnu - -before_install: set -e - -install: - - sh ci/install.sh - - source ~/.cargo/env || true - -script: - - bash ci/script.sh - -after_script: set +e - -before_deploy: - - sh ci/before_deploy.sh - -cache: cargo -before_cache: - # Travis can't cache files that are not readable by "others" - - chmod -R a+r $HOME/.cargo - -notifications: - email: - on_success: never diff --git a/Cargo.toml b/Cargo.toml index e375eb0..f922462 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,13 +14,6 @@ documentation = "https://docs.rs/bytes" repository = "https://github.com/tokio-rs/bytes" readme = "README.md" keywords = ["buffers", "zero-copy", "io"] -exclude = [ - ".gitignore", - ".travis.yml", - "deploy.sh", - "bench/**/*", - "test/**/*" -] categories = ["network-programming", "data-structures"] edition = "2018" diff --git a/README.md b/README.md index 1dd8d5d..6931eb9 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,13 @@ A utility library for working with bytes. -[![Crates.io](https://img.shields.io/crates/v/bytes.svg?maxAge=2592000)](https://crates.io/crates/bytes) -[![Build Status](https://travis-ci.org/tokio-rs/bytes.svg?branch=master)](https://travis-ci.org/tokio-rs/bytes) +[![Crates.io][crates-badge]][crates-url] +[![Build Status][azure-badge]][azure-url] + +[crates-badge]: https://img.shields.io/crates/v/bytes.svg +[crates-url]: https://crates.io/crates/bytes +[azure-badge]: https://dev.azure.com/tokio-rs/bytes/_apis/build/status/tokio-rs.bytes?branchName=master +[azure-url]: https://dev.azure.com/tokio-rs/bytes/_build/latest?definitionId=3&branchName=master [Documentation](https://docs.rs/bytes) diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..2f2b61f --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,63 @@ +trigger: ["master"] +pr: ["master"] + +jobs: +# Check formatting +# - template: ci/azure-rustfmt.yml +# parameters: +# name: rustfmt + +# Apply clippy lints +# - template: ci/azure-clippy.yml +# parameters: +# name: clippy + +# This represents the minimum Rust version supported by +# Bytes. Updating this should be done in a dedicated PR. +# +# Tests are not run as tests may require newer versions of +# rust. +- template: ci/azure-test-stable.yml + parameters: + name: minrust + rust_version: 1.36.0 + cmd: check + +# Stable +- template: ci/azure-test-stable.yml + parameters: + name: stable + cross: true + features: + - serde + - i128 + - either + +# Nightly +- template: ci/azure-test-stable.yml + parameters: + name: nightly + # Pin nightly to avoid being impacted by breakage + rust_version: nightly-2019-07-17 + benches: true + +# Run tests on some extra platforms +- template: ci/azure-cross-compile.yml + parameters: + name: cross + +# Sanitizers +- template: ci/azure-tsan.yml + parameters: + name: tsan + rust_version: nightly + +- template: ci/azure-deploy-docs.yml + parameters: + dependsOn: + # - rustfmt + # - clippy + - stable + - nightly + - minrust + - cross diff --git a/ci/azure-cross-compile.yml b/ci/azure-cross-compile.yml new file mode 100644 index 0000000..cdcc197 --- /dev/null +++ b/ci/azure-cross-compile.yml @@ -0,0 +1,55 @@ +parameters: + cmd: test + rust_version: stable + +jobs: +- job: ${{ parameters.name }} + displayName: Cross + strategy: + matrix: + i686: + vmImage: ubuntu-16.04 + target: i686-unknown-linux-gnu + armv7: + vmImage: ubuntu-16.04 + target: armv7-unknown-linux-gnueabihf + powerpc: + vmImage: ubuntu-16.04 + target: powerpc-unknown-linux-gnu + powerpc64: + vmImage: ubuntu-16.04 + target: powerpc64-unknown-linux-gnu + wasm: + vmImage: ubuntu-16.04 + target: wasm32-unknown-unknown + pool: + vmImage: $(vmImage) + + steps: + - template: azure-install-rust.yml + parameters: + rust_version: ${{parameters.rust_version}} + + # FIXME(taiki-e): When https://github.com/rust-embedded/cross/pull/169 is + # merged, switch to the installation from crates.io. + # See https://nbsoftsolutions.com/blog/azure-pipelines-for-rust-projects#workaround-cross-compilation + # for the current script. + - script: | + git clone https://github.com/rust-embedded/cross.git + cd cross + git apply ../ci/cross-patch + cargo install --path . + rm -rf cross + displayName: Install cross + condition: not(eq(variables['target'], 'wasm32-unknown-unknown')) + + - script: cross ${{ parameters.cmd }} --target $(target) + displayName: cross ${{ parameters.cmd }} --target $(target) + condition: not(eq(variables['target'], 'wasm32-unknown-unknown')) + + # WASM support + - script: | + rustup target add $(target) + cargo build --target $(target) + displayName: cargo build --target $(target) + condition: eq(variables['target'], 'wasm32-unknown-unknown') diff --git a/ci/azure-deploy-docs.yml b/ci/azure-deploy-docs.yml new file mode 100644 index 0000000..52ac48f --- /dev/null +++ b/ci/azure-deploy-docs.yml @@ -0,0 +1,39 @@ +parameters: + dependsOn: [] + +jobs: +- job: documentation + displayName: 'Deploy API Documentation' + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + pool: + vmImage: 'Ubuntu 16.04' + dependsOn: + - ${{ parameters.dependsOn }} + steps: + - template: azure-install-rust.yml + parameters: + rust_version: stable + - script: | + cargo doc --no-deps + cp -R target/doc '$(Build.BinariesDirectory)' + displayName: 'Generate Documentation' + - script: | + set -e + + git --version + ls -la + git init + git config user.name 'Deployment Bot (from Azure Pipelines)' + git config user.email 'deploy@tokio-rs.com' + git config --global credential.helper 'store --file ~/.my-credentials' + printf "protocol=https\nhost=github.com\nusername=carllerche\npassword=%s\n\n" "$GITHUB_TOKEN" | git credential-store --file ~/.my-credentials store + git remote add origin https://github.com/tokio-rs/bytes + git checkout -b gh-pages + git add . + git commit -m 'Deploy Bytes API documentation' + git push -f origin gh-pages + env: + GITHUB_TOKEN: $(githubPersonalToken) + workingDirectory: '$(Build.BinariesDirectory)' + displayName: 'Deploy Documentation' + diff --git a/ci/azure-install-rust.yml b/ci/azure-install-rust.yml new file mode 100644 index 0000000..0217659 --- /dev/null +++ b/ci/azure-install-rust.yml @@ -0,0 +1,33 @@ +steps: + # Linux and macOS. + - script: | + set -e + curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain none + export PATH=$PATH:$HOME/.cargo/bin + rustup toolchain install $RUSTUP_TOOLCHAIN + rustup default $RUSTUP_TOOLCHAIN + echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin" + env: + RUSTUP_TOOLCHAIN: ${{parameters.rust_version}} + displayName: "Install rust (*nix)" + condition: not(eq(variables['Agent.OS'], 'Windows_NT')) + + # Windows. + - script: | + curl -sSf -o rustup-init.exe https://win.rustup.rs + rustup-init.exe -y --default-toolchain none + set PATH=%PATH%;%USERPROFILE%\.cargo\bin + rustup toolchain install %RUSTUP_TOOLCHAIN% + rustup default %RUSTUP_TOOLCHAIN% + echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin" + env: + RUSTUP_TOOLCHAIN: ${{parameters.rust_version}} + displayName: "Install rust (windows)" + condition: eq(variables['Agent.OS'], 'Windows_NT') + + # All platforms. + - script: | + rustup toolchain list + rustc -Vv + cargo -V + displayName: Query rust and cargo versions diff --git a/ci/azure-test-stable.yml b/ci/azure-test-stable.yml new file mode 100644 index 0000000..dd15616 --- /dev/null +++ b/ci/azure-test-stable.yml @@ -0,0 +1,42 @@ +parameters: + cmd: test + rust_version: stable + features: [] + +jobs: +- job: ${{ parameters.name }} + displayName: ${{ parameters.displayName }} + strategy: + matrix: + Linux: + vmImage: ubuntu-16.04 + + ${{ if parameters.cross }}: + MacOS: + vmImage: macOS-10.13 + Windows: + vmImage: vs2017-win2016 + pool: + vmImage: $(vmImage) + + steps: + - template: azure-install-rust.yml + parameters: + rust_version: ${{parameters.rust_version}} + + # Run with default crate features + - script: cargo ${{ parameters.cmd }} + displayName: cargo ${{ parameters.cmd }} + + # Run with each specified feature + - ${{ each feature in parameters.features.value }}: + - script: cargo ${{ parameters.cmd }} --features ${{ feature }} + displayName: cargo ${{ parameters.cmd }} --tests --features ${{ feature }} + + - ${{ if eq(parameters.cmd, 'test') }}: + - script: cargo doc --no-deps + displayName: cargo doc --no-deps + + - ${{ if parameters.benches }}: + - script: cargo check --benches + displayName: Check benchmarks diff --git a/ci/azure-tsan.yml b/ci/azure-tsan.yml new file mode 100644 index 0000000..44cd5f7 --- /dev/null +++ b/ci/azure-tsan.yml @@ -0,0 +1,26 @@ +jobs: +- job: ${{ parameters.name }} + displayName: TSAN + pool: + vmImage: ubuntu-16.04 + + steps: + - template: azure-install-rust.yml + parameters: + rust_version: ${{ parameters.rust_version }} + + - script: | + set -e + + export RUST_TEST_THREADS=1 + export ASAN_OPTIONS="detect_odr_violation=0 detect_leaks=0" + export TSAN_OPTIONS="suppressions=`pwd`/ci/tsan" + + # Run address sanitizer + RUSTFLAGS="-Z sanitizer=address" \ + cargo test --tests --target x86_64-unknown-linux-gnu + + # Run thread sanitizer + RUSTFLAGS="-Z sanitizer=thread" \ + cargo test --tests --target x86_64-unknown-linux-gnu + displayName: TSAN / MSAN diff --git a/ci/before_deploy.ps1 b/ci/before_deploy.ps1 deleted file mode 100644 index 191a30b..0000000 --- a/ci/before_deploy.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -# This script takes care of packaging the build artifacts that will go in the -# release zipfile - -$SRC_DIR = $PWD.Path -$STAGE = [System.Guid]::NewGuid().ToString() - -Set-Location $ENV:Temp -New-Item -Type Directory -Name $STAGE -Set-Location $STAGE - -$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip" - -# TODO Update this to package the right artifacts -Copy-Item "$SRC_DIR\target\$($Env:TARGET)\release\hello.exe" '.\' - -7z a "$ZIP" * - -Push-AppveyorArtifact "$ZIP" - -Remove-Item *.* -Force -Set-Location .. -Remove-Item $STAGE -Set-Location $SRC_DIR diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh deleted file mode 100644 index 026dc28..0000000 --- a/ci/before_deploy.sh +++ /dev/null @@ -1,33 +0,0 @@ -# This script takes care of building your crate and packaging it for release - -set -ex - -main() { - local src=$(pwd) \ - stage= - - case $TRAVIS_OS_NAME in - linux) - stage=$(mktemp -d) - ;; - osx) - stage=$(mktemp -d -t tmp) - ;; - esac - - test -f Cargo.lock || cargo generate-lockfile - - # TODO Update this to build the artifacts that matter to you - cross rustc --bin hello --target $TARGET --release -- -C lto - - # TODO Update this to package the right artifacts - cp target/$TARGET/release/hello $stage/ - - cd $stage - tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz * - cd $src - - rm -rf $stage -} - -main diff --git a/ci/cross-patch b/ci/cross-patch new file mode 100644 index 0000000..f59b551 --- /dev/null +++ b/ci/cross-patch @@ -0,0 +1,22 @@ +diff --git a/src/docker.rs b/src/docker.rs +index 1525b87..5c9cd54 100644 +--- a/src/docker.rs ++++ b/src/docker.rs +@@ -62,7 +62,7 @@ pub fn register(target: &Target, verbose: bool) -> Result<()> { + docker_command("run") + .arg("--privileged") + .arg("--rm") +- .arg("-it") ++ .arg("-i") + .arg("ubuntu:16.04") + .args(&["sh", "-c", cmd]) + .run(verbose) +@@ -160,7 +160,7 @@ pub fn run(target: &Target, + .args(&["-v", &format!("{}:/rust:ro", sysroot.display())]) + .args(&["-v", &format!("{}:/target", target_dir.display())]) + .args(&["-w", "/project"]) +- .args(&["-it", &image(toml, target)?]) ++ .args(&["-i", &image(toml, target)?]) + .args(&["sh", "-c", &format!("PATH=$PATH:/rust/bin {:?}", cmd)]) + .run_and_get_status(verbose) + } diff --git a/ci/install.sh b/ci/install.sh deleted file mode 100644 index 76bb734..0000000 --- a/ci/install.sh +++ /dev/null @@ -1,31 +0,0 @@ -set -ex - -main() { - curl https://sh.rustup.rs -sSf | \ - sh -s -- -y --default-toolchain $TRAVIS_RUST_VERSION - - local target= - if [ $TRAVIS_OS_NAME = linux ]; then - target=x86_64-unknown-linux-gnu - sort=sort - else - target=x86_64-apple-darwin - sort=gsort # for `sort --sort-version`, from brew's coreutils. - fi - - # This fetches latest stable release - local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \ - | cut -d/ -f3 \ - | grep -E '^v[0-9.]+$' \ - | $sort --version-sort \ - | tail -n1) - echo cross version: $tag - curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- \ - --force \ - --git japaric/cross \ - --tag $tag \ - --target $target -} - -main diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100644 index d1ed7f9..0000000 --- a/ci/script.sh +++ /dev/null @@ -1,18 +0,0 @@ -# This script takes care of testing your crate - -set -ex - -main() { - cross build --target $TARGET $EXTRA_ARGS - - if [ ! -z $DISABLE_TESTS ]; then - return - fi - - cross test --target $TARGET $EXTRA_ARGS -} - -# we don't run the "test phase" when doing deploys -if [ -z $TRAVIS_TAG ]; then - main -fi