From 1c90502a3c4f735a7546a1147b100946f1a5af01 Mon Sep 17 00:00:00 2001 From: Sam Tay Date: Thu, 25 Jun 2020 02:10:48 -0700 Subject: Add CI courtesy of trust & cross --- .travis.yml | 65 +++++++++++++++++++++++++++++++++++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- appveyor.yml | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ci/before_deploy.ps1 | 22 ++++++++++++++++ ci/before_deploy.sh | 31 +++++++++++++++++++++++ ci/install.sh | 47 ++++++++++++++++++++++++++++++++++ ci/script.sh | 24 ++++++++++++++++++ 8 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 .travis.yml create mode 100644 appveyor.yml 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 new file mode 100644 index 0000000..3f8dbbd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,65 @@ +# Based on the "trust" template v0.1.2 +# https://github.com/japaric/trust/tree/v0.1.2 + +dist: trusty +language: rust +services: docker + +env: + global: + - CRATE_NAME=so + +jobs: + include: + # Linux + - env: TARGET=x86_64-unknown-linux-musl + - env: TARGET=x86_64-unknown-linux-gnu + + # OSX + - env: TARGET=x86_64-apple-darwin + os: osx + + # TODO figure out how to get tls libraries working on *bsd targets + # BSD + # - env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1 PKG_CONFIG_ALLOW_CROSS=1 + +before_install: + - set -e + - rustup self update + +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: + token: + secure: 1wWcYP/bJ3Poba8Y4D1BFV//8JFSJOL74ah9JP+QbOH7HmXtIX2xjaVUhzhZNU0rQHzibPzlbbe1lyr/SKqbCwzupowxxFlx6MOovQd8su8BWKsONpIaFtIMRDvkRVTIKo1/9Wp7tdjoFBVohY0ERnMuj2oV51tavYyl+hdEViZb6qQyGGuzotK1LzOaQslAqtCIjbs2mVXGkSURDuikYVJld8wyaO02zIeALDEs+czbQI0AUQ1l+dsy2vk+/pds2w5cgLGe7jtbFWLTgZU5eChV/3ArWSgeDxlZiNCDdUXfJ35TSLtrLzEexqVZNz3njlSfdOc5kueYGG1PhetNUJ+8WWDtoes3GnSYyh/lNv4UOjH34OZBrfazWllGHdDEE9yl/0Hu/QJ8uDUtDyImtfRCmJNRNZO7VkBturl/D8z6/Mq3mMF/fWkWfHlA4bDRtIA20ZYCzilmAT4DuMl8QQ89M6B65uJkBHN1EbnXMQTB/tzuvDRFbaRzCZ1WMudGoT9PyhgRcTzJEhGzfoEMRlUIbAffihnkiPyT7VRYcL2zSefnw2pvrnuZmykrkHF8/oyUPHvgYp1s/GMhBZexfrJ2moOWoxObYscoeI0gphLdycwHv5tJXR4U7eIoTD4SUYjNfwJf84G7rFbM62WfXUxO+gvJzQsHr3XxSZVoZ1c= + file_glob: true + file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.* + on: + condition: $TRAVIS_RUST_VERSION = stable + tags: true + provider: releases + +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 + - /^v\d+\.\d+\.\d+.*$/ + - master + +notifications: + email: + on_success: never diff --git a/Cargo.lock b/Cargo.lock index c447442..c364202 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1805,7 +1805,7 @@ checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" [[package]] name = "so" -version = "0.3.1" +version = "0.3.2" dependencies = [ "clap", "crossterm", diff --git a/Cargo.toml b/Cargo.toml index 6755923..63bd90f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "so" -version = "0.3.1" +version = "0.3.2" license = "MIT" description = "A terminal interface for StackOverflow" readme = "README.md" diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..74c62fc --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,71 @@ +# Based on the "trust" template v0.1.2 +# https://github.com/japaric/trust/tree/v0.1.2 + +environment: + global: + RUST_VERSION: stable + + CRATE_NAME: so + + matrix: + # MinGW + - TARGET: i686-pc-windows-gnu + - TARGET: x86_64-pc-windows-gnu + + # MSVC + - TARGET: i686-pc-windows-msvc + - TARGET: x86_64-pc-windows-msvc + +install: + - ps: >- + If ($env:TARGET -eq 'x86_64-pc-windows-gnu') { + $env:PATH += ';C:\msys64\mingw64\bin' + } ElseIf ($env:TARGET -eq 'i686-pc-windows-gnu') { + $env:PATH += ';C:\msys64\mingw32\bin' + } + - curl -sSf -o rustup-init.exe https://win.rustup.rs/ + - rustup-init.exe -y --default-host %TARGET% --default-toolchain %RUST_VERSION% + - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin + - rustc -Vv + - cargo -V + +test_script: + # we don't run the "test phase" when doing deploys + - if [%APPVEYOR_REPO_TAG%]==[false] ( + cargo build --no-default-features --features windows --features reqwest/native-tls-vendored --target %TARGET% && + cargo build --no-default-features --features windows --features reqwest/native-tls-vendored --target %TARGET% --release && + cargo test --no-default-features --features windows --features reqwest/native-tls-vendored --target %TARGET% + ) + +before_deploy: + - cargo rustc --no-default-features --features windows reqwest/native-tls-vendored --target %TARGET% --release --bin %CRATE_NAME% -- -C lto + - ps: ci\before_deploy.ps1 + +deploy: + artifact: /.*\.zip/ + auth_token: + secure: UTTZXiJCZo8UF4H4xvBe7SyC40UKviK1Z7qzR3mThCIg7WuIKuLLjbxM0NEomrZE + description: '' + on: + RUST_VERSION: stable + appveyor_repo_tag: true + provider: GitHub + +cache: + - C:\Users\appveyor\.cargo\registry + - target + +branches: + only: + # Release tags + - /^v\d+\.\d+\.\d+.*$/ + - master + +notifications: + - provider: Email + to: + - sam.chong.tay@gmail.com + on_build_success: false + +# Building is done in the test phase, so we disable Appveyor's build phase. +build: false diff --git a/ci/before_deploy.ps1 b/ci/before_deploy.ps1 new file mode 100644 index 0000000..5bc9388 --- /dev/null +++ b/ci/before_deploy.ps1 @@ -0,0 +1,22 @@ +# 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" + +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..7525d8c --- /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 so --target $TARGET --release -- -C lto + + cp target/$TARGET/release/so $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..3e96e97 --- /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/rust-embedded/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 rust-embedded/cross \ + --tag $tag \ + --target $target +} + +main diff --git a/ci/script.sh b/ci/script.sh new file mode 100644 index 0000000..6c3703f --- /dev/null +++ b/ci/script.sh @@ -0,0 +1,24 @@ +# This script takes care of testing your crate + +set -ex + +main() { + local features="--features reqwest/native-tls-vendored" + if [[ $TARGET =~ .*-freebsd ]]; then + features="--features reqwest/rustls-tls" + fi + + cross build $features --target $TARGET + cross build $features --target $TARGET --release + + if [ ! -z $DISABLE_TESTS ]; then + return + fi + + cross test $features --target $TARGET +} + +# we don't run the "test phase" when doing deploys +if [ -z $TRAVIS_TAG ]; then + main +fi -- cgit v1.2.3