From 0375facc29aaffb55f2c2c4b29eba8dddf5841cd Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Sat, 1 Jul 2023 19:41:59 -0500 Subject: [PATCH 1/9] Add `typos` pre-commit hook --- flake.lock | 62 +++++++++++++++++++++++++++++++++++------------------- flake.nix | 5 +++++ 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/flake.lock b/flake.lock index 7791387..92d7249 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "advisory-db": { "flake": false, "locked": { - "lastModified": 1682282022, - "narHash": "sha256-qCMDFeWjANtpFKF0NEl6uVenfgruhSCnbnOMDO0WCzE=", + "lastModified": 1684873045, + "narHash": "sha256-MVXbXNXcqiaeJZbwVw6R16xqxJkpm+ipAIljz4/9QaM=", "owner": "rustsec", "repo": "advisory-db", - "rev": "5f4eca136204fb9e86d6297b20f149d225276824", + "rev": "e162556b9e8c1542c187290453cbd322e8905f0c", "type": "github" }, "original": { @@ -26,11 +26,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1681680516, - "narHash": "sha256-EB8Adaeg4zgcYDJn9sR6UMjN/OHdIiMMK19+3LmmXQY=", + "lastModified": 1684981077, + "narHash": "sha256-68X9cFm0RTZm8u0rXPbeBzOVUH5OoUGAfeHHVoxGd9o=", "owner": "ipetkov", "repo": "crane", - "rev": "54b63c8eae4c50172cb50b612946ff1d2bc1c75c", + "rev": "35110cccf28823320f4fd697fcafcb5038683982", "type": "github" }, "original": { @@ -72,12 +72,15 @@ } }, "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1678901627, - "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", "owner": "numtide", "repo": "flake-utils", - "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", "type": "github" }, "original": { @@ -88,7 +91,7 @@ }, "flake-utils_2": { "inputs": { - "systems": "systems" + "systems": "systems_2" }, "locked": { "lastModified": 1681202837, @@ -127,11 +130,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1681706826, - "narHash": "sha256-OGTMgnGBDE7XV0AnR83zFXxPpgEEe44mVebFRMe9P2g=", + "lastModified": 1685249274, + "narHash": "sha256-oqo9yIloFeeeef3tRpxCQwE4ZZKRU055Zv30otw+IoE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "016a65fde03180d0c6e817da11b9c7bc8316a0ab", + "rev": "41bb263d28f1a3a3c4dbc6ce21d462cebd94ac71", "type": "github" }, "original": { @@ -169,11 +172,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1681831107, - "narHash": "sha256-pXl3DPhhul9NztSetUJw2fcN+RI3sGOYgKu29xpgnqw=", + "lastModified": 1684842236, + "narHash": "sha256-rYWsIXHvNhVQ15RQlBUv67W3YnM+Pd+DuXGMvCBq2IE=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "b7ca8f6fff42f6af75c17f9438fed1686b7d855d", + "rev": "61e567d6497bc9556f391faebe5e410e6623217f", "type": "github" }, "original": { @@ -204,11 +207,11 @@ ] }, "locked": { - "lastModified": 1680488274, - "narHash": "sha256-0vYMrZDdokVmPQQXtFpnqA2wEgCCUXf5a3dDuDVshn0=", + "lastModified": 1683080331, + "narHash": "sha256-nGDvJ1DAxZIwdn6ww8IFwzoHb2rqBP4wv/65Wt5vflk=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "7ec2ff598a172c6e8584457167575b3a1a5d80d8", + "rev": "d59c3fa0cba8336e115b376c2d9e91053aa59e56", "type": "github" }, "original": { @@ -227,11 +230,11 @@ ] }, "locked": { - "lastModified": 1682216676, - "narHash": "sha256-nClm9zj7Tk/uJ3b61GWPG8dBKdvsrYz4y4Kgpz+SB9Y=", + "lastModified": 1685240871, + "narHash": "sha256-bOCbP0lWTjhmrPcdyuFD/yx/38CKkzC2TNXmBzZSLJA=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "7e938508fee57a0c0603329f63ec0509c1ae9aad", + "rev": "aa1b08de9ca770534ad750dccc70cebd95c15e26", "type": "github" }, "original": { @@ -254,6 +257,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 70b41e2..b8fab2d 100644 --- a/flake.nix +++ b/flake.nix @@ -108,6 +108,11 @@ nixfmt.enable = true; rustfmt.enable = true; cargo-check.enable = true; + typos = { + enable = true; + types = [ "text" ]; + excludes = [ "exampledir/.*" ]; + }; }; }; } // pkgs.lib.optionalAttrs (system == "x86_64-linux") { From 01b363d7c06bb34e16efe7a4ff54e570db308af8 Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Sat, 1 Jul 2023 19:42:12 -0500 Subject: [PATCH 2/9] Remove `cargo-check` pre-commit hook --- flake.nix | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index b8fab2d..80ea1a4 100644 --- a/flake.nix +++ b/flake.nix @@ -64,10 +64,7 @@ # Build the actual crate itself, reusing the dependency # artifacts from above. - rga = craneLib.buildPackage { - inherit cargoArtifacts src buildInputs; - doCheck = false; - }; + rga = craneLib.buildPackage { inherit cargoArtifacts src buildInputs; }; pre-commit = pre-commit-hooks.lib."${system}".run; in { @@ -107,7 +104,6 @@ hooks = { nixfmt.enable = true; rustfmt.enable = true; - cargo-check.enable = true; typos = { enable = true; types = [ "text" ]; From de8e51884e90bbc4fb0a67aa877a7c75ba602cec Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Sun, 4 Jun 2023 00:47:39 -0500 Subject: [PATCH 3/9] Run linting, formatting, and tests in CI using Nix --- .github/workflows/ci.yml | 64 +++++++--------------------------------- 1 file changed, 10 insertions(+), 54 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 154f3b2..594b73d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,69 +1,25 @@ # Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md # -# While our "example" application has the platform-specific code, -# for simplicity we are compiling and testing everything on the Ubuntu environment only. -# For multi-OS testing see the `cross.yml` workflow. +# While our "example" application has platform-specific code, +# for simplicity we are compiling and testing everything in a nix-on-Linux environment only. on: [push, pull_request] name: ci jobs: - check: - name: Check - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Run cargo check - uses: actions-rs/cargo@v1 - with: - command: check - - test: - name: Test Suite - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install nix - uses: cachix/install-nix-action@v18 - - - name: Run tests - run: nix develop --command cargo test - - lints: + nix-flake-check: name: Lints runs-on: ubuntu-latest steps: - name: Checkout sources - uses: actions/checkout@v2 + uses: actions/checkout@v3 - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt, clippy + - name: Install nix + uses: cachix/install-nix-action@v21 - - name: Run cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - name: Ensure the build succeeds + run: nix build - - name: Run cargo clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings + - name: Run `nix flake check` to run formatters, linters, and tests + run: nix flake check --print-build-logs From fdd4efe12ef779d533a7d2da263232fc603b405c Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Sun, 4 Jun 2023 01:50:41 -0500 Subject: [PATCH 4/9] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'advisory-db': 'github:rustsec/advisory-db/e162556b9e8c1542c187290453cbd322e8905f0c' (2023-05-23) → 'github:rustsec/advisory-db/af3f3d503f82056785841bee49997bae65eba1c0' (2023-06-03) • Updated input 'flake-utils': 'github:numtide/flake-utils/cfacdce06f30d2b68473a46042957675eebb3401' (2023-04-11) → 'github:numtide/flake-utils/a1720a10a6cfe8234c0e93907ffe81be440f4cef' (2023-05-31) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/41bb263d28f1a3a3c4dbc6ce21d462cebd94ac71' (2023-05-28) → 'github:NixOS/nixpkgs/45d47b647d7bbaede5121d731cbee78f6093b6d6' (2023-06-04) • Updated input 'pre-commit-hooks': 'github:cachix/pre-commit-hooks.nix/61e567d6497bc9556f391faebe5e410e6623217f' (2023-05-23) → 'github:cachix/pre-commit-hooks.nix/ca2fdbf3edda2a38140184da6381d49f8206eaf4' (2023-05-29) • Updated input 'rust-overlay': 'github:oxalica/rust-overlay/aa1b08de9ca770534ad750dccc70cebd95c15e26' (2023-05-28) → 'github:oxalica/rust-overlay/1ef3c6de6127a1cba94cc5492cdde52e33d06ea4' (2023-06-04) --- flake.lock | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/flake.lock b/flake.lock index 92d7249..5df8a58 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "advisory-db": { "flake": false, "locked": { - "lastModified": 1684873045, - "narHash": "sha256-MVXbXNXcqiaeJZbwVw6R16xqxJkpm+ipAIljz4/9QaM=", + "lastModified": 1685821301, + "narHash": "sha256-4XRcnSboLJw1XKjDpg2jBU70jEw/8Bgx4nUmnq3kXbY=", "owner": "rustsec", "repo": "advisory-db", - "rev": "e162556b9e8c1542c187290453cbd322e8905f0c", + "rev": "af3f3d503f82056785841bee49997bae65eba1c0", "type": "github" }, "original": { @@ -94,11 +94,11 @@ "systems": "systems_2" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", "type": "github" }, "original": { @@ -130,11 +130,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1685249274, - "narHash": "sha256-oqo9yIloFeeeef3tRpxCQwE4ZZKRU055Zv30otw+IoE=", + "lastModified": 1685860998, + "narHash": "sha256-ZexAPe8yvJaLvn5aVgjW0vY41RnmJGbgOdGBJk1yDIE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "41bb263d28f1a3a3c4dbc6ce21d462cebd94ac71", + "rev": "45d47b647d7bbaede5121d731cbee78f6093b6d6", "type": "github" }, "original": { @@ -172,11 +172,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1684842236, - "narHash": "sha256-rYWsIXHvNhVQ15RQlBUv67W3YnM+Pd+DuXGMvCBq2IE=", + "lastModified": 1685361114, + "narHash": "sha256-4RjrlSb+OO+e1nzTExKW58o3WRwVGpXwj97iCta8aj4=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "61e567d6497bc9556f391faebe5e410e6623217f", + "rev": "ca2fdbf3edda2a38140184da6381d49f8206eaf4", "type": "github" }, "original": { @@ -230,11 +230,11 @@ ] }, "locked": { - "lastModified": 1685240871, - "narHash": "sha256-bOCbP0lWTjhmrPcdyuFD/yx/38CKkzC2TNXmBzZSLJA=", + "lastModified": 1685846256, + "narHash": "sha256-G4aYK4VqlMHImvZ0lUnLHw1A+Cx28T0sBMvAKZBcGpk=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "aa1b08de9ca770534ad750dccc70cebd95c15e26", + "rev": "1ef3c6de6127a1cba94cc5492cdde52e33d06ea4", "type": "github" }, "original": { From ab500733aa1e9c272e1c3b1220e2cd2e59927ab3 Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Mon, 19 Jun 2023 22:25:57 -0500 Subject: [PATCH 5/9] Run clippy --- src/adapters/ffmpeg.rs | 4 ++-- src/adapters/sqlite.rs | 2 +- src/preproc_cache.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/adapters/ffmpeg.rs b/src/adapters/ffmpeg.rs index b18b666..2ed3612 100644 --- a/src/adapters/ffmpeg.rs +++ b/src/adapters/ffmpeg.rs @@ -134,7 +134,7 @@ impl WritingFileAdapter for FFmpegAdapter { return Err(format_err!("ffprobe failed: {:?}", exit)); } } - if subtitle_streams.len() > 0 { + if !subtitle_streams.is_empty() { for probe_stream in subtitle_streams.iter() { // extract subtitles let mut cmd = Command::new("ffmpeg"); @@ -143,7 +143,7 @@ impl WritingFileAdapter for FFmpegAdapter { .arg("-i") .arg(&inp_fname) .arg("-map") - .arg(format!("0:{}", probe_stream.index.to_string())) // 0 for first input + .arg(format!("0:{}", probe_stream.index)) // 0 for first input .arg("-f") .arg("webvtt") .arg("-"); diff --git a/src/adapters/sqlite.rs b/src/adapters/sqlite.rs index 826d091..dba24a4 100644 --- a/src/adapters/sqlite.rs +++ b/src/adapters/sqlite.rs @@ -138,7 +138,7 @@ mod test { #[tokio::test] async fn simple() -> Result<()> { - let adapter: Box = Box::new(SqliteAdapter::default()); + let adapter: Box = Box::::default(); let fname = test_data_dir().join("hello.sqlite3"); let (a, d) = simple_fs_adapt_info(&fname).await?; let res = adapter.adapt(a, &d).await?; diff --git a/src/preproc_cache.rs b/src/preproc_cache.rs index f361792..d0eed0e 100644 --- a/src/preproc_cache.rs +++ b/src/preproc_cache.rs @@ -181,7 +181,7 @@ mod test { #[tokio::test] async fn test_read_write() -> anyhow::Result<()> { let path = tempfile::tempdir()?; - let db = open_cache_db(&path.path().join("foo.sqlite3")).await?; + let _db = open_cache_db(&path.path().join("foo.sqlite3")).await?; // db.set(); Ok(()) } From ec19d0d595d9a228be31bc2cdf6d72ac462f028d Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Sat, 1 Jul 2023 19:29:49 -0500 Subject: [PATCH 6/9] Run `cargo fmt` --- src/adapters/ffmpeg.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/adapters/ffmpeg.rs b/src/adapters/ffmpeg.rs index 2ed3612..32298fe 100644 --- a/src/adapters/ffmpeg.rs +++ b/src/adapters/ffmpeg.rs @@ -54,7 +54,7 @@ struct FFprobeOutput { } #[derive(Serialize, Deserialize)] struct FFprobeStream { - index: i32, // stream index + index: i32, // stream index } #[async_trait] @@ -83,10 +83,14 @@ impl WritingFileAdapter for FFmpegAdapter { let subtitle_streams = { let probe = Command::new("ffprobe") .args(vec![ - "-v", "error", // show all errors - "-select_streams", "s", // show only subtitle streams - "-of", "json", // use json as output format - "-show_entries", "stream=index", // show index of subtitle streams + "-v", + "error", // show all errors + "-select_streams", + "s", // show only subtitle streams + "-of", + "json", // use json as output format + "-show_entries", + "stream=index", // show index of subtitle streams ]) .arg("-i") .arg(&inp_fname) @@ -139,7 +143,8 @@ impl WritingFileAdapter for FFmpegAdapter { // extract subtitles let mut cmd = Command::new("ffmpeg"); cmd.arg("-hide_banner") - .arg("-loglevel").arg("panic") + .arg("-loglevel") + .arg("panic") .arg("-i") .arg(&inp_fname) .arg("-map") From ff0b92300af4cef98c05da4d7c154f67eb86e9e2 Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Sat, 1 Jul 2023 19:31:03 -0500 Subject: [PATCH 7/9] Reuse Nix-built Cargo deps throughout flake --- flake.nix | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 80ea1a4..06b2e3d 100644 --- a/flake.nix +++ b/flake.nix @@ -45,10 +45,8 @@ craneLib = crane.lib.${system}; src = pkgs.lib.cleanSourceWith { - src = craneLib.path ./.; # original, unfiltered source - filter = path: type: - (builtins.match ".*jsonc$" path != null) # include JSONC files - || (craneLib.filterCargoSources path type); + src = craneLib.path ./.; + filter = pkgs.lib.cleanSourceFilter; }; buildInputs = with pkgs; @@ -115,7 +113,7 @@ # NB: cargo-tarpaulin only supports x86_64 systems # Check code coverage (note: this will not upload coverage anywhere) rga-coverage = - craneLib.cargoTarpaulin { inherit cargoArtifacts src; }; + craneLib.cargoTarpaulin { inherit buildInputs cargoArtifacts src; }; }; # `nix build` From b609b06724302bffd34a885a41bd5177e72ecafa Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Sun, 2 Jul 2023 18:46:08 -0500 Subject: [PATCH 8/9] Remove `cargo tarpaulin` from Nix checks `cargo tarpaulin` times out when run in GitHub Actions. --- flake.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/flake.nix b/flake.nix index 06b2e3d..088c00c 100644 --- a/flake.nix +++ b/flake.nix @@ -109,11 +109,6 @@ }; }; }; - } // pkgs.lib.optionalAttrs (system == "x86_64-linux") { - # NB: cargo-tarpaulin only supports x86_64 systems - # Check code coverage (note: this will not upload coverage anywhere) - rga-coverage = - craneLib.cargoTarpaulin { inherit buildInputs cargoArtifacts src; }; }; # `nix build` From cf561d7fa3e805ae77a73b98ca44cc5913fb4384 Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Mon, 3 Jul 2023 11:58:20 -0500 Subject: [PATCH 9/9] Rename CI job --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 594b73d..07f646f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ name: ci jobs: nix-flake-check: - name: Lints + name: nix flake check runs-on: ubuntu-latest steps: - name: Checkout sources