Skip to content

Commit

Permalink
#56: Auto-deploy to github releases from travis, appveyor and circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
ozkriff committed Sep 17, 2017
1 parent 426497e commit 0d2d4df
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 6 deletions.
25 changes: 21 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
version: 2

jobs:
test:
working_directory: ~/tgst
build:
docker:
- image: tomaka/cargo-apk
steps:
- checkout
- run: cargo apk build

deploy:
docker:
- image: tomaka/cargo-apk
steps:
- checkout
- run: git clone --depth=1 https://github.com/ozkriff/zemeroth_assets assets
- run: cargo apk build
- run: ./.circleci/upload_apk_to_github_releases.sh

workflows:
version: 2
build-test-and-deploy:
build-and-deploy:
jobs:
- test
- build:
filters:
tags:
ignore: /.*/
- deploy:
filters:
tags:
only: /.*/
branches:
ignore: /.*/
35 changes: 35 additions & 0 deletions .circleci/upload_apk_to_github_releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

# Based on https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447

# https://github.com/settings/tokens -> circleci's env GITHUB_API_TOKEN

set -e

tag=$CIRCLE_TAG
owner=$CIRCLE_PROJECT_USERNAME
repo=$CIRCLE_PROJECT_REPONAME
filename=./zemeroth-debug.apk
GH_REPO="https://api.github.com/repos/$owner/$repo"
GH_TAGS="$GH_REPO/releases/tags/$tag"
AUTH="Authorization: token $GITHUB_API_TOKEN"

cp ./target/android-artifacts/app/build/outputs/apk/app-debug.apk $filename

# Validate token.
curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; }

# Create a release
RELEASE_URL="https://api.github.com/repos/$owner/$repo/releases?access_token=$GITHUB_API_TOKEN"
curl --data "{\"tag_name\": \"$tag\"}" $RELEASE_URL

# Read asset tags
response=$(curl -sH "$AUTH" $GH_TAGS)

# Get ID of the asset based on given filename
eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
[ "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response\n" >&2; exit 1; }

# Upload the asset
GH_ASSET="https://uploads.github.com/repos/$owner/$repo/releases/$id/assets?name=$(basename $filename)"
curl --data-binary @"$filename" -H "$AUTH" -H "Content-Type: application/octet-stream" $GH_ASSET
22 changes: 21 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: rust

env:
- zipname="zemeroth-$TRAVIS_OS_NAME.tar.gz"

cache: cargo

rust:
Expand All @@ -18,4 +21,21 @@ os:
sudo: false

script:
- cargo build && cargo test
- cargo build
- cargo test
- cargo build --release

before_deploy:
- git clone --depth=1 https://github.com/ozkriff/zemeroth_assets assets
- mv target/release/zemeroth .
- tar -zcvf $zipname assets zemeroth

deploy:
provider: releases
skip_cleanup: true
overwrite: true
file: $zipname
api_key:
secure: sn8NPGcybxiRAIDp5Tk5nhvg89PTgm75VjkyjYfufKmuk3KDOhW2b2CYC6VvlM88a4FAMSWDaYXKi0N3yEYFC2RmqrvtpocBGKsom2fSmvRv/4YWIWCOK7Zpw7IBhRfTn/2dHkLa3Uy+7dyO96LW8qtiuEsotyJCrWaXuLr1+wYdWXWL6oeGsw41sB22Umc4WZJP/SryjGb+5b349WNCipf0rMLdU0sqW7fOJfIg0cv9W1k9FiuHLfw3Li1JzU2qo5TWX3oxv8MPFQ9/lVEHAYkI8tvxaSheN/L3xlpWV1Qjrk9vxN1bIVygyCaARJhzTgTAZ+OH4B1h1Mkwc0emY6ITRbcN4khko599E17AvmhVrB7xE0wNtJtVS9z2coWqcC4MO1yLIFGyC8hxH6BubmGTQln1q7KRy48l8uNJczfW+vi6lwj8Sni0HungZZBzyfv6eNPzU0IZE6rh+FN2pmdfaqAxjo8BPfyZvJFuJqJcTNvUkdT9fXyILgHuzdEmQBOVZhzqn3jOJfv3kHpaEF7prywEEzRr0A4S1RvMCyYN9PH7XvcGKGq1dJNEwCHmgnUfuCkROBKBnsa9PvJTPy3tHY7Z0EhveoQYXMnfhlqN3LTBb3l6Gwg2GK1lajLuLB/Q6tGKuGgRI1r5sLwqPFioIjuL71LecnAgyMilm5c=
on:
tags: true
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ News: https://twitter.com/ozkriff
Devlog album: http://imgur.com/a/SMVqO


Downloads
---------

Precompiled binaries for linux, win, osx and android: https://github.com/ozkriff/zemeroth/releases


Overview
--------

Expand Down
24 changes: 23 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
environment:
global:
PROJECT_NAME: zemeroth
matrix:
- TARGET: i686-pc-windows-gnu
CHANNEL: stable
Expand Down Expand Up @@ -28,8 +30,28 @@ install:
build: false

test_script:
- cmd: 'cargo build && cargo test'
- cmd: 'cargo build && cargo test && cargo build --release'

cache:
- target
- C:\Users\appveyor\.cargo\registry

before_deploy:
- mkdir staging
- mkdir staging\assets
- copy target\release\zemeroth.exe staging
- cd staging
- git clone --depth=1 https://github.com/ozkriff/zemeroth_assets assets
- 7z a ../%PROJECT_NAME%-%TARGET%.zip *
- appveyor PushArtifact ../%PROJECT_NAME%-%TARGET%.zip

deploy:
provider: GitHub
artifact: /.*\.zip/
auth_token:
secure: ENk8Tp+3wU90QF5utTGj5QM3bYyXHRtWm+mMgH+SotiCbIRc6mf0DsoKQgA1F/64
on:
CHANNEL: stable
appveyor_repo_tag: true
branch:
- master

0 comments on commit 0d2d4df

Please sign in to comment.