Skip to content

Commit

Permalink
WIP: automated releases
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Oct 2, 2018
1 parent b066cf4 commit bee7ecf
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 2 deletions.
81 changes: 79 additions & 2 deletions .travis.yml
@@ -1,9 +1,86 @@
# Based on the "trust" template v0.1.2
# https://github.com/japaric/trust/tree/v0.1.2

dist: trusty
language: rust
cache:
- cargo
services: docker
sudo: required

# TODO Rust builds on stable by default, this can be
# overridden on a case by case basis down below.

env:
global:
# TODO Update this to match the name of your project.
- CRATE_NAME=trust

matrix:
# TODO These are all the build jobs. Adjust as necessary. Comment out what you
# don't need
include:
- 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

# Windows
- env: TARGET=x86_64-pc-windows-gnu

before_install:
- set -e
- rustup self update

install:
- sh ci/install.sh
- source ~/.cargo/env || true

before_script:
- rustup component add clippy-preview

script:
- cargo clippy -- -D warnings
- cargo build
- python tests/check_examples.py

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 0123456789012345678901234567890123456789
# - Paste the output down here
api_key:
secure: k6Dv0rzo4PnXoMjxUTx1jUIc1vKYUbCKc+RjW3QaqWWQ8IrbnKqIm4+xdX60xCTTr17k+kxalK3Sdu+Aj4pr8XvvYh5ko7nYbZ7XZwX8EYdQHpmfiUNpG22neEY2W3KG0x++CHYCnZep69VMbrMrfa+c1O9FBWWGUDcPvOt0T7dDOngp7tSnpYxc9a3wBRMJT9QocY+ZSrwTmiwNhdemYa83ZhOYcimPc640vwR4YEu+OXhbnFuURotyyqHhOkQ7irVNhYDAnpi4vAagaEiNrxXhIK8LxkOvHOy6NY7W8arqU3/IZxI9djc7wyLnHDSNYHt8c9af1ZRmY0LE7pWolFKtqJPhD7RzBJVemmC0OMTBZxbl7X4oLRaRaKpviyWag6eoyMH5iOKFl6wNFARmsi4xUxusaaXKikzoxQVwSejiXUcpePj9hMfiYQfc5lvKSgH+xL/tj4KATmr3p9fz90rQtnrsGaI/kOe0XoO5Ydg2dXmZu2R3woYivFOY5D4+LZxW2AC6qXd9eBobdfeDWJ7gvLYwGdr3Egy1xugOw2MZvUEHubWx3vW5DVdWwA+zQFKd8H6hIlCzfxgOOMZTPOpUIQAvAXDPzqCLWnYXQYrLShEvGh9yeXeTW+J92zXZ0iODsH62BCAO10Bln4on/Rx1NkHI28V+C+Gmtn9Tv/I=
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

branches:
only:
# release tags
- /^v\d+\.\d+\.\d+.*$/
- master

notifications:
email:
on_success: never
23 changes: 23 additions & 0 deletions 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\blocktest.exe" '.\'

7z a "$ZIP" *

Push-AppveyorArtifact "$ZIP"

Remove-Item *.* -Force
Set-Location ..
Remove-Item $STAGE
Set-Location $SRC_DIR
33 changes: 33 additions & 0 deletions 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 blocktest --target $TARGET --release -- -C lto

# TODO Update this to package the right artifacts
cp target/$TARGET/release/blocktest $stage/

cd $stage
tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz *
cd $src

rm -rf $stage
}

main
47 changes: 47 additions & 0 deletions 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
24 changes: 24 additions & 0 deletions 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

0 comments on commit bee7ecf

Please sign in to comment.