From 004b8822f12e92a881d6cf2e94e3fa1888654660 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Thu, 23 Mar 2017 19:53:26 +0900 Subject: [PATCH] Try trust for creating binaries on travis --- .travis.yml | 74 +++++++++++++++++++++++++++++++++++++++----- ci/before_deploy.ps1 | 23 ++++++++++++++ ci/before_deploy.sh | 33 ++++++++++++++++++++ ci/install.sh | 31 +++++++++++++++++++ ci/script.sh | 24 ++++++++++++++ 5 files changed, 178 insertions(+), 7 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 79ef3140..67ec1045 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,70 @@ +dist: trusty language: rust +services: docker +sudo: required + + +env: + global: + - CRATE_NAME=gutenberg + +matrix: + # TODO These are all the build jobs. Adjust as necessary. Comment out what you + # don't need + include: + # Linux + - env: TARGET=x86_64-unknown-linux-gnu + - env: TARGET=x86_64-unknown-linux-musl + # OSX + - env: TARGET=x86_64-apple-darwin + os: osx + + # Testing other channels + - env: TARGET=x86_64-unknown-linux-gnu + rust: beta + - env: TARGET=x86_64-unknown-linux-gnu + rust: nightly + + +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 + +deploy: + # TODO update `api_key.secure` + # - Create a `public_repo` GitHub token. Go to: https://github.com/settings/tokens/new + # - Encrypt it: `travis encrypt YOUR_TOKEN` + # - Paste the output down here + api_key: + secure: X0M1TT06/MHfwaENl+u/K3twBU0BVTQimXfBkHzODWsWC84SGeJPMiovIkuBxq4P7Wk7sIr1d/IINlq0sK40IvI3Xwy95YtpTKcK52ffZjTmHSNExCy+OhW2JefNPOwPI89JWKsmHM1I8FuDRiENTyawVS8akcl1XnQhS3V3a1zEuwpULO+6UwDTauJDRdVenDY7tHxbwYH644djZpKcL3LsPLkv0r0XlWnyH+Lw65/ggUmw63KaZTN+hOYfznXGNjlsv2YSD8lCo7eGGg+WA1rsr1SDOxzMM60OOE2Y4lDo0lX9tPWAxMfltvuouxfZ8Y2II4oNEYQui+AqaZ6CfhjFrfZG5P6QdFcGcjiYhDC+s+R9m+tCtzCcKh+lahxcfwOEo1O9pAsg77XVy5gf9guM++9uhYc54Z7tUeyNyJQVaQHt0drmqqeQWfk8w2YBmTPiJ7mwAbhEU5gISWQBpc9eRM1PiOaWDOJHgyV1rZfOT6RxgKBu5DW4pSZ6Iar7Qc+u4ei80QRI2jVsnlPY8/5rl/z0fqSnOen/wyGQHNI18SwXiy0TbN8aMpwr9tllOBYtjrWoX4xCj8NJksl1EAYaE2Cwy768mSfO9FTMqGQpuG5S6M9BRsG5pOtZdKpxjyP8vJ1ahp8KDI9Mz8QJSfG6kOHXqCaed+MmJNxJYI0= file_glob: true + file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.* + on: + # TODO Here you can pick which targets will generate binary releases + # In this example, there are some targets that are tested using the stable + # and nightly channels. This condition makes sure there is only one release + # for such targets and that's generated using the stable channel + 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 -rust: - - nightly - - beta - - stable - -notifications: - email: false +branches: + only: + # release tags + - /^v\d+\.\d+\.\d+.*$/ + - master diff --git a/ci/before_deploy.ps1 b/ci/before_deploy.ps1 new file mode 100644 index 00000000..191a30b8 --- /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\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 new file mode 100644 index 00000000..026dc289 --- /dev/null +++ b/ci/before_deploy.sh @@ -0,0 +1,33 @@ +# 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/install.sh b/ci/install.sh new file mode 100644 index 00000000..76bb7340 --- /dev/null +++ b/ci/install.sh @@ -0,0 +1,31 @@ +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 new file mode 100644 index 00000000..ddd7f936 --- /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