Repository: bearcove/loona (language: rust)

Issue:
Better h2spec tracking (CI etc.)
Here's what I'd like:

  * A single command to run `h2spec-server` + `h2spec`, along with a JUnit report
  * Something like https://github.com/marketplace/actions/junit-report-action that parses the JUnit report and comments on pull requests.s


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml
new file mode 100644
index 00000000..0880bac6
--- /dev/null
+++ b/.github/workflows/report.yml
@@ -0,0 +1,25 @@
+name: report
+
+on:
+  workflow_run:
+    workflows: [build]
+    types: [completed]
+    
+permissions:
+  checks: write
+
+jobs:
+  checks:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Download h2spec Report
+        uses: dawidd6/action-download-artifact@v2
+        with:
+          name: h2spec-results
+          workflow: ${{ github.event.workflow.id }}
+          run_id: ${{ github.event.workflow_run.id }}
+      - name: Publish h2spec Report
+        uses: mikepenz/action-junit-report@v3
+        with:
+          commit: ${{github.event.workflow_run.head_sha}}
+          report_paths: 'target/h2spec-junit'
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index fe3043a1..3168f01d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ target
 Cargo.lock
 *.lcov
 lcov.info
+junit.xml
diff --git a/Justfile b/Justfile
index 1f4b04da..ed0d7824 100644
--- a/Justfile
+++ b/Justfile
@@ -7,7 +7,9 @@ _default:
 ci-test:
 	#!/bin/bash -eux
 	just build-testbed
-	cargo llvm-cov nextest --lcov --output-path coverage.lcov
+	cargo llvm-cov --no-report nextest
+	cargo llvm-cov --no-report run --manifest-path h2spec-server/Cargo.toml -- -j 'target/junit.xml'
+	cargo llvm-cov report --lcov --output-path coverage.lcov
 	codecov
 
 cov:
@@ -28,13 +30,9 @@ single-test *args:
 bench *args:
 	RUST_BACKTRACE=1 cargo bench {{args}} -- --plotting-backend plotters
 
-h2spec-server:
-	cargo run --manifest-path h2spec-server/Cargo.toml
-
-h2spec:
+h2spec *args:
 	echo "This requires h2spec to be installed: https://github.com/summerwind/h2spec"
-	echo "...and the h2spec server to be running: just h2spec-server"
-	h2spec -p 8888 -o 1
+	cargo run --manifest-path h2spec-server/Cargo.toml -- {{args}}
 
 check:
 	cargo clippy --all-targets
diff --git a/h2spec-server/Cargo.toml b/h2spec-server/Cargo.toml
index 8f3eb712..0483a799 100644
--- a/h2spec-server/Cargo.toml
+++ b/h2spec-server/Cargo.toml
@@ -8,5 +8,6 @@ edition = "2021"
 [dependencies]
 color-eyre = "0.6.2"
 hring = { version = "0.1.0", path = ".." }
+tokio = { version = "1.23.0", features = ["full"] }
 tracing = "0.1.37"
 tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
diff --git a/h2spec-server/src/main.rs b/h2spec-server/src/main.rs
index 08ad2d69..eb3dded3 100644
--- a/h2spec-server/src/main.rs
+++ b/h2spec-server/src/main.rs
@@ -1,7 +1,7 @@
 #![allow(incomplete_features)]
 #![feature(async_fn_in_trait)]
 
-use std::{net::SocketAddr, rc::Rc};
+use std::{collections::VecDeque, net::SocketAddr, rc::Rc};
 
 use hring::{
     http::{StatusCode, Version},
@@ -9,6 +9,7 @@ use hring::{
     Body, BodyChunk, Encoder, ExpectResponseHeaders, Headers, Request, Responder, Response,
     ResponseDone, RollMut, ServerDriver,
 };
+use tokio::process::Command;
 use tracing_subscriber::EnvFilter;
 
 fn main() {
@@ -82,6 +83,28 @@ async fn real_main() -> color_eyre::Result<()> {
     let ln = TcpListener::bind(addr)?;
     tracing::info!("Listening on {}", ln.local_addr()?);
 
+    let _task = tokio_uring::spawn(async move { run_server(ln).await.unwrap() });
+
+    let mut args = std::env::args().skip(1).collect::<VecDeque<_>>();
+    if matches!(args.get(0).map(|s| s.as_str()), Some("--")) {
+        args.pop_front();
+    }
+    tracing::info!("Custom args: {args:?}");
+
+    Command::new("h2spec")
+        .arg("-p")
+        .arg("8888")
+        .arg("-o")
+        .arg("1")
+        .args(&args)
+        .spawn()?
+        .wait()
+        .await?;
+
+    Ok(())
+}
+
+async fn run_server(ln: TcpListener) -> color_eyre::Result<()> {
     loop {
         let (stream, addr) = ln.accept().await?;
         tracing::info!(%addr, "Accepted connection from");
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index bd3df37b..ba332a85 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -1,2 +1,3 @@
 [toolchain]
-channel = "nightly-2023-01-02"
\ No newline at end of file
+channel = "nightly-2023-01-02"
+components = ["llvm-tools-preview"]
\ No newline at end of file


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 4a738fd0..e1b31349 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -18,10 +18,20 @@ jobs:
         uses: actions/checkout@v3
         with:
           fetch-depth: 2
-      - name: Run tests
+      - name: Run unit tests and h2spec
         run: |
           cd ${{ github.workspace }}
           sccache --zero-stats
           cargo clippy
+          mkdir tools
+          export PATH=$PATH:${PWD}/tools
+          (pushd tools && curl -L https://github.com/summerwind/h2spec/releases/download/v2.6.0/h2spec_linux_amd64.tar.gz | tar -xz && popd)
           just ci-test
-          sccache --show-stats
\ No newline at end of file
+          sccache --show-stats
+      - name: Upload h2spec Report
+        uses: actions/upload-artifact@v3
+        if: always() # always run even if the previous step fails
+        with:
+          name: h2spec-results
+          path: 'target/h2spec-junit.xml'
+          retention-days: 30