1
0
mirror of https://github.com/actix/examples synced 2024-11-23 14:31:07 +01:00

migrate ci to github actions (#367)

This commit is contained in:
Rob Ede 2020-09-16 01:11:49 +01:00 committed by GitHub
parent e3c6a1ec07
commit d836b046c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 6522 additions and 77 deletions

58
.github/workflows/clippy-fmt.yml vendored Normal file
View File

@ -0,0 +1,58 @@
name: lint
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
fmt:
name: rustfmt check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
override: true
- name: rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
clippy:
name: clippy check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: cache cargo artifacts
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
./target/debug
key: cargo-clippy-${{ matrix.version }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-clippy-${{ matrix.version }}-
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
override: true
- name: clippy
uses: actions-rs/clippy-check@v1
timeout-minutes: 30
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --all-features --tests

60
.github/workflows/linux.yml vendored Normal file
View File

@ -0,0 +1,60 @@
name: CI (Linux)
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- master
jobs:
build_and_test:
name: ${{ matrix.version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ["stable", "nightly"]
steps:
- uses: actions/checkout@v2
- name: cache cargo artifacts
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
./target/debug
key: cargo-linux-${{ matrix.version }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-linux-${{ matrix.version }}-
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.version }}
override: true
- name: cargo check
uses: actions-rs/cargo@v1
timeout-minutes: 30
with:
command: check
args: --workspace --bins --examples --tests
- name: start redis
uses: supercharge/redis-github-action@1.1.0
with:
redis-version: 6
- name: cargo test
uses: actions-rs/cargo@v1
timeout-minutes: 30
env:
# included in example of redis, not clear its purpose
CI: true
with:
command: test
args: --workspace --all-features --no-fail-fast -- --nocapture

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
**/Cargo.lock
!/Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk

View File

@ -1,54 +0,0 @@
language: rust
dist: xenial
addons:
apt:
sources:
- ppa:chris-lea/redis-server
packages:
- redis-server
services:
- redis-server
cache:
apt: true
directories:
- $HOME/.cargo
- $HOME/.rustup
before_cache:
- rm -rf $HOME/.cargo/registry
matrix:
include:
- rust: stable
- rust: beta
- rust: nightly
allow_failures:
- rust: nightly
env:
global:
# - RUSTFLAGS="-C link-dead-code"
- OPENSSL_VERSION=openssl-1.1.1
before_install:
- sudo apt-get -qq update
- sudo apt-get -y install libssl-dev libelf-dev libdw-dev binutils-dev libiberty-dev
# Add clippy
before_script:
- |
if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then
rustup component add clippy --toolchain=nightly
fi
- export PATH=$PATH:~/.cargo/bin
script:
- cargo check --all
- cargo test --all --no-fail-fast
- |
if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then
cargo clippy
fi

6384
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

8
codecov.yml Normal file
View File

@ -0,0 +1,8 @@
coverage:
status:
project:
default:
threshold: 1% # make CI green
patch:
default:
threshold: 1% # make CI green

View File

@ -24,11 +24,3 @@ async fn main() -> std::io::Result<()> {
.run()
.await
}
#[cfg(test)]
mod tests {
#[test]
fn sample_test() {
assert!(true);
}
}

View File

@ -32,11 +32,11 @@ fn json_error_handler(err: error::JsonPayloadError, _req: &HttpRequest) -> error
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(greet)
.app_data(web::JsonConfig::default()
.error_handler(json_error_handler)
) // <- register error_handler for JSON extractors.
App::new().service(greet).app_data(
web::JsonConfig::default()
// register error_handler for JSON extractors.
.error_handler(json_error_handler),
)
})
.bind("127.0.0.1:8088")?
.run()

View File

@ -108,7 +108,6 @@ mod test {
App,
};
use serde_json::json;
use time;
#[actix_rt::test]
async fn test_workflow() {
@ -233,10 +232,7 @@ mod test {
.into_iter()
.find(|c| c.name() == "test-session")
.unwrap();
assert_eq!(
true,
cookie_1.value().to_string() != cookie_2.value().to_string()
);
assert_ne!(cookie_1.value(), cookie_2.value());
let result_5 = resp_5.json::<IndexResponse>().await.unwrap();
assert_eq!(
@ -294,7 +290,7 @@ mod test {
counter: 0
}
);
assert!(cookie_3.value().to_string() != cookie_2.value().to_string());
assert_ne!(cookie_3.value(), cookie_2.value());
// Step 9: POST to logout, including session cookie #2
// - set-cookie actix-session will be in response with session cookie #2
@ -333,6 +329,6 @@ mod test {
.into_iter()
.find(|c| c.name() == "test-session")
.unwrap();
assert!(cookie_5.value().to_string() != cookie_2.value().to_string());
assert_ne!(cookie_5.value(), cookie_2.value());
}
}

View File

@ -75,7 +75,7 @@ impl Broadcaster {
fn spawn_ping(me: Data<Mutex<Self>>) {
actix_web::rt::spawn(async move {
let mut task = interval_at(Instant::now(), Duration::from_secs(10));
while let Some(_) = task.next().await {
while task.next().await.is_some() {
me.lock().unwrap().remove_stale_clients();
}
})

View File

@ -119,7 +119,7 @@ impl Handler<Connect> for ChatServer {
// auto join session to Main room
self.rooms
.entry("Main".to_owned())
.or_insert(HashSet::new())
.or_insert_with(HashSet::new)
.insert(id);
// send id back
@ -198,7 +198,7 @@ impl Handler<Join> for ChatServer {
self.rooms
.entry(name.clone())
.or_insert(HashSet::new())
.or_insert_with(HashSet::new)
.insert(id);
self.send_message(&name, "Someone connected", id);