From 1edcd279dbc4269240c1b22ae2d2c58357d86945 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 9 Sep 2022 09:59:36 +0100 Subject: [PATCH 1/8] Add rust to CI --- .github/workflows/tests.yml | 81 ++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 50dc8e30d491..f38b8e444913 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,6 +10,23 @@ concurrency: cancel-in-progress: true jobs: + # Job to detect what has changed so we don't run e.g. Rust checks on PRs that + # don't modify Rust code. + changes: + runs-on: ubuntu-latest + outputs: + rust: ${{ !startsWith(github.ref, 'refs/pull/') || steps.filter.outputs.rust }} + steps: + - uses: dorny/paths-filter@v2 + id: filter + # We only check on PRs + if: startsWith(github.ref, 'refs/pull/') + with: + filters: | + rust: + - 'rust/**' + - 'Cargo.toml' + check-sampleconfig: runs-on: ubuntu-latest steps: @@ -65,10 +82,52 @@ jobs: extras: "all" - run: poetry run scripts-dev/check_pydantic_models.py + lint-clippy: + runs-on: ubuntu-latest + needs: changes + if: ${{ needs.changes.outputs.rust == 'true' }} + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.61.0 + override: true + - uses: Swatinem/rust-cache@v2 + + - run: cargo clippy + + lint-rustfmt: + runs-on: ubuntu-latest + needs: changes + if: ${{ needs.changes.outputs.rust == 'true' }} + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.61.0 + override: true + - uses: Swatinem/rust-cache@v2 + + - run: cargo fmt --check + # Dummy step to gate other tests on without repeating the whole list linting-done: if: ${{ !cancelled() }} # Run this even if prior jobs were skipped - needs: [lint, lint-crlf, lint-newsfile, lint-pydantic, check-sampleconfig, check-schema-delta] + needs: + - lint + - lint-crlf + - lint-newsfile + - lint-pydantic + - check-sampleconfig + - check-schema-delta + - lint-clippy + - lint-rustfmt runs-on: ubuntu-latest steps: - run: "true" @@ -384,6 +443,25 @@ jobs: shell: bash name: Run Complement Tests + cargo-test: + needs: + - linting-done + - changes + + if: ${{ needs.changes.outputs.rust == 'true' }} + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.61.0 + override: true + - uses: Swatinem/rust-cache@v2 + + - run: cargo test + # a job which marks all the other jobs as complete, thus allowing PRs to be merged. tests-done: if: ${{ always() }} @@ -398,6 +476,7 @@ jobs: - export-data - portdb - complement + - cargo-test runs-on: ubuntu-latest steps: - uses: matrix-org/done-action@v2 From 5ee6d0045c15b028f01d7a57ed44842d3c97fff8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 9 Sep 2022 10:00:23 +0100 Subject: [PATCH 2/8] Newsfile --- changelog.d/13763.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/13763.misc diff --git a/changelog.d/13763.misc b/changelog.d/13763.misc new file mode 100644 index 000000000000..2e0dd68a0f94 --- /dev/null +++ b/changelog.d/13763.misc @@ -0,0 +1 @@ +Add a stub Rust crate. From be7999c15350eef7f80b0f96392f248a1d61e3c3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 9 Sep 2022 10:00:56 +0100 Subject: [PATCH 3/8] Fix yaml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f38b8e444913..543ae66642c3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -448,7 +448,7 @@ jobs: - linting-done - changes - if: ${{ needs.changes.outputs.rust == 'true' }} + if: ${{ needs.changes.outputs.rust == 'true' }} steps: - uses: actions/checkout@v2 From 26cf9c548611fff716188ac0d365280c7930ea30 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 9 Sep 2022 10:01:28 +0100 Subject: [PATCH 4/8] Fix yaml --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 543ae66642c3..c56244388f8d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -444,12 +444,12 @@ jobs: name: Run Complement Tests cargo-test: + if: ${{ needs.changes.outputs.rust == 'true' }} + runs-on: ubuntu-latest needs: - linting-done - changes - if: ${{ needs.changes.outputs.rust == 'true' }} - steps: - uses: actions/checkout@v2 From 61bda300d50a33909ddb355255443a71c6f36ed3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 9 Sep 2022 10:03:38 +0100 Subject: [PATCH 5/8] Test changing rust src file --- rust/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index fc4eb39154fc..142fc2ed93af 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -11,5 +11,6 @@ fn sum_as_string(a: usize, b: usize) -> PyResult { #[pymodule] fn synapse_rust(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; + Ok(()) } From e85eb719b7dd2fc7785aa9f674f9645b5da2f7cc Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 9 Sep 2022 10:05:57 +0100 Subject: [PATCH 6/8] Install the necessary components --- .github/workflows/tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c56244388f8d..3e466c9a0acf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -95,6 +95,7 @@ jobs: with: toolchain: 1.61.0 override: true + components: [clippy] - uses: Swatinem/rust-cache@v2 - run: cargo clippy @@ -112,6 +113,7 @@ jobs: with: toolchain: 1.61.0 override: true + components: [rustfmt] - uses: Swatinem/rust-cache@v2 - run: cargo fmt --check From 65b25bb0c58708011783c640deae74ee38409b8c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 9 Sep 2022 10:07:04 +0100 Subject: [PATCH 7/8] Fixup --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3e466c9a0acf..d07effcf3195 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -95,7 +95,7 @@ jobs: with: toolchain: 1.61.0 override: true - components: [clippy] + components: ["clippy"] - uses: Swatinem/rust-cache@v2 - run: cargo clippy @@ -113,7 +113,7 @@ jobs: with: toolchain: 1.61.0 override: true - components: [rustfmt] + components: ["rustfmt"] - uses: Swatinem/rust-cache@v2 - run: cargo fmt --check From 6fe51c0cda7ea60b1e0cc9c86f402c1c2ec60967 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 9 Sep 2022 10:07:58 +0100 Subject: [PATCH 8/8] Fixup --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d07effcf3195..7c4ae3d7ffd1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -95,7 +95,7 @@ jobs: with: toolchain: 1.61.0 override: true - components: ["clippy"] + components: clippy - uses: Swatinem/rust-cache@v2 - run: cargo clippy @@ -113,7 +113,7 @@ jobs: with: toolchain: 1.61.0 override: true - components: ["rustfmt"] + components: rustfmt - uses: Swatinem/rust-cache@v2 - run: cargo fmt --check