From f5fd7786f8678516971d54e432edca9348788be7 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 21 Apr 2020 17:53:29 -0700 Subject: [PATCH] Switch CI to GitHub Actions --- .github/workflows/ci.yaml | 75 +++++++++++++++++++++++++++++++++++ .github/workflows/master.yaml | 31 +++++++++++++++ .github/workflows/pr.yaml | 46 +++++++++++++++++++++ .travis.yml | 36 ----------------- Cargo.toml | 2 +- README.md | 4 +- bors.toml | 8 +++- ci/rustup.sh | 12 +++--- ci/test_full.sh | 74 +++++++++++++++++++++++----------- 9 files changed, 217 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/master.yaml create mode 100644 .github/workflows/pr.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..0e936f9 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,75 @@ +name: CI +on: + push: + branches: + - staging + - trying + +jobs: + + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + rust: [ + 1.31.0, # 2018! + 1.32.0, # rand + stable, + beta, + nightly + ] + steps: + - name: Rust install + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + - name: Checkout + uses: actions/checkout@v2 + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + - name: Test + run: ./ci/test_full.sh + + # try a target that doesn't have std at all, but does have alloc + no_std: + name: No Std + runs-on: ubuntu-latest + steps: + - name: Rust install + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + target: thumbv6m-none-eabi + - name: Checkout + uses: actions/checkout@v1 + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --target thumbv6m-none-eabi --no-default-features --features "libm rand serde" + + fmt: + name: Format + runs-on: ubuntu-latest + steps: + - name: Rust install + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.42.0 + profile: minimal + override: true + components: rustfmt + - name: Checkout + uses: actions/checkout@v2 + - name: Check formatting + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check diff --git a/.github/workflows/master.yaml b/.github/workflows/master.yaml new file mode 100644 index 0000000..1bc4ec6 --- /dev/null +++ b/.github/workflows/master.yaml @@ -0,0 +1,31 @@ +name: master +on: + push: + branches: + - master + schedule: + - cron: '0 0 * * 0' # 00:00 Sunday + +jobs: + + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + rust: [1.31.0, stable] + steps: + - name: Rust install + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + - name: Checkout + uses: actions/checkout@v2 + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + - name: Test + run: ./ci/test_full.sh diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..8641b5a --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,46 @@ +name: PR +on: + pull_request: + +jobs: + + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + rust: [1.31.0, stable] + steps: + - name: Rust install + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + - name: Checkout + uses: actions/checkout@v2 + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + - name: Test + run: ./ci/test_full.sh + + fmt: + name: Format + runs-on: ubuntu-latest + steps: + - name: Rust install + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.42.0 + profile: minimal + override: true + components: rustfmt + - name: Checkout + uses: actions/checkout@v2 + - name: Check formatting + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 428599e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: rust -sudo: false -rust: - - 1.31.0 # 2018! - - 1.32.0 # rand - - stable - - beta - - nightly -script: - - cargo build --verbose - - ./ci/test_full.sh -matrix: - include: - # try a target that doesn't have std at all - - name: "no_std" - rust: stable - env: TARGET=thumbv6m-none-eabi - before_script: - - rustup target add $TARGET - script: - - cargo build --verbose --target $TARGET --no-default-features --features libm,rand,serde - - name: "rustfmt" - rust: 1.31.0 - before_script: - - rustup component add rustfmt - script: - - cargo fmt --all -- --check -notifications: - email: - on_success: never -branches: - only: - - master - - next - - staging - - trying diff --git a/Cargo.toml b/Cargo.toml index 5163eb8..9112539 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ name = "num-complex" repository = "https://github.com/rust-num/num-complex" version = "0.3.0-pre" readme = "README.md" -exclude = ["/ci/*", "/.travis.yml", "/bors.toml"] +exclude = ["/bors.toml", "/ci/*", "/.github/*"] publish = false edition = "2018" diff --git a/README.md b/README.md index fe8f183..73bcb48 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![crate](https://img.shields.io/crates/v/num-complex.svg)](https://crates.io/crates/num-complex) [![documentation](https://docs.rs/num-complex/badge.svg)](https://docs.rs/num-complex) -![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg) -[![Travis status](https://travis-ci.org/rust-num/num-complex.svg?branch=master)](https://travis-ci.org/rust-num/num-complex) +[![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) +[![build status](https://github.com/rust-num/num-complex/workflows/master/badge.svg)](https://github.com/rust-num/num-complex/actions) `Complex` numbers for Rust. diff --git a/bors.toml b/bors.toml index ca08e81..9bc7ba2 100644 --- a/bors.toml +++ b/bors.toml @@ -1,3 +1,9 @@ status = [ - "continuous-integration/travis-ci/push", + "Test (1.31.0)", + "Test (1.32.0)", + "Test (stable)", + "Test (beta)", + "Test (nightly)", + "No Std", + "Format", ] diff --git a/ci/rustup.sh b/ci/rustup.sh index f7cf748..0f94c36 100755 --- a/ci/rustup.sh +++ b/ci/rustup.sh @@ -1,12 +1,10 @@ #!/bin/sh -# Use rustup to locally run the same suite of tests as .travis.yml. -# (You should first install/update all versions listed below.) +# Use rustup to locally run the same suite of tests as .github/workflows/ +# (You should first install/update all of the versions below.) set -ex -export TRAVIS_RUST_VERSION -for TRAVIS_RUST_VERSION in 1.31.0 1.32.0 stable beta nightly; do - run="rustup run $TRAVIS_RUST_VERSION" - $run cargo build --verbose - $run $PWD/ci/test_full.sh +ci=$(dirname $0) +for version in 1.31.0 1.32.0 stable beta nightly; do + rustup run "$version" "$ci/test_full.sh" done diff --git a/ci/test_full.sh b/ci/test_full.sh index ca71bbf..cb531df 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -1,32 +1,58 @@ #!/bin/bash -set -ex - -echo Testing num-complex on rustc ${TRAVIS_RUST_VERSION} - -case "$TRAVIS_RUST_VERSION" in - 1.31.*) FEATURES="libm serde" ;; - *) FEATURES="libm serde rand" ;; -esac - -# num-complex should build and test everywhere. -cargo build --verbose -cargo test --verbose - -# It should build with minimal features too. +set -e + +CRATE=num-complex +MSRV=1.31 + +get_rust_version() { + local array=($(rustc --version)); + echo "${array[1]}"; + return 0; +} +RUST_VERSION=$(get_rust_version) + +check_version() { + IFS=. read -ra rust <<< "$RUST_VERSION" + IFS=. read -ra want <<< "$1" + [[ "${rust[0]}" -gt "${want[0]}" || + ( "${rust[0]}" -eq "${want[0]}" && + "${rust[1]}" -ge "${want[1]}" ) + ]] +} + +echo "Testing $CRATE on rustc $RUST_VERSION" +if ! check_version $MSRV ; then + echo "The minimum for $CRATE is rustc $MSRV" + exit 1 +fi + +FEATURES=(libm serde) +check_version 1.32 && FEATURES+=(rand) +echo "Testing supported features: ${FEATURES[*]}" + +set -x + +# test the default +cargo build +cargo test + +# test `no_std` cargo build --no-default-features cargo test --no-default-features -# Each isolated feature should also work everywhere. -for feature in $FEATURES; do - cargo build --verbose --no-default-features --features="$feature" - cargo test --verbose --no-default-features --features="$feature" +# test each isolated feature, with and without std +for feature in ${FEATURES[*]}; do + cargo build --no-default-features --features="std $feature" + cargo test --no-default-features --features="std $feature" + + cargo build --no-default-features --features="$feature" + cargo test --no-default-features --features="$feature" done -# test all supported features together -cargo build --features="$FEATURES" -cargo test --features="$FEATURES" +# test all supported features, with and without std +cargo build --features="std ${FEATURES[*]}" +cargo test --features="std ${FEATURES[*]}" -# test all supported features together with std -cargo build --features="std $FEATURES" -cargo test --features="std $FEATURES" +cargo build --features="${FEATURES[*]}" +cargo test --features="${FEATURES[*]}"