Skip to content

Commit dec0f21

Browse files
authored
Try GitHub actions (#27)
* First try for github actions * Run tests also on all toolchains and os's * Syntax fix * More syntax fix * More syntax fix * Install postgres * Only try check builds for now * It's macos * Try to install all platform dependent libraries * Fix yml * Fix equal * More fixes * Even more fixes * Fix windows image name * Check more things * Fix typo * More typos * Fix windows? * Windows setup fixes * More fixes + clippy * More windows setup fixes * Try to fix sqlite install on windows * Next try * Even more fixes * More fixes * Don't use default features * Make wundergraph_cli not depend on sqlite and postgres * Setup PATH for sqlite on windows * Next try * Some more fixes * Typos… * Next try from sqlite * Fix paths * Setup visual studio * Add missing slash * Try another binary name * Try absulut path * Next try * Next try * Debug * More debug * Use addpath to setup path * Next sqlite windows try * Sqlite tests need `RUST_TEST_THREADS=1` * Config postgres * Typos everywhere * Try to fix setup on macOS * Fix postgres setup on windows * Debugging * More debuging * Next try * Next try * Next try * Another variant * More fixes * More debugging * Debugging * WTF * Next try * Another try * More debugging * next try * Fix yaml * Next try * Update insta snapshot * Add some caching * Try to fix caching * Fix typo * Next try * Try to fix linking sqlite on windows + fix rustfmt * Fix rustfmt + some debugging * Move nocapture to the right place * Do not hard code any paths * Make this a path * Fix the path stuff * More debugging * We need to escape paths on windows… * Create a postgres database on windows * improve caching * Try to fix paths on windows * More path stuff * Next try to create postgres db * Seems like the argument order is different here * Use a newer postgres on windows * Use the correct path * Try another way to initialize the postgres db on windows * That's bash, so use bash variables here * Fix PQ_LIB_DIR * Rename to CI * Add an workflow that runs cargo audit regularly * Disable travis * Fix path * Remove caching, seems to cache ~nothing at least not target, because that's too big * Cache cargo things + name clippy jobs differently * Clippy fixes in wundergraph_cli
1 parent db32eb5 commit dec0f21

File tree

9 files changed

+244
-69
lines changed

9 files changed

+244
-69
lines changed

.github/workflows/audit.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Security audit
2+
on:
3+
push:
4+
paths:
5+
- '**/Cargo.toml'
6+
- '**/Cargo.lock'
7+
schedule:
8+
- cron: '0 0 */7 * *'
9+
jobs:
10+
security_audit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
- uses: actions-rs/audit-check@v1
15+
with:
16+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci.yml

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
on: [pull_request]
2+
3+
name: CI Tests
4+
5+
jobs:
6+
check_and_test:
7+
name: Check
8+
strategy:
9+
matrix:
10+
rust: ["1.38.0", "stable", "beta", "nightly"]
11+
backend: ["postgres", "sqlite"]
12+
os: [ubuntu-18.04, macos-latest, windows-latest]
13+
runs-on: ${{ matrix.os }}
14+
steps:
15+
- name: Checkout sources
16+
uses: actions/checkout@v1
17+
- name: Set environment variables
18+
shell: bash
19+
if: matrix.backend == 'postgres'
20+
run: |
21+
echo '::set-env name=DATABASE_URL::postgres://postgres:postgres@localhost/wundergraph_test'
22+
23+
- name: Set environment variables
24+
shell: bash
25+
if: matrix.backend == 'sqlite'
26+
run: |
27+
echo '::set-env name=DATABASE_URL::./test.db'
28+
echo '::set-env name=RUST_TEST_THREADS::1'
29+
30+
- name: Cache cargo registry
31+
uses: actions/cache@v1
32+
with:
33+
path: ~/.cargo/registry
34+
key: ${{ runner.os }}-${{ matrix.backend }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
35+
- name: Cache cargo index
36+
uses: actions/cache@v1
37+
with:
38+
path: ~/.cargo/git
39+
key: ${{ runner.os }}-${{ matrix.backend }}-cargo-index-${{ hashFiles('**/Cargo.toml') }}
40+
- name: Install libpq (Linux)
41+
if: runner.os == 'Linux' && matrix.backend == 'postgres'
42+
run: |
43+
sudo apt-get update
44+
sudo apt-get install -y libpq-dev postgresql
45+
echo "host all all 127.0.0.1/32 md5" > sudo tee -a /etc/postgresql/9.5/main/pg_hba.conf
46+
sudo service postgresql restart && sleep 3
47+
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
48+
sudo -u postgres psql -c "CREATE DATABASE wundergraph_test WITH OWNER = 'postgres';"
49+
sudo service postgresql restart && sleep 3
50+
51+
- name: Install sqlite (Linux)
52+
if: runner.os == 'Linux' && matrix.backend == 'sqlite'
53+
run: sudo apt-get update && sudo apt-get install -y libsqlite3-dev sqlite3
54+
55+
- name: Install libpq (MacOs)
56+
if: runner.os == 'macOS' && matrix.backend == 'postgres'
57+
run: |
58+
brew update
59+
brew install postgres
60+
/usr/local/opt/postgres/bin/pg_ctl -D /usr/local/var/postgres start
61+
sleep 3
62+
/usr/local/opt/postgres/bin/createuser -s postgres
63+
/usr/local/opt/postgres/bin/createdb wundergraph_test -O postgres
64+
/usr/local/opt/postgres/bin/psql -c "ALTER USER postgres PASSWORD 'postgres';" wundergraph_test
65+
66+
- name: Install sqlite (MacOS)
67+
if: runner.os == 'macOS' && matrix.backend == 'sqlite'
68+
run: |
69+
brew update &&
70+
brew install sqlite
71+
72+
- name: Install sqlite (Windows)
73+
if: runner.os == 'Windows' && matrix.backend == 'sqlite'
74+
shell: cmd
75+
run: |
76+
choco install sqlite
77+
cd /D C:\ProgramData\chocolatey\lib\SQLite\tools
78+
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
79+
lib /machine:x64 /def:sqlite3.def /out:sqlite3.lib
80+
echo ::add-path::C:\ProgramData\chocolatey\lib\SQLite\tools
81+
echo ::set-env name=SQLITE3_LIB_DIR::C:\ProgramData\chocolatey\lib\SQLite\tools
82+
dir
83+
84+
- name: Install libpq (Windows)
85+
if: runner.os == 'Windows' && matrix.backend == 'postgres'
86+
shell: bash
87+
run: |
88+
choco install postgresql12 --force --params '/Password:postgres'
89+
echo '::add-path::C:\Program Files\PostgreSQL\12\bin'
90+
echo '::add-path::C:\Program Files\PostgreSQL\12\lib'
91+
echo '::set-env name=PQ_LIB_DIR::C:\Program Files\PostgreSQL\12\lib'
92+
PGPASSWORD='postgres' "C:\Program Files\PostgreSQL\12\bin\psql.exe" -Upostgres -c "CREATE DATABASE wundergraph_test WITH OWNER = 'postgres';"
93+
94+
- name: Install rust toolchain
95+
uses: actions-rs/toolchain@v1
96+
with:
97+
profile: minimal
98+
toolchain: ${{ matrix.rust }}
99+
override: true
100+
101+
- name: Run cargo check for wundergraph_derive
102+
uses: actions-rs/cargo@v1
103+
with:
104+
command: check
105+
args: --manifest-path wundergraph_derive/Cargo.toml --features "${{ matrix.backend }}"
106+
107+
- name: Run cargo check for wundergraph
108+
uses: actions-rs/cargo@v1
109+
with:
110+
command: check
111+
args: --manifest-path wundergraph/Cargo.toml --features "${{ matrix.backend }}"
112+
113+
- name: Run cargo check for wundergraph_example
114+
uses: actions-rs/cargo@v1
115+
with:
116+
command: check
117+
args: --manifest-path wundergraph_example/Cargo.toml --features "${{ matrix.backend }}" --no-default-features
118+
119+
- name: Run cargo check for wundergraph_bench
120+
uses: actions-rs/cargo@v1
121+
with:
122+
command: check
123+
args: --manifest-path wundergraph_bench/Cargo.toml --features "${{ matrix.backend }}" --no-default-features
124+
125+
- name: Run cargo check for wundergraph_cli
126+
uses: actions-rs/cargo@v1
127+
with:
128+
command: check
129+
args: --manifest-path wundergraph_cli/Cargo.toml --features "${{ matrix.backend }}" --no-default-features
130+
131+
- name: Run cargo test for wundergraph
132+
uses: actions-rs/cargo@v1
133+
with:
134+
command: test
135+
args: --manifest-path wundergraph/Cargo.toml --features "${{ matrix.backend }} wundergraph_example/${{ matrix.backend }} wundergraph_bench/${{ matrix.backend }}" --no-default-features
136+
137+
- name: Run cargo test for wundergraph_cli
138+
uses: actions-rs/cargo@v1
139+
with:
140+
command: test
141+
args: --manifest-path wundergraph_cli/Cargo.toml --features "${{ matrix.backend }}" --no-default-features -- --nocapture
142+
143+
144+
clippy_check:
145+
name: Rustfmt + Clippy
146+
runs-on: ubuntu-latest
147+
steps:
148+
- uses: actions/checkout@v1
149+
- uses: actions-rs/toolchain@v1
150+
with:
151+
toolchain: nightly-2019-10-03
152+
profile: minimal
153+
components: clippy, rustfmt
154+
- name: Cache cargo registry
155+
uses: actions/cache@v1
156+
with:
157+
path: ~/.cargo/registry
158+
key: clippy-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
159+
- name: Cache cargo index
160+
uses: actions/cache@v1
161+
with:
162+
path: ~/.cargo/git
163+
key: clippy-cargo-index-${{ hashFiles('**/Cargo.toml') }}
164+
- name: Rustfmt
165+
run: |
166+
cargo fmt --all -- --check
167+
- uses: actions-rs/clippy-check@v1
168+
name: Clippy wundergraph_derive
169+
with:
170+
name: Clippy wundergraph_derive
171+
token: ${{ secrets.GITHUB_TOKEN }}
172+
args: --manifest-path wundergraph_derive/Cargo.toml --features "postgres sqlite"
173+
- uses: actions-rs/clippy-check@v1
174+
name: Clippy wundergraph
175+
with:
176+
name: Clippy wundergraph
177+
token: ${{ secrets.GITHUB_TOKEN }}
178+
args: --manifest-path wundergraph/Cargo.toml --features "postgres sqlite"
179+
- uses: actions-rs/clippy-check@v1
180+
name: Clippy wundergraph_cli
181+
with:
182+
name: Clippy wundergraph_cli
183+
token: ${{ secrets.GITHUB_TOKEN }}
184+
args: --manifest-path wundergraph_cli/Cargo.toml --features "postgres sqlite"

.travis.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

wundergraph_cli/src/infer_schema_internals/inference.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub fn load_table_data(
129129
(Automatically generated by Diesel.)",
130130
name
131131
);
132-
let primary_key = get_primary_keys(&connection, &name)?;
132+
let primary_key = get_primary_keys(connection, &name)?;
133133
let primary_key = primary_key
134134
.iter()
135135
.map(|k| {
@@ -141,10 +141,10 @@ pub fn load_table_data(
141141
})
142142
.collect();
143143

144-
let column_data = get_column_information(&connection, &name)?
144+
let column_data = get_column_information(connection, &name)?
145145
.into_iter()
146146
.map(|c| {
147-
let ty = determine_column_type(&c, &connection)?;
147+
let ty = determine_column_type(&c, connection)?;
148148
let rust_name = if RESERVED_NAMES.contains(&c.column_name.as_str()) {
149149
Some(format!("{}_", c.column_name))
150150
} else {

wundergraph_cli/src/infer_schema_internals/sqlite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn load_foreign_key_constraints(
8585
.collect())
8686
})
8787
.collect::<QueryResult<Vec<Vec<_>>>>()?;
88-
Ok(rows.into_iter().flat_map(|x| x).collect())
88+
Ok(rows.into_iter().flatten().collect())
8989
}
9090

9191
pub fn get_table_data(

wundergraph_cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use crate::database::InferConnection;
4141

4242
#[derive(StructOpt, Debug)]
4343
#[structopt(name = "wundergraph")]
44+
#[allow(clippy::result_unwrap_used)]
4445
enum Wundergraph {
4546
#[structopt(name = "print-schema")]
4647
PrintSchema {

wundergraph_cli/src/print_schema/mod.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ mod tests {
158158
fn round_trip() {
159159
use std::fs::File;
160160
use std::io::{BufRead, BufReader, Read, Write};
161+
use std::path::PathBuf;
161162
use std::process::Command;
162163

163164
let conn = get_connection();
@@ -184,7 +185,7 @@ mod tests {
184185
let main = tmp_dir
185186
.path()
186187
.join("wundergraph_roundtrip_test/src/main.rs");
187-
std::fs::remove_file(&main);
188+
std::fs::remove_file(&main).unwrap();
188189
let mut main_file = File::create(main).unwrap();
189190

190191
let migrations = MIGRATION.iter().fold(String::new(), |mut acc, s| {
@@ -224,47 +225,62 @@ mod tests {
224225
.open(cargo_toml)
225226
.unwrap();
226227
let current_root = env!("CARGO_MANIFEST_DIR");
228+
let mut wundergraph_dir = PathBuf::from(current_root);
229+
wundergraph_dir.push("..");
230+
wundergraph_dir.push("wundergraph");
231+
232+
let wundergraph_dir = wundergraph_dir.to_str().unwrap().replace(r"\", r"\\");
233+
227234
#[cfg(feature = "postgres")]
228235
{
229236
writeln!(
230237
cargo_toml_file,
231-
"{}",
232-
r#"diesel = {version = "1.4", features = ["postgres", "chrono"]}"#
238+
r#"diesel = {{version = "1.4", features = ["postgres", "chrono"]}}"#
233239
)
234240
.unwrap();
241+
235242
writeln!(
236243
cargo_toml_file,
237-
"wundergraph = {{path = \"{}/../wundergraph/\", features = [\"postgres\", \"chrono\"] }}",
238-
current_root
244+
"wundergraph = {{path = \"{}\", features = [\"postgres\", \"chrono\"] }}",
245+
wundergraph_dir
239246
)
240247
.unwrap();
241248
}
242249
#[cfg(feature = "sqlite")]
243250
{
244251
writeln!(
245252
cargo_toml_file,
246-
"{}",
247-
r#"diesel = {version = "1.4", features = ["sqlite", "chrono"]}"#
253+
r#"diesel = {{version = "1.4", features = ["sqlite", "chrono"]}}"#
248254
)
249255
.unwrap();
256+
250257
writeln!(
251258
cargo_toml_file,
252-
"wundergraph = {{path = \"{}/../wundergraph\", features = [\"sqlite\", \"chrono\"] }}",
253-
current_root
259+
"wundergraph = {{path = \"{}\", features = [\"sqlite\", \"chrono\"] }}",
260+
wundergraph_dir
254261
)
255262
.unwrap();
256263
}
257-
writeln!(cargo_toml_file, "{}", r#"juniper = "0.14""#).unwrap();
258-
writeln!(cargo_toml_file, "{}", r#"failure = "0.1""#).unwrap();
259-
writeln!(cargo_toml_file, "{}", r#"actix-web = "1""#).unwrap();
260-
writeln!(cargo_toml_file, "{}", r#"chrono = "0.4""#).unwrap();
264+
writeln!(cargo_toml_file, r#"juniper = "0.14""#).unwrap();
265+
writeln!(cargo_toml_file, r#"failure = "0.1""#).unwrap();
266+
writeln!(cargo_toml_file, r#"actix-web = "1""#).unwrap();
267+
writeln!(cargo_toml_file, r#"chrono = "0.4""#).unwrap();
261268
writeln!(
262269
cargo_toml_file,
263-
"{}",
264-
r#"serde = {version = "1", features = ["derive"]}"#
270+
r#"serde = {{version = "1", features = ["derive"]}}"#
265271
)
266272
.unwrap();
267-
writeln!(cargo_toml_file, "{}", r#"serde_json = "1""#).unwrap();
273+
writeln!(cargo_toml_file, r#"serde_json = "1""#).unwrap();
274+
275+
{
276+
use std::io::Seek;
277+
use std::io::SeekFrom;
278+
cargo_toml_file.seek(SeekFrom::Start(0)).unwrap();
279+
280+
let mut toml = String::new();
281+
cargo_toml_file.read_to_string(&mut toml).unwrap();
282+
println!("{:?}", toml);
283+
}
268284

269285
std::mem::drop(conn);
270286
let mut child = Command::new("cargo")

0 commit comments

Comments
 (0)