Skip to content

Commit 1eaca0b

Browse files
committed
github workflow experiment
1 parent 838fbd9 commit 1eaca0b

File tree

3 files changed

+324
-47
lines changed

3 files changed

+324
-47
lines changed

.github/workflows/ci.yml

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: ['v*']
7+
pull_request:
8+
branches: [main]
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
17+
services:
18+
postgres:
19+
image: postgres:13.4
20+
env:
21+
POSTGRES_USER: postgres
22+
POSTGRES_PASSWORD: postgres
23+
options: >-
24+
--health-cmd pg_isready
25+
--health-interval 10s
26+
--health-timeout 5s
27+
--health-retries 5
28+
ports:
29+
- 5432:5432
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Install Nix
35+
uses: cachix/install-nix-action@v27
36+
with:
37+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Cache Nix store
40+
uses: DeterminateSystems/magic-nix-cache-action@v7
41+
42+
- name: Cache Rust dependencies
43+
uses: Swatinem/rust-cache@v2
44+
with:
45+
shared-key: "rust-deps"
46+
cache-on-failure: true
47+
48+
- name: Check formatting
49+
run: nix develop --command cargo fmt -- --check
50+
51+
- name: Run clippy
52+
run: nix develop --command cargo clippy --all-targets --all-features -- -D warnings
53+
54+
- name: Run tests
55+
run: nix develop --command cargo test
56+
env:
57+
DATABASE_URL: postgresql://postgres:postgres@localhost
58+
59+
build-linux:
60+
runs-on: ubuntu-latest
61+
needs: test
62+
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Install Nix
67+
uses: cachix/install-nix-action@v27
68+
with:
69+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Cache Nix store
72+
uses: DeterminateSystems/magic-nix-cache-action@v7
73+
74+
- name: Cache Rust dependencies
75+
uses: Swatinem/rust-cache@v2
76+
with:
77+
shared-key: "rust-deps"
78+
cache-on-failure: true
79+
80+
- name: Build Linux binary (musl)
81+
run: |
82+
nix build .#anonymiser-musl
83+
cp result/bin/anonymiser anonymiser-x86_64-unknown-linux-musl
84+
85+
- name: Upload artifact
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: anonymiser-linux
89+
path: anonymiser-x86_64-unknown-linux-musl
90+
91+
test-alpine:
92+
runs-on: ubuntu-latest
93+
needs: build-linux
94+
container:
95+
image: alpine:3.18
96+
97+
services:
98+
postgres:
99+
image: postgres:13.4
100+
env:
101+
POSTGRES_USER: postgres
102+
POSTGRES_PASSWORD: postgres
103+
options: >-
104+
--health-cmd pg_isready
105+
--health-interval 10s
106+
--health-timeout 5s
107+
--health-retries 5
108+
109+
steps:
110+
- name: Download Linux binary
111+
uses: actions/download-artifact@v4
112+
with:
113+
name: anonymiser-linux
114+
115+
- name: Make binary executable
116+
run: chmod +x anonymiser-x86_64-unknown-linux-musl
117+
118+
- name: Test binary on Alpine
119+
run: |
120+
./anonymiser-x86_64-unknown-linux-musl generate-strategies --db-url postgresql://postgres:postgres@postgres
121+
env:
122+
DATABASE_URL: postgresql://postgres:postgres@postgres
123+
124+
test-amazon-linux:
125+
runs-on: ubuntu-latest
126+
needs: build-linux
127+
container:
128+
image: public.ecr.aws/amazonlinux/amazonlinux:latest
129+
130+
services:
131+
postgres:
132+
image: postgres:13.4
133+
env:
134+
POSTGRES_USER: postgres
135+
POSTGRES_PASSWORD: postgres
136+
options: >-
137+
--health-cmd pg_isready
138+
--health-interval 10s
139+
--health-timeout 5s
140+
--health-retries 5
141+
142+
steps:
143+
- name: Download Linux binary
144+
uses: actions/download-artifact@v4
145+
with:
146+
name: anonymiser-linux
147+
148+
- name: Make binary executable
149+
run: chmod +x anonymiser-x86_64-unknown-linux-musl
150+
151+
- name: Test binary on Amazon Linux
152+
run: |
153+
./anonymiser-x86_64-unknown-linux-musl generate-strategies --db-url postgresql://postgres:postgres@postgres
154+
env:
155+
DATABASE_URL: postgresql://postgres:postgres@postgres
156+
157+
build-macos:
158+
strategy:
159+
matrix:
160+
include:
161+
- runner: macos-13
162+
target: x86_64-apple-darwin
163+
name: Intel Mac
164+
- runner: macos-14
165+
target: aarch64-apple-darwin
166+
name: Apple silicon mac
167+
168+
runs-on: ${{ matrix.runner }}
169+
needs: test
170+
171+
steps:
172+
- uses: actions/checkout@v4
173+
174+
- name: Install Nix
175+
uses: cachix/install-nix-action@v27
176+
with:
177+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
178+
179+
- name: Cache Nix store
180+
uses: DeterminateSystems/magic-nix-cache-action@v7
181+
182+
- name: Cache Rust dependencies
183+
uses: Swatinem/rust-cache@v2
184+
with:
185+
shared-key: "rust-deps"
186+
cache-on-failure: true
187+
188+
- name: Build macOS binary
189+
run: |
190+
nix build .#anonymiser
191+
cp result/bin/anonymiser anonymiser-${{ matrix.target }}
192+
193+
- name: Test binary
194+
run: ./anonymiser-${{ matrix.target }} --help
195+
196+
- name: Upload artifact
197+
uses: actions/upload-artifact@v4
198+
with:
199+
name: anonymiser-${{ matrix.target }}
200+
path: anonymiser-${{ matrix.target }}
201+
202+
release:
203+
runs-on: ubuntu-latest
204+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
205+
needs: [test-alpine, test-amazon-linux, build-macos]
206+
permissions:
207+
contents: write
208+
209+
steps:
210+
- uses: actions/checkout@v4
211+
212+
- name: Download Linux binary
213+
uses: actions/download-artifact@v4
214+
with:
215+
name: anonymiser-linux
216+
217+
- name: Download macOS x86_64 binary
218+
uses: actions/download-artifact@v4
219+
with:
220+
name: anonymiser-x86_64-apple-darwin
221+
222+
- name: Download macOS ARM64 binary
223+
uses: actions/download-artifact@v4
224+
with:
225+
name: anonymiser-aarch64-apple-darwin
226+
227+
- name: Create GitHub Release
228+
env:
229+
GH_TOKEN: ${{ github.token }}
230+
run: |
231+
gh release create --draft --generate-notes "${{ github.ref_name }}" \
232+
'./anonymiser-x86_64-unknown-linux-musl#Linux' \
233+
'./anonymiser-x86_64-apple-darwin#Intel Mac' \
234+
'./anonymiser-aarch64-apple-darwin#Apple silicon mac'

flake.nix

Lines changed: 86 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,98 @@
1616
flake-utils,
1717
rust-overlay,
1818
}:
19-
flake-utils.lib.eachDefaultSystem (system: let
20-
overlays = [rust-overlay.overlays.default];
21-
pkgs = import nixpkgs {inherit overlays system;};
19+
flake-utils.lib.eachDefaultSystem (
20+
system: let
21+
overlays = [rust-overlay.overlays.default];
22+
pkgs = import nixpkgs {inherit overlays system;};
2223

23-
rust = pkgs.rust-bin.stable.latest.default.override {extensions = ["rust-src"];};
24-
rustPlatform = pkgs.makeRustPlatform {
25-
cargo = rust;
26-
rustc = rust;
27-
};
24+
rust = pkgs.rust-bin.stable.latest.default.override {extensions = ["rust-src"];};
25+
rustPlatform = pkgs.makeRustPlatform {
26+
cargo = rust;
27+
rustc = rust;
28+
};
2829

29-
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
30-
in {
31-
# `nix develop`.
32-
devShells = {
33-
default = pkgs.mkShell {
34-
inputsFrom = [self.packages.${system}.anonymiser];
35-
buildInputs = with pkgs; [rust-analyzer];
30+
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
31+
in {
32+
# `nix develop`.
33+
devShells = {
34+
default = pkgs.mkShell {
35+
inputsFrom = [self.packages.${system}.anonymiser];
36+
buildInputs = with pkgs; [rust-analyzer];
37+
};
3638
};
37-
};
3839

39-
# `nix fmt`.
40-
formatter = pkgs.alejandra;
40+
# `nix fmt`.
41+
formatter = pkgs.alejandra;
42+
43+
# `nix build`.
44+
packages = {
45+
anonymiser = rustPlatform.buildRustPackage {
46+
pname = manifest.name;
47+
version = manifest.version;
48+
src = pkgs.nix-gitignore.gitignoreSource [] ./.;
49+
cargoLock.lockFile = ./Cargo.lock;
50+
51+
# Compile-time dependencies.
52+
nativeBuildInputs = with pkgs; [
53+
pkg-config
54+
cmake
55+
perl # Required for vendored OpenSSL build
56+
];
57+
# Run-time dependencies.
58+
buildInputs = with pkgs;
59+
[
60+
openssl
61+
]
62+
++ pkgs.lib.optionals pkgs.stdenv.isDarwin (
63+
with pkgs.darwin.apple_sdk.frameworks; [
64+
Security
65+
SystemConfiguration
66+
]
67+
);
68+
69+
checkFlags = [
70+
# Skip tests which require access to a PostgreSQL server.
71+
"--skip=anonymiser::tests::successfully_transforms"
72+
"--skip=anonymiser::tests::successfully_truncates"
73+
"--skip=parsers::db_schema::tests::can_read_db_columns"
74+
];
75+
};
76+
77+
# Static musl build for Linux distribution
78+
anonymiser-musl = rustPlatform.buildRustPackage {
79+
pname = "${manifest.name}-musl";
80+
version = manifest.version;
81+
src = pkgs.nix-gitignore.gitignoreSource [] ./.;
82+
cargoLock.lockFile = ./Cargo.lock;
83+
84+
# Target musl for static linking
85+
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
86+
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
87+
88+
# Compile-time dependencies.
89+
nativeBuildInputs = with pkgs; [
90+
pkg-config
91+
cmake
92+
perl # Required for vendored OpenSSL build
93+
];
94+
95+
# With vendored OpenSSL, we don't need runtime dependencies
96+
buildInputs = [];
4197

42-
# `nix build`.
43-
packages = {
44-
anonymiser = rustPlatform.buildRustPackage {
45-
pname = manifest.name;
46-
version = manifest.version;
47-
src = pkgs.nix-gitignore.gitignoreSource [] ./.;
48-
cargoLock.lockFile = ./Cargo.lock;
98+
checkFlags = [
99+
# Skip tests which require access to a PostgreSQL server.
100+
"--skip=anonymiser::tests::successfully_transforms"
101+
"--skip=anonymiser::tests::successfully_truncates"
102+
"--skip=parsers::db_schema::tests::can_read_db_columns"
103+
];
49104

50-
# Compile-time dependencies.
51-
nativeBuildInputs = with pkgs; [
52-
pkg-config
53-
cmake
54-
];
55-
# Run-time dependencies.
56-
buildInputs = with pkgs;
57-
[
58-
openssl
59-
]
60-
++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
61-
Security
62-
SystemConfiguration
63-
]);
105+
# Only build on Linux
106+
meta.platforms = ["x86_64-linux"];
107+
};
64108

65-
checkFlags = [
66-
# Skip tests which require acces to a PostgreSQL server.
67-
"--skip=anonymiser::tests::successfully_transforms"
68-
"--skip=parsers::db_schema::tests::can_read_db_columns"
69-
];
109+
default = self.packages.${system}.anonymiser;
70110
};
71-
default = self.packages.${system}.anonymiser;
72-
};
73-
});
111+
}
112+
);
74113
}

src/file_reader.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ pub fn read(
4949
file_writer.write_all(transformed_row.as_bytes())?;
5050
line.clear();
5151
}
52+
53+
// Flush to ensure all data is written before auto_finish() on drop
54+
file_writer.flush()?;
55+
5256
Ok(())
5357
}
5458

0 commit comments

Comments
 (0)