From a1147ba3cd9cf92cc4013c2ddec40b08d7dc5d71 Mon Sep 17 00:00:00 2001 From: Paul Delafosse Date: Sun, 13 Sep 2020 11:35:56 +0200 Subject: [PATCH] ci: add github action ci/cd --- .github/workflows/CD.yml | 45 ++++++++++++++++++++++++++ .github/workflows/CI.yml | 69 ++++++++++++++++++++++++++++++++++++++++ ci/action.sh | 47 +++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 .github/workflows/CD.yml create mode 100644 .github/workflows/CI.yml create mode 100644 ci/action.sh diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml new file mode 100644 index 00000000..0e92ee5a --- /dev/null +++ b/.github/workflows/CD.yml @@ -0,0 +1,45 @@ +name: Publish + +on: + push: + tags: + - '*' + +jobs: + binary: + name: Publish binary for ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + # This should work with only the `include`s but it currently doesn't because of this bug: + # https://github.community/t5/How-to-use-Git-and-GitHub/GitHub-Actions-Matrix-options-dont-work-as-documented/td-p/29558 + target: [x86_64-osx, x86_64-unknown-linux-musl, armv7-unknown-linux-musleabihf, armv7-linux-androideabi, aarch64-linux-android] + include: + - os: macos-latest + target: x86_64-osx + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + - os: ubuntu-latest + target: armv7-unknown-linux-musleabihf + - os: ubuntu-latest + target: armv7-linux-androideabi + - os: ubuntu-latest + target: aarch64-linux-android + + steps: + - uses: hecrj/setup-rust-action@v1.3.1 + with: + rust-version: nightly + - uses: actions/checkout@v1 + - name: Build + run: ci/action.sh release ${{ matrix.target }} + - name: Get the version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v1-release + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/tar/cocogito.tar.gz + tag: ${{ github.ref }} + asset_name: cocogitto-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}.tar.gz \ No newline at end of file diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..e36db3d8 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,69 @@ + +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + test: + name: Tests + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: Test + uses: actions-rs/tarpaulin@v0.1 + with: + args: '-- --test-threads 1' + + - name: Upload to codecov.io + uses: codecov/codecov-action@v1.0.2 + with: + token: ${{secrets.CODECOV_TOKEN}} + + - name: Archive code coverage results + uses: actions/upload-artifact@v1 + with: + name: code-coverage-report + path: cobertura.xml + + lints: + name: Lints & Format + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rustfmt, clippy + + - name: Run cargo fmt + uses: actions-rs/cargo@v1 + continue-on-error: false + with: + command: fmt + args: --all -- --check + + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + continue-on-error: false + with: + command: clippy + args: -- -D warnings \ No newline at end of file diff --git a/ci/action.sh b/ci/action.sh new file mode 100644 index 00000000..2cc189b8 --- /dev/null +++ b/ci/action.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -euo pipefail + +export COCOGITTO_HOME="$(cd "$(dirname "$0")/.." && pwd)" + +echoerr() { + echo "$@" 1>&2 +} + +release() { + + TAR_DIR="${COCOGITTO_HOME}/target/tar" + + target="${1:-}" + if [[ $target == *"osx"* ]]; then + echoerr "OSX cross-compile is impossible. Fallbacking to cargo..." + target="" + fi + + cd "$COCOGITTO_HOME" + + rm -rf "${COCOGITTO_HOME}/target" 2> /dev/null || true + + if [ -n "$target" ]; then + cargo install cross 2> /dev/null || true + cross build --release --target "$target" --bin cocogitto + bin_folder="${target}/release" + else + cargo build --release + bin_folder="release" + fi + + bin_path="${COCOGITTO_HOME}/target/${bin_folder}/cocogitto" + chmod +x "$bin_path" + mkdir -p "$TAR_DIR" 2> /dev/null || true + + cp "$bin_path" "$TAR_DIR" + + cd "$TAR_DIR" + tar -czf cocogitto.tar.gz * + +} + +cmd="$1" +shift + +release "$@" \ No newline at end of file