Skip to content

Commit 93b50d5

Browse files
committed
ci: add Nix CI shell and PR nightly checks
1 parent 90145d1 commit 93b50d5

6 files changed

Lines changed: 191 additions & 78 deletions

File tree

.github/workflows/ci-nightly.yml

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: CI (nightly)
22

33
on:
4+
# Temporary: validate nightly CI on pull requests during the Nix migration.
5+
pull_request:
6+
types: [opened, synchronize, reopened]
47
schedule: [cron: "40 1 * * *"]
58
workflow_dispatch:
69

@@ -27,49 +30,30 @@ jobs:
2730
with:
2831
toolchain: ${{ matrix.version }}
2932

30-
- name: Install system packages
31-
run: |
32-
sudo apt-get update
33-
sudo apt-get -y install sqlite3
34-
sudo apt-get -y install libpq-dev
35-
sudo apt-get -y install redis-server
33+
- name: Install Nix
34+
uses: nixbuild/nix-quick-install-action@9f63be77f412a248c9d9a65a4c82cf066cdf8f0c # v35
3635

37-
- name: Install DB CLI tools
38-
run: |
39-
cargo install --force sqlx-cli --no-default-features --features=sqlite,rustls
40-
cargo install --force diesel_cli --no-default-features --features=sqlite,postgres
36+
- name: Enter Nix devshell
37+
uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
38+
with:
39+
arguments: .#ci
4140

4241
- name: Create Test DBs
43-
env:
44-
DATABASE_URL: sqlite://./todo.db
45-
run: |
46-
sqlx database create
47-
chmod a+rwx ./todo.db
48-
sqlx migrate run --source=./basics/todo/migrations
42+
run: just init-db
4943

5044
- name: Start Redis
51-
run: |
52-
if ! redis-cli ping; then
53-
redis-server --daemonize yes
54-
fi
55-
redis-cli ping
45+
run: just start-redis
5646

5747
- name: cargo check
58-
run: cargo check --workspace --bins --examples --tests
48+
run: just cargo-check
5949
timeout-minutes: 30
6050

6151
- name: cargo test
62-
run: cargo test --workspace --all-features --no-fail-fast --exclude=db-diesel -- --nocapture
52+
run: just test
6353
timeout-minutes: 30
6454

6555
- name: cargo test (diesel)
66-
env:
67-
DATABASE_URL: test.db
68-
run: |
69-
cd databases/diesel
70-
diesel migration run
71-
chmod a+rwx test.db
72-
cargo test -p=db-diesel --no-fail-fast -- --nocapture
56+
run: just test-diesel
7357
timeout-minutes: 10
7458

7559
- name: Install cargo-ci-cache-clean
@@ -78,4 +62,4 @@ jobs:
7862
tool: cargo-ci-cache-clean
7963

8064
- name: CI cache clean
81-
run: cargo-ci-cache-clean
65+
run: just ci-cache-clean

.github/workflows/ci.yml

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,30 @@ jobs:
3131
with:
3232
toolchain: ${{ matrix.version }}
3333

34-
- name: Install system packages
35-
run: |
36-
sudo apt-get update
37-
sudo apt-get -y install sqlite3
38-
sudo apt-get -y install libpq-dev
39-
sudo apt-get -y install redis-server
34+
- name: Install Nix
35+
uses: nixbuild/nix-quick-install-action@9f63be77f412a248c9d9a65a4c82cf066cdf8f0c # v35
4036

41-
- name: Install DB CLI tools
42-
run: |
43-
cargo install --force sqlx-cli --no-default-features --features=sqlite,rustls
44-
cargo install --force diesel_cli --no-default-features --features=sqlite,postgres
37+
- name: Enter Nix devshell
38+
uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
39+
with:
40+
arguments: .#ci
4541

4642
- name: Create Test DBs
47-
env:
48-
DATABASE_URL: sqlite://./todo.db
49-
run: |
50-
sqlx database create
51-
chmod a+rwx ./todo.db
52-
sqlx migrate run --source=./basics/todo/migrations
43+
run: just init-db
5344

5445
- name: Start Redis
55-
run: |
56-
if ! redis-cli ping; then
57-
redis-server --daemonize yes
58-
fi
59-
redis-cli ping
46+
run: just start-redis
6047

6148
- name: cargo check
62-
run: cargo check --workspace --bins --examples --tests
49+
run: just cargo-check
6350
timeout-minutes: 30
6451

6552
- name: cargo test
66-
run: cargo test --workspace --all-features --no-fail-fast --exclude=db-diesel -- --nocapture
53+
run: just test
6754
timeout-minutes: 30
6855

6956
- name: cargo test (diesel)
70-
env:
71-
DATABASE_URL: test.db
72-
run: |
73-
cd databases/diesel
74-
diesel migration run
75-
chmod a+rwx test.db
76-
cargo test -p=db-diesel --no-fail-fast -- --nocapture
57+
run: just test-diesel
7758
timeout-minutes: 10
7859

7960
- name: Install cargo-ci-cache-clean
@@ -82,4 +63,4 @@ jobs:
8263
tool: cargo-ci-cache-clean
8364

8465
- name: CI cache clean
85-
run: cargo-ci-cache-clean
66+
run: just ci-cache-clean

.github/workflows/clippy-fmt.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,22 @@ jobs:
3434
with:
3535
persist-credentials: false
3636

37-
- name: Install Rust
37+
- name: Install Rust (stable)
3838
uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0
3939
with:
4040
toolchain: stable
4141
components: rustfmt
4242

43+
- name: Install Nix
44+
uses: nixbuild/nix-quick-install-action@9f63be77f412a248c9d9a65a4c82cf066cdf8f0c # v35
45+
46+
- name: Enter Nix devshell
47+
uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
48+
with:
49+
arguments: .#ci
50+
4351
- name: rustfmt
44-
uses: actions-rust-lang/rustfmt@4066006ec54a31931b9b1fddfd38f2fdf2d27143 # v1.1.2
52+
run: just fmt-check
4553

4654
clippy:
4755
name: clippy check
@@ -58,12 +66,20 @@ jobs:
5866
with:
5967
persist-credentials: false
6068

61-
- name: Install Rust
69+
- name: Install Rust (stable)
6270
uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0
6371
with:
6472
toolchain: stable
6573
components: clippy
6674

75+
- name: Install Nix
76+
uses: nixbuild/nix-quick-install-action@9f63be77f412a248c9d9a65a4c82cf066cdf8f0c # v35
77+
78+
- name: Enter Nix devshell
79+
uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
80+
with:
81+
arguments: .#ci
82+
6783
- name: clippy
6884
timeout-minutes: 30
69-
run: cargo clippy --workspace --all-features --tests -- -D warnings
85+
run: just clippy-ci

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
> Curated examples using the Actix ecosystem.
44
5+
## Development
6+
7+
Enter the full local development shell with `nix develop`. It provides native libraries, database tools, and project tooling used by the examples. Rust must be available in the host environment.
8+
9+
The lighter CI shell is available with `nix develop .#ci`. It provides the database and service packages used by CI, without the extra local development tooling. CI selects its Rust toolchain separately.
10+
11+
Initialize the SQLite databases used by the examples with `just init-db` from the repository root. The same operation is also available as `nix run .#init-db` for use outside a development shell.
12+
13+
Run the local CI build and test sequence with `just ci` inside the default development shell.
14+
515
<!-- prettier-ignore-start -->
616

717
[![CI status](https://github.com/actix/examples/actions/workflows/ci.yml/badge.svg)](https://github.com/actix/examples/actions)

flake.nix

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,89 @@
77
outputs = inputs@{ flake-parts, ... }:
88
flake-parts.lib.mkFlake { inherit inputs; } {
99
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
10-
perSystem = { pkgs, config, inputs', system, lib, ... }: {
11-
formatter = pkgs.nixpkgs-fmt;
12-
13-
devShells.default = pkgs.mkShell {
14-
packages = [
15-
config.formatter
16-
pkgs.nodePackages.prettier
17-
pkgs.taplo
18-
pkgs.just
19-
] ++ lib.optional pkgs.stdenv.isDarwin [
20-
pkgs.pkgsBuildHost.libiconv
10+
perSystem = { pkgs, config, lib, ... }:
11+
let
12+
runtimeLibraryPath = lib.makeLibraryPath [
13+
pkgs.openssl
14+
pkgs.sqlite
15+
pkgs.libpq
16+
pkgs.zlib
2117
];
18+
19+
rustRuntimeShellHook = lib.optionalString pkgs.stdenv.isLinux ''
20+
export RUSTFLAGS="''${RUSTFLAGS:-} -C link-arg=-Wl,-rpath,${runtimeLibraryPath}"
21+
'';
22+
23+
initDb = pkgs.writeShellApplication {
24+
name = "init-db";
25+
runtimeInputs = [
26+
pkgs.coreutils
27+
pkgs.sqlx-cli
28+
pkgs.diesel-cli
29+
];
30+
text = ''
31+
set -euo pipefail
32+
33+
if [ ! -d "$PWD/basics/todo/migrations" ] || [ ! -d "$PWD/databases/diesel/migrations" ]; then
34+
echo "init-db must be run from the repository root" >&2
35+
exit 1
36+
fi
37+
38+
DATABASE_URL="sqlite://./todo.db" sqlx database create
39+
chmod a+rwx ./todo.db
40+
DATABASE_URL="sqlite://./todo.db" sqlx migrate run --source=./basics/todo/migrations
41+
42+
(
43+
cd databases/diesel
44+
DATABASE_URL=test.db diesel migration run
45+
chmod a+rwx ./test.db
46+
)
47+
'';
48+
};
49+
in
50+
{
51+
formatter = pkgs.nixpkgs-fmt;
52+
53+
devShells.default = pkgs.mkShell {
54+
packages = [
55+
config.formatter
56+
pkgs.nodePackages.prettier
57+
pkgs.taplo
58+
pkgs.fd
59+
pkgs.just
60+
pkgs.pkg-config
61+
pkgs.openssl
62+
pkgs.sqlite
63+
pkgs.libpq
64+
pkgs.redis
65+
pkgs.sqlx-cli
66+
pkgs.diesel-cli
67+
] ++ lib.optional pkgs.stdenv.isDarwin [
68+
pkgs.pkgsBuildHost.libiconv
69+
];
70+
shellHook = rustRuntimeShellHook;
71+
};
72+
73+
devShells.ci = pkgs.mkShell {
74+
packages = [
75+
pkgs.just
76+
pkgs.pkg-config
77+
pkgs.openssl
78+
pkgs.sqlite
79+
pkgs.libpq
80+
pkgs.redis
81+
pkgs.sqlx-cli
82+
pkgs.diesel-cli
83+
] ++ lib.optional pkgs.stdenv.isDarwin [
84+
pkgs.pkgsBuildHost.libiconv
85+
];
86+
shellHook = rustRuntimeShellHook;
87+
};
88+
89+
apps.init-db = {
90+
type = "app";
91+
program = lib.getExe initDb;
92+
};
2293
};
23-
};
2494
};
2595
}

justfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ fmt:
88
fd --hidden --extension=toml --exec-batch taplo format
99
cargo +nightly fmt
1010

11+
# Check Rust formatting.
12+
[group("lint")]
13+
fmt-check:
14+
cargo fmt --all -- --check
15+
1116
# Check project.
1217
[group("lint")]
1318
check: && clippy
@@ -19,3 +24,50 @@ check: && clippy
1924
[group("lint")]
2025
clippy:
2126
cargo clippy --workspace --all-targets --all-features
27+
28+
# Run the CI Clippy check.
29+
[group("lint")]
30+
clippy-ci:
31+
cargo clippy --workspace --all-features --tests -- -D warnings
32+
33+
# Initialize the test databases.
34+
init-db:
35+
nix run .#init-db
36+
37+
# Start Redis for integration tests.
38+
start-redis:
39+
#!/usr/bin/env bash
40+
set -euo pipefail
41+
42+
if ! redis-cli ping; then
43+
redis-server --daemonize yes
44+
fi
45+
redis-cli ping
46+
47+
# Check that all workspace targets compile.
48+
cargo-check:
49+
cargo check --workspace --bins --examples --tests
50+
51+
# Test the workspace except for the Diesel example.
52+
test:
53+
cargo test --workspace --all-features --no-fail-fast --exclude=db-diesel -- --nocapture
54+
55+
# Test the Diesel example.
56+
test-diesel:
57+
#!/usr/bin/env bash
58+
set -euo pipefail
59+
60+
cd databases/diesel
61+
DATABASE_URL=test.db cargo test -p=db-diesel --no-fail-fast -- --nocapture
62+
63+
# Run the build and test sequence locally.
64+
ci:
65+
just init-db
66+
just start-redis
67+
just cargo-check
68+
just test
69+
just test-diesel
70+
71+
# Clean Cargo artifacts before uploading the CI cache.
72+
ci-cache-clean:
73+
cargo-ci-cache-clean

0 commit comments

Comments
 (0)