From 2607557578383c6daa2aff939ab2623f950bee0e Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Mon, 13 Jun 2016 14:48:01 +0100 Subject: [PATCH] use travis to make releases to github When a tag is pushed we will following this patch also do a release build if the debug build and tests passes. We will then being packaging for each target, along with an archive for the source code. The packages are named after the targets. We do a normal debug build and tests first because these are cheaper to do and will give a shorter turnaround time for developers if any tests fail. You can also only run tests with debug builds. Fixes #72. --- .travis.yml | 23 +++++++++------ ci.sh | 80 ++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c745e51..a22e2924 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,12 +9,6 @@ matrix: - gcc-arm-linux-gnueabihf - libc6-armhf-cross - libc6-dev-armhf-cross - - env: TARGET=i686-unknown-linux-gnu - addons: - apt: - packages: - - gcc-multilib - - env: TARGET=x86_64-unknown-linux-gnu - env: TARGET=x86_64-unknown-linux-musl dist: trusty sudo: required @@ -29,10 +23,8 @@ matrix: apt: packages: - gcc-mingw-w64 - - gcc-mingw-w64-i686 - gcc-mingw-w64-x86-64 - binutils-mingw-w64-x86-64 - - binutils-mingw-w64-i686 - libbz2-dev install: @@ -47,3 +39,18 @@ script: branches: only: - master + +deploy: + provider: releases + api_key: + secure: + OY6y0xRhlGSBH+3+7+7K6s4pp0Tf3BA61NAubEK4gpO23AKfyJUK+vqqCbdo06Z0E4QO4O1ke6fot7Gq9EdxJmsl/Kk5LDd9Rv3BXSYdjPupzs7coYuD8wv10NfAX6ETd9ITyPim2Zq6bq8nx1S2ESTpos/js1HCtVW3nrlCV58= + skip_cleanup: true + file: + - "geckodriver-$TRAVIS_TAG.tar.gz" + - "geckodriver-$TRAVIS_TAG-arm7hf.zip" + - "geckodriver-$TRAVIS_TAG-win64.zip" + - "geckodriver-$TRAVIS_TAG-linux64.tar.gz" + on: + tags: true + repo: mozilla/geckodriver diff --git a/ci.sh b/ci.sh index d47e7ad9..4ad7e2b0 100644 --- a/ci.sh +++ b/ci.sh @@ -42,16 +42,26 @@ linker = "$prefix-gcc" EOF } -# Build current crate and print file type information. +# Build current crate for given target and print file type information. +# If the second argument is set, a release build will be made. cargo_build() { - cargo build --target $1 - - if [[ "$1" =~ "windows" ]] + local mode + if [ -z "$2" ] then - file target/$1/debug/geckodriver.exe + mode=debug else - file target/$1/debug/geckodriver + mode=release fi + + local modeflag + if [ "$mode" == "release" ] + then + modeflag=--release + fi + + cargo build --target $1 $modeflag + + file $(get_binary $1 $mode) } # Run current crate's tests if the current system supports it. @@ -59,16 +69,72 @@ cargo_test() { if echo "$1" | grep -E "(i686|x86_64)-unknown-linux-(gnu|musl)" then cargo test --target $1 + fi +} + +# Returns relative path to binary +# based on build target and type ("release"/"debug"). +get_binary() { + local ext + if [[ "$1" =~ "windows" ]] + then + ext=".exe" + fi + echo "target/$1/$2/geckodriver$ext" +} + +# Create a compressed archive of the binary +# for the given given git tag, build target, and build type. +package_binary() { + local target + case "$2" in + armv7-unknown-linux-gnueabihf) + target=arm7hf + ;; + x86_64-pc-windows-gnu) + target=win64 + ;; + x86_64-unknown-linux-musl) + target=linux64 + ;; + esac + + local bin + bin=$(get_binary $2 $3) + cp $bin . + + if [[ "$2" =~ "windows" ]] + then + zip geckodriver-$1-$target.zip geckodriver.exe + file geckodriver-$1-$target.zip else - >&2 echo "not running tests on $1" + tar zcvf geckodriver-$1-$target.tar.gz geckodriver + file geckodriver-$1-$target.tar.gz fi } +# Create a compressed archive of the source code +# for the given git tag. +package_source() { + git archive --format=tar --prefix="geckodriver-$1/" $1 | \ + gzip >geckodriver-$1.tar.gz +} + main() { rustup_target_add $TARGET + cargo_config $TARGET cargo_build $TARGET cargo_test $TARGET + + # when something is tagged, + # also create a release build and package it + if [ ! -z "$TRAVIS_TAG" ] + then + cargo_build $TARGET 1 + package_binary $TRAVIS_TAG $TARGET "release" + package_source $TRAVIS_TAG + fi } main