From 5fec6455dbe5c2923a108ecba1b1f79d32fec434 Mon Sep 17 00:00:00 2001 From: Ximo Guanter Date: Sat, 30 Nov 2019 22:06:09 +0100 Subject: [PATCH] add trust ci --- .travis.yml | 70 +++++++++++++++++++++++++++++++++++++------- ci/before_deploy.ps1 | 23 +++++++++++++++ ci/before_deploy.sh | 31 ++++++++++++++++++++ ci/install.sh | 47 +++++++++++++++++++++++++++++ ci/script.sh | 24 +++++++++++++++ 5 files changed, 184 insertions(+), 11 deletions(-) create mode 100644 ci/before_deploy.ps1 create mode 100644 ci/before_deploy.sh create mode 100644 ci/install.sh create mode 100644 ci/script.sh diff --git a/.travis.yml b/.travis.yml index 9ec22aa..d1d63bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,67 @@ +# Based on the "trust" template v0.1.2 +# https://github.com/japaric/trust/tree/v0.1.2 + +dist: trusty language: rust -os: - - linux - - osx -rust: - - stable +services: docker +sudo: required + +env: + global: + - CRATE_NAME=suspicious-pods + +matrix: + include: + # Linux + - env: TARGET=i686-unknown-linux-gnu + - env: TARGET=i686-unknown-linux-musl + - env: TARGET=x86_64-unknown-linux-gnu + - env: TARGET=x86_64-unknown-linux-musl + + # OSX + - env: TARGET=i686-apple-darwin + os: osx + - env: TARGET=x86_64-apple-darwin + os: osx + +before_install: + - set -e + - rustup self update + +install: + - sh ci/install.sh + - source ~/.cargo/env || true + script: - - cargo build --release --all + - bash ci/script.sh + +after_script: set +e + +before_deploy: + - sh ci/before_deploy.sh + deploy: api_key: secure: "ds+KXq+nhiRx8OgbYZOezbiM8TuzuG6Ib059TQcrbcHlI+x4rWdaYtdQQujqddwyvtEmD2kfMm0Aw9fDHQB1L8s2Unu04xqxddQ7H4nsixNFse5CgJlaBBXHWylZb46JSwsFpTbOZti/I3o4BxUcn5VaaWu/UMS/j874/pQQWlw+LYZmdd+SyOb3dIlpgp2Ecd1xX9kpqUFV0a3a7bh3uPwnl9EyukZ4Sa8+xqARQengfHvnQpQTFv0TsrdylRg+MpfcFiLxNNyyPky6kiGzMlT1QuUx5s/s8eLszecOalmNRoYi43qf6q22PHHLyTNt98D0Ikk+CvuFcuiygpdI7aynJEpRDRdxoVcHXo/ZHHCm1x5Ckr7vWaCwKaetUmF0rUHf29uv3McEDFEiK1QzcOefNQPDN2mZml/GBULK8Q6+aukX0VR6SLHZ2KHatjL7tErwTnqIzYlZiQgcpOlA78QOyvJqjcNQa2l9j61PFIpPx1sSpVsYoltnSi5lKCkHAYnW9MgaOnePzd+Nyfpwh1YYHvZs8M4P2FH3MG6SVTwKm7Aqnh4C/RN4mD4EVjKEyANqpsy+/WXSOpn4VXoymIVwivIjt055t2hj6bqsXRsKgv0I2bPlrTO2aKTQNuKIw2x1TAf3ZXxqs5yLU8pnvpBvX1ac70IpxyIpWhsb8bQ=" - provider: releases - file: "target/release/suspicious-pods" - skip_cleanup: true - draft: true - name: "Draft $$TRAVIS_OS_NAME" + file_glob: true + file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.* on: + condition: $TRAVIS_RUST_VERSION = stable tags: true + provider: releases + skip_cleanup: true + cache: cargo +before_cache: + # Travis can't cache files that are not readable by "others" + - chmod -R a+r $HOME/.cargo + +branches: + only: + # release tags + - /^\d+\.\d+\.\d+.*$/ + - master + +notifications: + email: + on_success: never diff --git a/ci/before_deploy.ps1 b/ci/before_deploy.ps1 new file mode 100644 index 0000000..0788b1f --- /dev/null +++ b/ci/before_deploy.ps1 @@ -0,0 +1,23 @@ +# 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\$(env:CRATE_NAME).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 new file mode 100644 index 0000000..392fe2c --- /dev/null +++ b/ci/before_deploy.sh @@ -0,0 +1,31 @@ +# 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 + + cross rustc --bin suspicious-pods --target $TARGET --release -- -C lto + + cp target/$TARGET/release/suspicious-pods $stage/ + + cd $stage + tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz * + cd $src + + rm -rf $stage +} + +main diff --git a/ci/install.sh b/ci/install.sh new file mode 100644 index 0000000..80e18e4 --- /dev/null +++ b/ci/install.sh @@ -0,0 +1,47 @@ +set -ex + +main() { + local target= + if [ $TRAVIS_OS_NAME = linux ]; then + target=x86_64-unknown-linux-musl + sort=sort + else + target=x86_64-apple-darwin + sort=gsort # for `sort --sort-version`, from brew's coreutils. + fi + + # Builds for iOS are done on OSX, but require the specific target to be + # installed. + case $TARGET in + aarch64-apple-ios) + rustup target install aarch64-apple-ios + ;; + armv7-apple-ios) + rustup target install armv7-apple-ios + ;; + armv7s-apple-ios) + rustup target install armv7s-apple-ios + ;; + i386-apple-ios) + rustup target install i386-apple-ios + ;; + x86_64-apple-ios) + rustup target install x86_64-apple-ios + ;; + esac + + # 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.1.0-9.]+$' \ + | $sort --version-sort \ + | tail -n1) + 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 new file mode 100644 index 0000000..ddd7f93 --- /dev/null +++ b/ci/script.sh @@ -0,0 +1,24 @@ +# This script takes care of testing your crate + +set -ex + +# TODO This is the "test phase", tweak it as you see fit +main() { + cross build --target $TARGET + cross build --target $TARGET --release + + if [ ! -z $DISABLE_TESTS ]; then + return + fi + + cross test --target $TARGET + cross test --target $TARGET --release + + cross run --target $TARGET + cross run --target $TARGET --release +} + +# we don't run the "test phase" when doing deploys +if [ -z $TRAVIS_TAG ]; then + main +fi