Skip to content

Commit

Permalink
ci(flake): Update flake for ci and workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
DaRacci committed Sep 29, 2023
1 parent 2c34645 commit 6d5351a
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 104 deletions.
64 changes: 12 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,27 @@ on:
paths: [ "**/src/**", '.github/workflows/ci.yml' ]

jobs:
fmt-clippy:
flake-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@v2

- name: Setup Rust Toolchain and Cache
uses: actions-rust-lang/[email protected]
with:
toolchain: nightly
components: rustfmt, clippy

- name: Cargo fmt
run: |
cargo fmt --all -- --check
- name: Cargo clippy
run: |
cargo clippy --workspace -- -D warnings
- run: nix flake check

tests:
build-artifacts:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@v2

- name: Setup Rust Toolchain and Cache
uses: actions-rust-lang/[email protected]
with:
toolchain: nightly

- name: Run tests
run: |
cargo test --workspace --profile ci
artifact:
strategy:
matrix:
build: [ linux, windows ]
include:
- target: windows
os: windows-latest
extra: '.exe'
- target: linux
os: ubuntu-latest

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3

- name: Setup Rust Toolchain and Cache
uses: actions-rust-lang/[email protected]
with:
toolchain: nightly

- name: Run
run: |
cargo build --workspace --release
- run: nix build

- uses: actions/[email protected]
if: ${{ !github.event.act }}
with:
name: tools-${{ matrix.os }}
path: target/release/backup${{ matrix.extra }}
name: tools
path: result/bin/
if-no-files-found: error
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ default-members = [
"crates/cleaner",
"crates/country-ip",
"crates/memorable-pass",
"crates/rebooter"
]
resolver = "2"

Expand Down
4 changes: 4 additions & 0 deletions crates/backup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ edition = "2021"
categories = ["command-line-utilities", "system", "utilities", "cli"]
keywords = ["backup"]

[[bin]]
name = "backup"
path = "src/main.rs"

[features]
default = ["ui-cli", "sources-s3", "sources-bitwarden", "sources-1password"]
binary-downloader = ["bytes", "rand", "const_format"]
Expand Down
4 changes: 4 additions & 0 deletions crates/cleaner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ categories = ["command-line-utilities", "system", "utilities", "cli"]
keywords = ["cleaner", "clean", "cleaning", "cleaning-tool", "cleaning-utility"]
description = "A cleaning tool written in Rust"

[[bin]]
name = "cleaner"
path = "src/main.rs"

[dependencies]
lib = { path = "../lib" }
macros = { path = "../macros" }
Expand Down
3 changes: 3 additions & 0 deletions crates/interfacer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "interfacer"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "interfacer"
path = "src/main.rs"

[features]
default = ["ui-cli"]
Expand Down
24 changes: 12 additions & 12 deletions crates/memorable-pass/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["generator", "password", "memorable"]
description = "A memorable password generator written in Rust"

[[bin]]
name = "memorable"
name = "memorable-pass"
path = "src/main.rs"

[features]
Expand Down Expand Up @@ -53,14 +53,14 @@ tracing-subscriber = { workspace = true, default-features = false, features = ["
regex = "1.9.5"

[build-dependencies]
reqwest = { workspace = true, features = ["blocking","stream"] }
zip = { workspace = true }

csv = "1.2.2"
bytes = "1.5.0"
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }

anyhow = { workspace = true }
tracing = { workspace = true }
thiserror = { workspace = true }
#reqwest = { workspace = true, features = ["blocking","stream"] }
#zip = { workspace = true }
#
#csv = "1.2.2"
#bytes = "1.5.0"
#serde = { workspace = true, features = ["derive"] }
#serde_json = { workspace = true }
#
#anyhow = { workspace = true }
#tracing = { workspace = true }
#thiserror = { workspace = true }
7 changes: 2 additions & 5 deletions crates/memorable-pass/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use anyhow::Result;
// use anyhow::Result;

// #[derive(Debug, Serialize, Deserialize)]
// struct WordData {
Expand Down Expand Up @@ -68,7 +68,7 @@ use anyhow::Result;
// Ok(words)
// }

fn main() -> Result<()> {
fn main() {}
// let bad_words = get_bad_words()?;
// let words = extract_words(download_extract_zip(
// "https://www.cs.cmu.edu/~enron/enron_mail_20150507.tar.gz",
Expand All @@ -92,6 +92,3 @@ fn main() -> Result<()> {
// let json_data = serde_json::to_vec(&length_map)?;
// let mut json_file = File::create("word_data.json")?;
// json_file.write_all(&*json_data)?;

Ok(())
}
23 changes: 12 additions & 11 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,27 @@ let
cargoExtraArgs = if workspace != null then "--package ${workspace}" else "";

strictDeps = true;
doCheck = false; # Checks are done with flake
};

cargoArtifact = craneLib.buildDepsOnly commonArgs;

cargoBuild = artifact: extra: craneLib.buildPackage (commonArgs // {
cargoArtifact = artifact;
} // extra commonArgs);
cargoArtifacts = artifact;
} // (if extra != null then extra commonArgs else { }));

cargoClippy = artifact: extra: craneLib.cargoClippy (commonArgs // {
cargoArtifact = artifact;
cargoArtifacts = artifact;
cargoClippyExtraArgs = "--package ${workspace} -- --deny warnings";
} // extra commonArgs);
} // (if extra != null then extra commonArgs else { }));

cargoFmt = artifact: extra: craneLib.cargoFmt (commonArgs // {
cargoArtifact = artifact;
} // extra commonArgs);
cargoArtifacts = artifact;
} // (if extra != null then extra commonArgs else { }));

cargoTest = artifact: extra: craneLib.cargoNextest (commonArgs // {
cargoArtifact = artifact;
} // extra commonArgs);
cargoArtifacts = artifact;
} // (if extra != null then extra commonArgs else { }));
in
{
passthru = commonDeps // commonEnv // {
Expand All @@ -152,9 +153,9 @@ in
cargoExtraArgs = "--lib";
});

crateTest = cargoTest cargoArtifact;
crateTest = cargoTest cargoArtifact null;

crateClippy = cargoClippy cargoArtifact;
crateClippy = cargoClippy cargoArtifact null;

crateFmt = cargoFmt cargoArtifact;
crateFmt = cargoFmt cargoArtifact null;
}
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 23 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
fenix = { url = "github:nix-community/fenix"; inputs.nixpkgs.follows = "nixpkgs"; };
};

outputs = { nixpkgs, flake-utils, crane, fenix, ... }:
outputs = { nixpkgs, flake-utils, crane, fenix, ... }@inputs:
let
# TODO - Darwin support (error: don't yet have a `targetPackages.darwin.LibsystemCross for x86_64-apple-darwin`)
targets = [ "x86_64-linux" ] ++ [ "x86_64-windows" ];
Expand Down Expand Up @@ -50,7 +50,7 @@
in
{
packages = builtins.mapAttrs (name: outputs: outputs.crateBinary) cargoOutputs // {
all = pkgs.symlinkJoin {
default = pkgs.symlinkJoin {
name = "all";
paths = builtins.attrValues (builtins.mapAttrs (name: outputs: outputs.crateBinary) cargoOutputs);
};
Expand All @@ -60,15 +60,26 @@
default = pkgs.callPackage ./shell.nix { inherit localSystem flake-utils crane fenix; };
};

checks = builtins.foldl'
(attr: packageChecks: (attr // packageChecks))
{ }
(builtins.attrValues (builtins.mapAttrs
(name: crateOutput: {
"${name}-fmt" = crateOutput.crateFmt;
"${name}-clippy" = crateOutput.crateClippy;
"${name}-test" = crateOutput.crateTest;
})
cargoOutputs));
checks =
let
nativeOutputs = builtins.filter (o: o.isNative) (builtins.attrValues (builtins.mapAttrs
(name: output: {
inherit name;
inherit (output.passthru) isNative;

inherit (output) crateFmt crateClippy crateTest;
})
cargoOutputs));
in
builtins.foldl'
(attr: packageChecks: (attr // packageChecks))
{ }
(builtins.map
(crate: {
"${crate.name}-formatting" = crate.crateFmt;
"${crate.name}-clippy" = crate.crateClippy;
"${crate.name}-test" = crate.crateTest;
})
nativeOutputs);
});
}
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ in
nativeBuildInputs = with pkgs; [
cocogitto
act
hyperfine
(fenixPkgs.complete.withComponents [
"cargo"
"rust-src"
Expand Down

0 comments on commit 6d5351a

Please sign in to comment.