From 795900cf39ac2411888b572e12e5fa4d01f53400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 10:42:05 +0100 Subject: [PATCH 01/20] CI: Add a lint github workflow. --- .github/workflows/lint.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..3d0ed9d9 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,29 @@ +name: Lint + +on: + push: + pull_request: + branches: [ master ] + +env: + CARGO_TERM_COLOR: always + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all --check + + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-targets -- -D warnings From e24fb8b4714f3ab4907c9ab9cadb3b10b42c20ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 10:44:19 +0100 Subject: [PATCH 02/20] CI: Fix the cargo fmt invocation. --- .github/workflows/lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3d0ed9d9..cb5ece16 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,7 +9,7 @@ env: CARGO_TERM_COLOR: always jobs: - check: + lint: runs-on: ubuntu-latest steps: @@ -21,7 +21,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: fmt - args: --all --check + args: --all -- --check - uses: actions-rs/cargo@v1 with: From 35247fac2abe9e3b50db0c97414800e596412c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 10:50:58 +0100 Subject: [PATCH 03/20] crypto: Fix a lint issue. --- matrix_sdk_crypto/src/olm/account.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index 0557129a..d181aae6 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -170,7 +170,7 @@ impl Account { return Err(OlmError::SessionWedged(user_id, sender_key)); } } - Err(e) => return Err(e.into()), + Err(e) => return Err(e), }; debug!("Decrypted a to-device event {:?}", event); From 59917f45e3a2e3e75543b0c017c257f60b74a965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 11:01:20 +0100 Subject: [PATCH 04/20] matrix-sdk: Fix a clippy lint. --- matrix_sdk/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 195a4a28..c0be1097 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -841,7 +841,7 @@ impl Client { since: Option<&str>, server: Option<&ServerName>, ) -> Result { - let limit = limit.map(|n| UInt::from(n)); + let limit = limit.map(UInt::from); let request = assign!(get_public_rooms::Request::new(), { limit, From 1d5ee22dd2990f5019c34f9fc3b944647fb054c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 11:08:41 +0100 Subject: [PATCH 05/20] CI: Name our lint stages. --- .github/workflows/lint.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cb5ece16..ad5c1e91 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,17 +13,21 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - name: Checkout the repo + uses: actions/checkout@v2 + - name: Install rust + uses: actions-rs/toolchain@v1 with: toolchain: stable - - uses: actions-rs/cargo@v1 + - name: Cargo fmt + uses: actions-rs/cargo@v1 with: command: fmt args: --all -- --check - - uses: actions-rs/cargo@v1 + - name: Clippy + uses: actions-rs/cargo@v1 with: command: clippy args: --all-targets -- -D warnings From 2cc899338a5fd8a0b47a570bbc891047487ca8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 11:21:09 +0100 Subject: [PATCH 06/20] CI: Split out the fmt and clippy runs into two jobs. --- .github/workflows/lint.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ad5c1e91..ffb02400 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Lint +name: CI on: push: @@ -9,16 +9,21 @@ env: CARGO_TERM_COLOR: always jobs: - lint: + style: + name: Check style runs-on: ubuntu-latest steps: - name: Checkout the repo uses: actions/checkout@v2 + - name: Install rust uses: actions-rs/toolchain@v1 with: toolchain: stable + components: rustfmt + profile: minimal + override: true - name: Cargo fmt uses: actions-rs/cargo@v1 @@ -26,6 +31,23 @@ jobs: command: fmt args: --all -- --check + clippy: + name: Run clippy + needs: [style] + runs-on: ubuntu-latest + + steps: + - name: Checkout the repo + uses: actions/checkout@v2 + + - name: Install rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + profile: minimal + override: true + - name: Clippy uses: actions-rs/cargo@v1 with: From e4779163b8d104f396212561f746db39716817ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 11:36:01 +0100 Subject: [PATCH 07/20] CI: Run the tests on the CI. --- .github/workflows/lint.yml | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ffb02400..ece8c47c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -53,3 +53,51 @@ jobs: with: command: clippy args: --all-targets -- -D warnings + + test: + name: ${{ matrix.name }} + needs: [clippy] + + runs-on: ${{ matrix.os || 'ubuntu-latest' }} + strategy: + matrix: + name: + - linux / stable + - linux / beta + - macOS / stable + - windows / stable-x86_64-msvc + + include: + - name: linux / stable + + - name: linux / beta + rust: beta + + - name: macOS / stable + os: macOS-latest + + - name: windows / stable-x86_64-msvc + os: windows-latest + target: x86_64-pc-windows-msvc + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Install rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust || 'stable' }} + target: ${{ matrix.target }} + profile: minimal + override: true + + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + + - name: Test + uses: actions-rs/cargo@v1 + with: + command: test From 27d9cf04de50fd852cf36df2becbdc2b36c6cbb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 11:52:21 +0100 Subject: [PATCH 08/20] base: Remove a flaky state store test. The state store is undergoing a rewrite and this test fails more often than i would like making our CI seem flaky. Remove the test since it's going to become obsolete anyways. --- matrix_sdk_base/src/state/json_store.rs | 40 ------------------------- 1 file changed, 40 deletions(-) diff --git a/matrix_sdk_base/src/state/json_store.rs b/matrix_sdk_base/src/state/json_store.rs index 1eea500b..a959418d 100644 --- a/matrix_sdk_base/src/state/json_store.rs +++ b/matrix_sdk_base/src/state/json_store.rs @@ -360,44 +360,4 @@ mod test { // test that we have removed the correct room assert!(invited.is_empty()); } - - #[tokio::test] - async fn test_client_sync_store() { - let dir = tempdir().unwrap(); - let path: &Path = dir.path(); - - let session = Session { - access_token: "1234".to_owned(), - user_id: user_id!("@cheeky_monkey:matrix.org"), - device_id: "DEVICEID".into(), - }; - - // a sync response to populate our JSON store - let store = Box::new(JsonStore::open(path).unwrap()); - let client = - BaseClient::new_with_config(BaseClientConfig::new().state_store(store)).unwrap(); - client.restore_login(session.clone()).await.unwrap(); - - let mut response = sync_response(SyncResponseFile::Default); - - // gather state to save to the db, the first time through loading will be skipped - client.receive_sync_response(&mut response).await.unwrap(); - - // now syncing the client will update from the state store - let store = Box::new(JsonStore::open(path).unwrap()); - let client = - BaseClient::new_with_config(BaseClientConfig::new().state_store(store)).unwrap(); - client.restore_login(session.clone()).await.unwrap(); - - // assert the synced client and the logged in client are equal - assert_eq!(*client.session().read().await, Some(session)); - assert_eq!( - client.sync_token().await, - Some("s526_47314_0_7_1_1_1_11444_1".to_string()) - ); - assert_eq!( - *client.ignored_users.read().await, - vec![user_id!("@someone:example.org")] - ); - } } From a80aa4c2add874a567ddc89b587d20b841c65678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 12:11:55 +0100 Subject: [PATCH 09/20] base: Fix some lint issues. --- matrix_sdk_base/src/state/json_store.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/matrix_sdk_base/src/state/json_store.rs b/matrix_sdk_base/src/state/json_store.rs index a959418d..19068995 100644 --- a/matrix_sdk_base/src/state/json_store.rs +++ b/matrix_sdk_base/src/state/json_store.rs @@ -224,11 +224,9 @@ mod test { use crate::{ identifiers::{room_id, user_id}, push::Ruleset, - BaseClient, BaseClientConfig, Session, + Session, }; - use matrix_sdk_test::{sync_response, SyncResponseFile}; - #[tokio::test] async fn test_store_client_state() { let dir = tempdir().unwrap(); From b982d363030741437e53d59067d1ccdb41c84b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 12:34:59 +0100 Subject: [PATCH 10/20] crypto: Run the time sensitive tests only on linux. --- matrix_sdk_crypto/src/olm/group_sessions/mod.rs | 2 +- matrix_sdk_crypto/src/session_manager/sessions.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/matrix_sdk_crypto/src/olm/group_sessions/mod.rs b/matrix_sdk_crypto/src/olm/group_sessions/mod.rs index a78bde53..67ac13d9 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/mod.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/mod.rs @@ -138,7 +138,7 @@ mod test { use crate::ReadOnlyAccount; #[tokio::test] - #[cfg(not(target_os = "macos"))] + #[cfg(target_os = "linux")] async fn expiration() { let settings = EncryptionSettings { rotation_period_msgs: 1, diff --git a/matrix_sdk_crypto/src/session_manager/sessions.rs b/matrix_sdk_crypto/src/session_manager/sessions.rs index 2cf2a2cc..51dfcc5e 100644 --- a/matrix_sdk_crypto/src/session_manager/sessions.rs +++ b/matrix_sdk_crypto/src/session_manager/sessions.rs @@ -422,7 +422,7 @@ mod test { // This test doesn't run on macos because we're modifying the session // creation time so we can get around the UNWEDGING_INTERVAL. #[async_test] - #[cfg(not(target_os = "macos"))] + #[cfg(not(target_os = "linux"))] async fn session_unwedging() { let manager = session_manager().await; let bob = bob_account(); From 795c1225dde3e175913e1262780547cd228e1941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 12:37:39 +0100 Subject: [PATCH 11/20] CI: Use the cargo-clippy workflow. --- .github/workflows/lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ece8c47c..4f2094da 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -49,9 +49,9 @@ jobs: override: true - name: Clippy - uses: actions-rs/cargo@v1 + uses: actions-rs/clippy-check@v1 with: - command: clippy + token: ${{ secrets.GITHUB_TOKEN }} args: --all-targets -- -D warnings test: From 0a76f75c226025a39dcdacd071e969054dda2646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 12:45:16 +0100 Subject: [PATCH 12/20] Revert "CI: Use the cargo-clippy workflow." This reverts commit 795c1225dde3e175913e1262780547cd228e1941. --- .github/workflows/lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4f2094da..ece8c47c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -49,9 +49,9 @@ jobs: override: true - name: Clippy - uses: actions-rs/clippy-check@v1 + uses: actions-rs/cargo@v1 with: - token: ${{ secrets.GITHUB_TOKEN }} + command: clippy args: --all-targets -- -D warnings test: From c8dd6bfd26ab2d2c2073b5328d8038d30d6d83fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 12:56:16 +0100 Subject: [PATCH 13/20] crypto: Scope the imports for the unwedging test into the test. --- matrix_sdk_crypto/src/session_manager/sessions.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/matrix_sdk_crypto/src/session_manager/sessions.rs b/matrix_sdk_crypto/src/session_manager/sessions.rs index 51dfcc5e..b074e305 100644 --- a/matrix_sdk_crypto/src/session_manager/sessions.rs +++ b/matrix_sdk_crypto/src/session_manager/sessions.rs @@ -316,8 +316,7 @@ mod test { use matrix_sdk_common::{ api::r0::keys::claim_keys::Response as KeyClaimResponse, - identifiers::{user_id, DeviceIdBox, DeviceKeyAlgorithm, UserId}, - instant::{Duration, Instant}, + identifiers::{user_id, DeviceIdBox, UserId}, }; use matrix_sdk_test::async_test; @@ -424,6 +423,11 @@ mod test { #[async_test] #[cfg(not(target_os = "linux"))] async fn session_unwedging() { + use matrix_sdk_common::{ + identifiers::DeviceKeyAlgorithm, + instant::{Duration, Instant}, + }; + let manager = session_manager().await; let bob = bob_account(); let (_, mut session) = bob.create_session_for(&manager.account).await; From 4ab6ae7f303cb2b46b36df628e437f4def65eb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 13:15:19 +0100 Subject: [PATCH 14/20] crypto: Fix an os_target definition. --- matrix_sdk_crypto/src/session_manager/sessions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix_sdk_crypto/src/session_manager/sessions.rs b/matrix_sdk_crypto/src/session_manager/sessions.rs index b074e305..95afe118 100644 --- a/matrix_sdk_crypto/src/session_manager/sessions.rs +++ b/matrix_sdk_crypto/src/session_manager/sessions.rs @@ -421,7 +421,7 @@ mod test { // This test doesn't run on macos because we're modifying the session // creation time so we can get around the UNWEDGING_INTERVAL. #[async_test] - #[cfg(not(target_os = "linux"))] + #[cfg(target_os = "linux")] async fn session_unwedging() { use matrix_sdk_common::{ identifiers::DeviceKeyAlgorithm, From 40d13d9b598a4ec244a1c5b641840292dc4c1b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 13:37:55 +0100 Subject: [PATCH 15/20] cyrpto: Another timing based test that only works on Linux. --- matrix_sdk_crypto/src/verification/machine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix_sdk_crypto/src/verification/machine.rs b/matrix_sdk_crypto/src/verification/machine.rs index c3ba5e88..c81344c3 100644 --- a/matrix_sdk_crypto/src/verification/machine.rs +++ b/matrix_sdk_crypto/src/verification/machine.rs @@ -380,7 +380,7 @@ mod test { assert!(bob.is_done()); } - #[cfg(not(target_os = "macos"))] + #[cfg(target_os = "linux")] #[tokio::test] async fn timing_out() { let (alice_machine, bob) = setup_verification_machine().await; From fdf48d1f30e1c10f5e6a92741b3affb08df673cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 13:58:26 +0100 Subject: [PATCH 16/20] CI: Rename the workflow file. --- .github/workflows/{lint.yml => ci.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{lint.yml => ci.yml} (100%) diff --git a/.github/workflows/lint.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/workflows/lint.yml rename to .github/workflows/ci.yml From 9679db6ddc0097bcabfa7951b479439c3219fdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 14:05:25 +0100 Subject: [PATCH 17/20] CI: Enable code coverage again. --- .github/workflows/coverage.yml | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..5b0f562d --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,36 @@ +name: Code coverage + +on: + push: + +env: + CARGO_TERM_COLOR: always + +jobs: + code_coverage: + name: Code Coverage + runs-on: "ubuntu-latest" + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install tarpaulin + uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-tarpaulin -f + + - name: Run tarpaulin + uses: actions-rs/cargo@v1 + with: + command: tarpaulin + args: --ignore-config --exclude-files "matrix_sdk/examples/*,matrix_sdk_common,matrix_sdk_test" --out Xml + + - name: Upload to codecov.io + uses: codecov/codecov-action@v1 From fa3583234c2f997d9ceb9e60294ee47dc100b144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 14:09:51 +0100 Subject: [PATCH 18/20] CI: Fix the coverage yml. --- .github/workflows/coverage.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 5b0f562d..bc3d12a9 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -8,9 +8,10 @@ env: jobs: code_coverage: - name: Code Coverage - runs-on: "ubuntu-latest" - steps: + name: Code Coverage + runs-on: "ubuntu-latest" + + steps: - name: Checkout repository uses: actions/checkout@v2 @@ -18,6 +19,7 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: stable + profile: minimal override: true - name: Install tarpaulin From 15b87e9dc1fe6bf1dc488c9790b04a05b6f67378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 14:30:49 +0100 Subject: [PATCH 19/20] CI: Restrict code coverage to the master branch. --- .github/workflows/coverage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index bc3d12a9..8b9076e1 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -2,6 +2,7 @@ name: Code coverage on: push: + branches: [ master ] env: CARGO_TERM_COLOR: always From 594e9b9e2d53af88a3678890307c793a104e865a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 14:31:14 +0100 Subject: [PATCH 20/20] README: Swap out the CI badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2768c56f..7b5dc261 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://img.shields.io/travis/matrix-org/matrix-rust-sdk.svg?style=flat-square)](https://travis-ci.org/matrix-org/matrix-rust-sdk) +![Build Status](https://img.shields.io/github/workflow/status/matrix-org/matrix-rust-sdk/CI?style=flat-square) [![codecov](https://img.shields.io/codecov/c/github/matrix-org/matrix-rust-sdk/master.svg?style=flat-square)](https://codecov.io/gh/matrix-org/matrix-rust-sdk) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg?style=flat-square)](https://opensource.org/licenses/Apache-2.0) [![#matrix-rust-sdk](https://img.shields.io/badge/matrix-%23matrix--rust--sdk-blue?style=flat-square)](https://matrix.to/#/#matrix-rust-sdk:matrix.org)