From 866a4e238904b28178d7a2130dd91bf877a2ccc6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 16 Jan 2021 20:56:37 +0300 Subject: [PATCH] CI --- .github/workflows/ci.yaml | 49 +++++++++++++++----------------- Cargo.toml | 5 ++++ bors.toml | 5 +--- xtask/Cargo.toml | 9 ++++++ xtask/src/main.rs | 59 +++++++++++++++++++++++++++++++++++++++ xtask/tests/tidy.rs | 6 ++++ 6 files changed, 103 insertions(+), 30 deletions(-) create mode 100644 xtask/Cargo.toml create mode 100644 xtask/src/main.rs create mode 100644 xtask/tests/tidy.rs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6b2894f..36259c7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,34 +2,31 @@ name: CI on: pull_request: push: - branches: - - master - - staging - - trying + branches: ["master", "staging", "trying"] + +env: + CARGO_INCREMENTAL: 0 + CARGO_NET_RETRY: 10 + CI: 1 + RUST_BACKTRACE: short + RUSTFLAGS: -D warnings + RUSTUP_MAX_RETRIES: 10 jobs: - tests: - name: Tests + test: + name: Rust runs-on: ubuntu-latest - - strategy: - matrix: - rust: [stable, beta] - - steps: - - name: Checkout repository - uses: actions/checkout@v2 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # fetch tags for publish + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - profile: minimal - override: true - - - name: Run Tests - run: cargo test --all-features --all-targets - - - name: Run Tests (release) - run: cargo test --release + - run: cargo run -p xtask -- ci + env: + CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index a3ce4af..2a6f4a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,11 @@ license = "MIT OR Apache-2.0" description = "Library for generic lossless syntax trees" edition = "2018" +exclude = [".github/", "bors.toml", "rustfmt.toml"] + +[workspace] +members = ["xtask"] + [dependencies] rustc-hash = "1.0.1" smol_str = "0.1.10" diff --git a/bors.toml b/bors.toml index c5e58d2..b92b99a 100644 --- a/bors.toml +++ b/bors.toml @@ -1,5 +1,2 @@ -status = [ - "Tests (stable)", - "Tests (beta)", -] +status = [ "Rust" ] delete_merged_branches = true diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 0000000..be9c166 --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "xtask" +version = "0.0.0" +publish = false +authors = ["Aleksey Kladov "] +edition = "2018" + +[dependencies] +xaction = "0.2" diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 0000000..d8ee44b --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,59 @@ +use std::env; + +use xaction::{cargo_toml, cmd, git, section, Result}; + +fn main() { + if let Err(err) = try_main() { + eprintln!("error: {}", err); + std::process::exit(1) + } +} + +fn try_main() -> Result<()> { + let subcommand = std::env::args().nth(1); + match subcommand { + Some(it) if it == "ci" => (), + _ => { + print_usage(); + Err("invalid arguments")? + } + } + + let cargo_toml = cargo_toml()?; + + { + let _s = section("BUILD"); + cmd!("cargo test --workspace --no-run").run()?; + } + + { + let _s = section("TEST"); + cmd!("cargo test --workspace -- --nocapture").run()?; + } + + let version = cargo_toml.version()?; + let tag = format!("v{}", version); + + let dry_run = + env::var("CI").is_err() || git::has_tag(&tag)? || git::current_branch()? != "master"; + xaction::set_dry_run(dry_run); + + { + let _s = section("PUBLISH"); + cargo_toml.publish()?; + git::tag(&tag)?; + git::push_tags()?; + } + Ok(()) +} + +fn print_usage() { + eprintln!( + "\ +Usage: cargo run -p xtask + +SUBCOMMANDS: + ci +" + ) +} diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs new file mode 100644 index 0000000..97c423a --- /dev/null +++ b/xtask/tests/tidy.rs @@ -0,0 +1,6 @@ +use xaction::cmd; + +#[test] +fn test_formatting() { + cmd!("cargo fmt --all -- --check").run().unwrap() +}