Merge pull request #175 from lafrenierejm/tighten-ci

Tighten CI by running in Nix
This commit is contained in:
phiresky 2023-07-04 21:48:10 +02:00 committed by GitHub
commit 1072fbf251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 103 deletions

View File

@ -1,69 +1,25 @@
# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md # Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md
# #
# While our "example" application has the platform-specific code, # While our "example" application has platform-specific code,
# for simplicity we are compiling and testing everything on the Ubuntu environment only. # for simplicity we are compiling and testing everything in a nix-on-Linux environment only.
# For multi-OS testing see the `cross.yml` workflow.
on: [push, pull_request] on: [push, pull_request]
name: ci name: ci
jobs: jobs:
check: nix-flake-check:
name: Check name: nix flake check
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout sources - 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
- 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 - name: Install nix
uses: cachix/install-nix-action@v18 uses: cachix/install-nix-action@v21
- name: Run tests - name: Ensure the build succeeds
run: nix develop --command cargo test run: nix build
lints: - name: Run `nix flake check` to run formatters, linters, and tests
name: Lints run: nix flake check --print-build-logs
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
components: rustfmt, clippy
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

View File

@ -3,11 +3,11 @@
"advisory-db": { "advisory-db": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1682282022, "lastModified": 1685821301,
"narHash": "sha256-qCMDFeWjANtpFKF0NEl6uVenfgruhSCnbnOMDO0WCzE=", "narHash": "sha256-4XRcnSboLJw1XKjDpg2jBU70jEw/8Bgx4nUmnq3kXbY=",
"owner": "rustsec", "owner": "rustsec",
"repo": "advisory-db", "repo": "advisory-db",
"rev": "5f4eca136204fb9e86d6297b20f149d225276824", "rev": "af3f3d503f82056785841bee49997bae65eba1c0",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -26,11 +26,11 @@
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
}, },
"locked": { "locked": {
"lastModified": 1681680516, "lastModified": 1684981077,
"narHash": "sha256-EB8Adaeg4zgcYDJn9sR6UMjN/OHdIiMMK19+3LmmXQY=", "narHash": "sha256-68X9cFm0RTZm8u0rXPbeBzOVUH5OoUGAfeHHVoxGd9o=",
"owner": "ipetkov", "owner": "ipetkov",
"repo": "crane", "repo": "crane",
"rev": "54b63c8eae4c50172cb50b612946ff1d2bc1c75c", "rev": "35110cccf28823320f4fd697fcafcb5038683982",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -72,12 +72,15 @@
} }
}, },
"flake-utils": { "flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": { "locked": {
"lastModified": 1678901627, "lastModified": 1681202837,
"narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", "rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -88,14 +91,14 @@
}, },
"flake-utils_2": { "flake-utils_2": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems_2"
}, },
"locked": { "locked": {
"lastModified": 1681202837, "lastModified": 1685518550,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401", "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -127,11 +130,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1681706826, "lastModified": 1685860998,
"narHash": "sha256-OGTMgnGBDE7XV0AnR83zFXxPpgEEe44mVebFRMe9P2g=", "narHash": "sha256-ZexAPe8yvJaLvn5aVgjW0vY41RnmJGbgOdGBJk1yDIE=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "016a65fde03180d0c6e817da11b9c7bc8316a0ab", "rev": "45d47b647d7bbaede5121d731cbee78f6093b6d6",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -169,11 +172,11 @@
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1681831107, "lastModified": 1685361114,
"narHash": "sha256-pXl3DPhhul9NztSetUJw2fcN+RI3sGOYgKu29xpgnqw=", "narHash": "sha256-4RjrlSb+OO+e1nzTExKW58o3WRwVGpXwj97iCta8aj4=",
"owner": "cachix", "owner": "cachix",
"repo": "pre-commit-hooks.nix", "repo": "pre-commit-hooks.nix",
"rev": "b7ca8f6fff42f6af75c17f9438fed1686b7d855d", "rev": "ca2fdbf3edda2a38140184da6381d49f8206eaf4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -204,11 +207,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1680488274, "lastModified": 1683080331,
"narHash": "sha256-0vYMrZDdokVmPQQXtFpnqA2wEgCCUXf5a3dDuDVshn0=", "narHash": "sha256-nGDvJ1DAxZIwdn6ww8IFwzoHb2rqBP4wv/65Wt5vflk=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "7ec2ff598a172c6e8584457167575b3a1a5d80d8", "rev": "d59c3fa0cba8336e115b376c2d9e91053aa59e56",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -227,11 +230,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1682216676, "lastModified": 1685846256,
"narHash": "sha256-nClm9zj7Tk/uJ3b61GWPG8dBKdvsrYz4y4Kgpz+SB9Y=", "narHash": "sha256-G4aYK4VqlMHImvZ0lUnLHw1A+Cx28T0sBMvAKZBcGpk=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "7e938508fee57a0c0603329f63ec0509c1ae9aad", "rev": "1ef3c6de6127a1cba94cc5492cdde52e33d06ea4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -254,6 +257,21 @@
"repo": "default", "repo": "default",
"type": "github" "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", "root": "root",

View File

@ -45,10 +45,8 @@
craneLib = crane.lib.${system}; craneLib = crane.lib.${system};
src = pkgs.lib.cleanSourceWith { src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.; # original, unfiltered source src = craneLib.path ./.;
filter = path: type: filter = pkgs.lib.cleanSourceFilter;
(builtins.match ".*jsonc$" path != null) # include JSONC files
|| (craneLib.filterCargoSources path type);
}; };
buildInputs = with pkgs; buildInputs = with pkgs;
@ -64,10 +62,7 @@
# Build the actual crate itself, reusing the dependency # Build the actual crate itself, reusing the dependency
# artifacts from above. # artifacts from above.
rga = craneLib.buildPackage { rga = craneLib.buildPackage { inherit cargoArtifacts src buildInputs; };
inherit cargoArtifacts src buildInputs;
doCheck = false;
};
pre-commit = pre-commit-hooks.lib."${system}".run; pre-commit = pre-commit-hooks.lib."${system}".run;
in { in {
@ -107,14 +102,13 @@
hooks = { hooks = {
nixfmt.enable = true; nixfmt.enable = true;
rustfmt.enable = true; rustfmt.enable = true;
cargo-check.enable = true; typos = {
enable = true;
types = [ "text" ];
excludes = [ "exampledir/.*" ];
};
}; };
}; };
} // 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 cargoArtifacts src; };
}; };
# `nix build` # `nix build`

View File

@ -54,7 +54,7 @@ struct FFprobeOutput {
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct FFprobeStream { struct FFprobeStream {
index: i32, // stream index index: i32, // stream index
} }
#[async_trait] #[async_trait]
@ -83,10 +83,14 @@ impl WritingFileAdapter for FFmpegAdapter {
let subtitle_streams = { let subtitle_streams = {
let probe = Command::new("ffprobe") let probe = Command::new("ffprobe")
.args(vec![ .args(vec![
"-v", "error", // show all errors "-v",
"-select_streams", "s", // show only subtitle streams "error", // show all errors
"-of", "json", // use json as output format "-select_streams",
"-show_entries", "stream=index", // show index of subtitle 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("-i")
.arg(&inp_fname) .arg(&inp_fname)
@ -134,16 +138,17 @@ impl WritingFileAdapter for FFmpegAdapter {
return Err(format_err!("ffprobe failed: {:?}", exit)); return Err(format_err!("ffprobe failed: {:?}", exit));
} }
} }
if subtitle_streams.len() > 0 { if !subtitle_streams.is_empty() {
for probe_stream in subtitle_streams.iter() { for probe_stream in subtitle_streams.iter() {
// extract subtitles // extract subtitles
let mut cmd = Command::new("ffmpeg"); let mut cmd = Command::new("ffmpeg");
cmd.arg("-hide_banner") cmd.arg("-hide_banner")
.arg("-loglevel").arg("panic") .arg("-loglevel")
.arg("panic")
.arg("-i") .arg("-i")
.arg(&inp_fname) .arg(&inp_fname)
.arg("-map") .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("-f")
.arg("webvtt") .arg("webvtt")
.arg("-"); .arg("-");

View File

@ -138,7 +138,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn simple() -> Result<()> { async fn simple() -> Result<()> {
let adapter: Box<dyn FileAdapter> = Box::new(SqliteAdapter::default()); let adapter: Box<dyn FileAdapter> = Box::<SqliteAdapter>::default();
let fname = test_data_dir().join("hello.sqlite3"); let fname = test_data_dir().join("hello.sqlite3");
let (a, d) = simple_fs_adapt_info(&fname).await?; let (a, d) = simple_fs_adapt_info(&fname).await?;
let res = adapter.adapt(a, &d).await?; let res = adapter.adapt(a, &d).await?;

View File

@ -181,7 +181,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn test_read_write() -> anyhow::Result<()> { async fn test_read_write() -> anyhow::Result<()> {
let path = tempfile::tempdir()?; 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(); // db.set();
Ok(()) Ok(())
} }