Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rust CI #35

Merged
merged 33 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f1630ea
Add rust ci
sanders41 Jan 11, 2024
26ac7a9
Ignore data in scripts/data
sanders41 Jan 11, 2024
b011da5
Run docker in detached mode
sanders41 Jan 11, 2024
e0d3092
Add db url environment vairable
sanders41 Jan 11, 2024
bd23521
Replace localhost with ip
sanders41 Jan 11, 2024
3dc9b63
Fix ip address
sanders41 Jan 11, 2024
93d8d91
Add health check
sanders41 Jan 11, 2024
d49118c
Give database time to get ready
sanders41 Jan 11, 2024
fb87bb9
Remove sleep
sanders41 Jan 11, 2024
9bc3cd7
Add debugging
sanders41 Jan 11, 2024
c5b74bc
Fix command
sanders41 Jan 11, 2024
e58aa5b
Point to config
sanders41 Jan 11, 2024
7bd4d80
Pipe to tail
sanders41 Jan 11, 2024
890eeb0
Add wait
sanders41 Jan 11, 2024
a8b5292
Sleep in action
sanders41 Jan 11, 2024
1142a3f
Add sleep to all steps
sanders41 Jan 11, 2024
2e79e9c
Try longer sleep
sanders41 Jan 11, 2024
139fd7d
Remove sleep
sanders41 Jan 11, 2024
adb61c0
Merge remote-tracking branch 'origin/main' into rust-ci
sanders41 Jan 11, 2024
a58990e
Run rust format
sanders41 Jan 11, 2024
09b1501
Append environment vairable
sanders41 Jan 11, 2024
6ae1c30
Create .env file in CI
sanders41 Jan 11, 2024
b0fe367
Add file to rust directory
sanders41 Jan 11, 2024
ba7911d
Debug
sanders41 Jan 11, 2024
a4c5465
More debugging
sanders41 Jan 11, 2024
cf0c851
Use full path
sanders41 Jan 11, 2024
eca6a19
Fix typo
sanders41 Jan 11, 2024
ec3c02b
Prepare sqlx
sanders41 Jan 11, 2024
825006f
Add env file
sanders41 Jan 11, 2024
ed3fbc5
Use command line flag
sanders41 Jan 11, 2024
bf3f4ac
Test hard coded password
sanders41 Jan 11, 2024
08db5ee
Remove hard code
sanders41 Jan 11, 2024
e28d941
Make test data directory
sanders41 Jan 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Testing

on:
push:
branches:
- main
pull_request:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUSTFLAGS: "-D warnings"
POSTGRES_PASSWORD: "test_password"
DATABASE_URL: "postgresql://postgres:[email protected]:5432/etl"
jobs:
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- name: Cache dependencies
uses: Swatinem/[email protected]
- name: Prep data and sqlx # This prevents sqlx errors if the database isn't running
run: sh ./scripts/prep_tests.sh
- name: Run cargo clippy
run: cargo clippy --all-targets -- --deny warnings
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- name: Cache dependencies
uses: Swatinem/[email protected]
- name: Run cargo fmt
run: cargo fmt --all -- --check
test:
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- name: Cache dependencies
uses: Swatinem/[email protected]
- name: Prep data and sqlx # This prevents sqlx errors if the database isn't running
run: sh ./scripts/prep_tests.sh
- name: Run cargo test
run: cargo test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ cython_debug/

# Rust
/target

/scripts/data/*
1 change: 1 addition & 0 deletions Cargo.lock

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

16 changes: 13 additions & 3 deletions pieces/intro/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,18 @@ fn run8() {
// Check for presence of value
let value = "AMD Ryzen 3";
let mut values = processors.values();
println!("Is \"AMD Ryzen 3\" in the hashmap of processors?: {}", values.any(|v| v == &value));
println!(
"Is \"AMD Ryzen 3\" in the hashmap of processors?: {}",
values.any(|v| v == &value)
);
// Lookup by key
let key = "13900KS";
let lookup_by_key = processors.get(key);
println!("Key \"{}\" has the value \"{}\"", key, lookup_by_key.unwrap());
println!(
"Key \"{}\" has the value \"{}\"",
key,
lookup_by_key.unwrap()
);
/*
Is "AMD Ryzen 3" in the hashmap of processors?: true
Key "13900KS" has the value "Intel Core i9"
Expand All @@ -178,7 +185,10 @@ fn run9() {
processors.insert("AMD Ryzen 5");
// Check for presence of value
let value = "AMD Ryzen 3";
println!("Is \"AMD Ryzen 3\" in the hashset of processors?: {}", processors.contains(&value));
println!(
"Is \"AMD Ryzen 3\" in the hashset of processors?: {}",
processors.contains(&value)
);
/*
Is "AMD Ryzen 3" in the hashset of processors?: true
*/
Expand Down
1 change: 0 additions & 1 deletion pieces/postgres_etl/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async fn main() -> Result<(), sqlx::Error> {
dotenv().ok();
// Obtain connection
let pg_uri = dotenvy::var("DATABASE_URL").unwrap();
// let pool = Arc::new(PgPool::connect(&pg_uri).await.unwrap());
let pool = PgPoolOptions::new()
.min_connections(5)
.max_connections(5)
Expand Down
13 changes: 13 additions & 0 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.9"

services:
database:
image: "postgres:latest"
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- ./pg/:/var/lib/postgresql/data/
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
- ./data:/data
21 changes: 21 additions & 0 deletions scripts/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SELECT 'CREATE DATABASE etl'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'etl')\gexec

\connect etl

CREATE TABLE IF NOT EXISTS persons(
id integer PRIMARY KEY,
name text,
age smallint,
isMarried boolean,
city text,
state text,
country text
)\gexec

TRUNCATE TABLE persons\gexec

COPY persons(id, name, age, isMarried, city, state, country)
FROM '/data/persons.csv'
DELIMITER ','
CSV HEADER\gexec
5 changes: 5 additions & 0 deletions scripts/prep_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!bin/bash

mkdir scripts/data
cp pieces/postgres_etl/data/persons.csv scripts/data
docker compose -f scripts/docker-compose.yml up -d