Skip to content

Commit 866a4e2

Browse files
committed
CI
1 parent da1ecae commit 866a4e2

File tree

6 files changed

+103
-30
lines changed

6 files changed

+103
-30
lines changed

.github/workflows/ci.yaml

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,31 @@ name: CI
22
on:
33
pull_request:
44
push:
5-
branches:
6-
- master
7-
- staging
8-
- trying
5+
branches: ["master", "staging", "trying"]
6+
7+
env:
8+
CARGO_INCREMENTAL: 0
9+
CARGO_NET_RETRY: 10
10+
CI: 1
11+
RUST_BACKTRACE: short
12+
RUSTFLAGS: -D warnings
13+
RUSTUP_MAX_RETRIES: 10
914

1015
jobs:
11-
tests:
12-
name: Tests
16+
test:
17+
name: Rust
1318
runs-on: ubuntu-latest
14-
15-
strategy:
16-
matrix:
17-
rust: [stable, beta]
18-
19-
steps:
2019

21-
- name: Checkout repository
22-
uses: actions/checkout@v2
20+
steps:
21+
- uses: actions/checkout@v2
22+
with:
23+
fetch-depth: 0 # fetch tags for publish
24+
- uses: actions-rs/toolchain@v1
25+
with:
26+
toolchain: stable
27+
profile: minimal
28+
override: true
2329

24-
- name: Install Rust toolchain
25-
uses: actions-rs/toolchain@v1
26-
with:
27-
toolchain: ${{ matrix.rust }}
28-
profile: minimal
29-
override: true
30-
31-
- name: Run Tests
32-
run: cargo test --all-features --all-targets
33-
34-
- name: Run Tests (release)
35-
run: cargo test --release
30+
- run: cargo run -p xtask -- ci
31+
env:
32+
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ license = "MIT OR Apache-2.0"
77
description = "Library for generic lossless syntax trees"
88
edition = "2018"
99

10+
exclude = [".github/", "bors.toml", "rustfmt.toml"]
11+
12+
[workspace]
13+
members = ["xtask"]
14+
1015
[dependencies]
1116
rustc-hash = "1.0.1"
1217
smol_str = "0.1.10"

bors.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
status = [
2-
"Tests (stable)",
3-
"Tests (beta)",
4-
]
1+
status = [ "Rust" ]
52
delete_merged_branches = true

xtask/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "xtask"
3+
version = "0.0.0"
4+
publish = false
5+
authors = ["Aleksey Kladov <[email protected]>"]
6+
edition = "2018"
7+
8+
[dependencies]
9+
xaction = "0.2"

xtask/src/main.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use std::env;
2+
3+
use xaction::{cargo_toml, cmd, git, section, Result};
4+
5+
fn main() {
6+
if let Err(err) = try_main() {
7+
eprintln!("error: {}", err);
8+
std::process::exit(1)
9+
}
10+
}
11+
12+
fn try_main() -> Result<()> {
13+
let subcommand = std::env::args().nth(1);
14+
match subcommand {
15+
Some(it) if it == "ci" => (),
16+
_ => {
17+
print_usage();
18+
Err("invalid arguments")?
19+
}
20+
}
21+
22+
let cargo_toml = cargo_toml()?;
23+
24+
{
25+
let _s = section("BUILD");
26+
cmd!("cargo test --workspace --no-run").run()?;
27+
}
28+
29+
{
30+
let _s = section("TEST");
31+
cmd!("cargo test --workspace -- --nocapture").run()?;
32+
}
33+
34+
let version = cargo_toml.version()?;
35+
let tag = format!("v{}", version);
36+
37+
let dry_run =
38+
env::var("CI").is_err() || git::has_tag(&tag)? || git::current_branch()? != "master";
39+
xaction::set_dry_run(dry_run);
40+
41+
{
42+
let _s = section("PUBLISH");
43+
cargo_toml.publish()?;
44+
git::tag(&tag)?;
45+
git::push_tags()?;
46+
}
47+
Ok(())
48+
}
49+
50+
fn print_usage() {
51+
eprintln!(
52+
"\
53+
Usage: cargo run -p xtask <SUBCOMMAND>
54+
55+
SUBCOMMANDS:
56+
ci
57+
"
58+
)
59+
}

xtask/tests/tidy.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use xaction::cmd;
2+
3+
#[test]
4+
fn test_formatting() {
5+
cmd!("cargo fmt --all -- --check").run().unwrap()
6+
}

0 commit comments

Comments
 (0)