Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
83 changes: 26 additions & 57 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,57 @@ on:
- "Cargo.toml"
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: true
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

concurrency:
group: CI-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build and Initialize profile.dev Cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- uses: rui314/setup-mold@v1
- uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true
- uses: actions/cache@v3.2.5
with:
path: |
./.cargo/.build
./target
~/.cargo
key: ${{ runner.os }}-cargo-dev-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/cargo@v1.0.3
with:
command: build

check:
name: Check
needs: [build]
development-lint:
name: Clippy with debug-assertions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- uses: rui314/setup-mold@v1
- uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true
- uses: actions/cache@v3.2.5
- run: rustup install stable
- run: rustup update
- run: rustup component add clippy
- uses: actions/cache@v3.2.6
with:
path: |
./.cargo/.build
./target
~/.cargo
key: ${{ runner.os }}-cargo-dev-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/cargo@v1.0.3
- name: Clippy
uses: actions-rs/cargo@v1.0.3
with:
command: check

clippy:
name: Clippy
needs: [build]
command: clippy
args: -- -D warnings -C debug-assertions=y

production-lint:
name: Clippy without debug-assertions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- uses: rui314/setup-mold@v1
- uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true
- run: rustup install stable
- run: rustup update
- run: rustup component add clippy
- uses: actions/cache@v3.2.5
- uses: actions/cache@v3.2.6
with:
path: |
./.cargo/.build
./target
~/.cargo
key: ${{ runner.os }}-cargo-dev-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/cargo@v1.0.3
key: ${{ runner.os }}-cargo-prod-${{ hashFiles('**/Cargo.lock') }}
- name: Clippy
uses: actions-rs/cargo@v1.0.3
with:
command: clippy
args: -- -D warnings
args: -- -D warnings -C debug-assertions=n

# things that use the cargo-test cache
test:
Expand All @@ -99,11 +74,8 @@ jobs:
steps:
- uses: actions/checkout@v3.3.0
- uses: rui314/setup-mold@v1
- uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true
- run: rustup install stable
- run: rustup update
- uses: actions/cache@v3.2.5
with:
path: |
Expand All @@ -122,13 +94,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true
- run: rustup install stable
- run: rustup update
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1.0.3
with:
command: fmt
args: --all -- --check
args: --all -- --check
20 changes: 10 additions & 10 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions create-rust-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ plugin_storage = [ "aws-config", "aws-types", "aws-endpoint", "aws-sdk-s3", "tok
plugin_graphql = []
plugin_utoipa = ["utoipa", "utoipa-swagger-ui", "backend_actix-web"]
plugin_tasks = ["fang"]
plugin_workspace_support = []
backend_poem = ["poem", "anyhow", "mime_guess", "tokio"]
backend_actix-web = ["actix-web", "actix-http", "actix-files", "actix-multipart", "actix-web-httpauth","derive_more", "futures", "env_logger"]
backend_axum = ["axum", "axum/ws", "tokio"]
Expand Down
3 changes: 2 additions & 1 deletion create-rust-app/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use diesel::PgConnection;
use diesel::r2d2::{self, ConnectionManager, PooledConnection};

use once_cell::sync::OnceCell;

#[cfg(feature = "database_postgres")]
Expand All @@ -8,6 +8,7 @@ type DbCon = diesel::PgConnection;
#[cfg(feature = "database_sqlite")]
type DbCon = diesel::SqliteConnection;

#[allow(dead_code)]
#[cfg(feature = "database_postgres")]
pub type DieselBackend = diesel::pg::Pg;

Expand Down
8 changes: 8 additions & 0 deletions create-rust-app/src/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,15 @@ fn get_features(project_dir: &'static str) -> Vec<String> {
let cargo_toml = Manifest::from_path(PathBuf::from_iter([project_dir, "Cargo.toml"]))
.unwrap_or_else(|_| panic!("Could not find \"{}\"", project_dir));
// .expect(&format!("Could not find \"{project_dir}\""));
#[cfg(not(feature = "plugin_workspace_support"))]
let deps = cargo_toml.dependencies;
#[cfg(feature = "plugin_workspace_support")]
let mut deps = cargo_toml.dependencies;
#[cfg(feature = "plugin_workspace_support")]
if let Some(workspace) = cargo_toml.workspace {
// if the manifest has a workspace table, also read dependencies in there
deps.extend(workspace.dependencies);
}
let dep = deps.get("create-rust-app").unwrap_or_else(|| {
panic!(
"Expected \"{}\" to list 'create-rust-app' as a dependency.",
Expand Down
6 changes: 2 additions & 4 deletions create-rust-app/src/tasks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Database;
use fang::Queue;
use once_cell::sync::OnceCell;
use crate::Database;
// re-export setup for tasks
pub use crate::setup;

Expand All @@ -13,8 +13,6 @@ pub fn queue() -> &'static Queue {
QUEUE.get_or_init(|| {
let db = Database::new();

Queue::builder()
.connection_pool(db.pool.clone())
.build()
Queue::builder().connection_pool(db.pool.clone()).build()
})
}
13 changes: 10 additions & 3 deletions create-rust-app/src/util/actix_web_utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#[cfg(debug_assertions)]
use actix_http::Uri;
#[cfg(debug_assertions)]
use std::str::FromStr;
#[cfg(debug_assertions)]
use std::sync::Mutex;

use super::template_utils::SinglePageApplication;
use crate::util::template_utils::{to_template_name, DEFAULT_TEMPLATE, TEMPLATES};
use actix_files::NamedFile;
use actix_http::Uri;

use actix_web::http::StatusCode;
use actix_web::{web, HttpRequest, HttpResponse, Scope};
use tera::Context;
Expand Down Expand Up @@ -136,11 +140,14 @@ pub async fn render_views(req: HttpRequest) -> HttpResponse {
template_response(req, content)
}

fn template_response(req: HttpRequest, content: String) -> HttpResponse {
fn template_response(_req: HttpRequest, content: String) -> HttpResponse {
#[cfg(not(debug_assertions))]
let content = content;
#[cfg(debug_assertions)]
let mut content = content;
#[cfg(debug_assertions)]
{
let uri = Uri::from_str(req.connection_info().host());
let uri = Uri::from_str(_req.connection_info().host());
let hostname = match &uri {
Ok(uri) => uri.host().unwrap_or("localhost"),
Err(_) => "localhost",
Expand Down
8 changes: 5 additions & 3 deletions create-rust-app/src/util/template_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ impl tera::Function for InjectBundle {
{
let manifest_entry = VITE_MANIFEST
.get(&format!("bundles/{bundle_name}"))
.expect(&format!("could not get bundle `{bundle_name}`"));
.unwrap_or_else(|| {
panic!("{}", "could not get bundle `{bundle_name}`")
});
let entry_file = format!(
r#"<script type="module" src="/{file}"></script>"#,
file = manifest_entry.file
Expand All @@ -63,7 +65,7 @@ impl tera::Function for InjectBundle {
.css
.as_ref()
.unwrap_or(&vec![])
.into_iter()
.iter()
.map(|css_file| {
format!(
r#"<link rel="stylesheet" href="/{file}" />"#,
Expand All @@ -76,7 +78,7 @@ impl tera::Function for InjectBundle {
.dynamicImports
.as_ref()
.unwrap_or(&vec![])
.into_iter()
.iter()
.map(|dyn_script_file| {
// TODO: make this deferred or async -- look this up!~
format!(
Expand Down
2 changes: 1 addition & 1 deletion create-rust-app_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ console = "0.15.5"
dialoguer = "0.10.3"
indoc = "1.0.8"
walkdir = "2.3.2"
rust-embed = "6.4.2"
rust-embed = { version = "6.6.1", features = ["debug-embed"] }
clap = {version = "4.1", features = ["wrap_help", "derive", "cargo"]}
toml = "0.5.11"
tsync = "1"
Expand Down
1 change: 0 additions & 1 deletion create-rust-app_cli/qsync/src/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ impl Hook {
.endpoint_url
.trim_start_matches("/api/")
.split('/')
.into_iter()
.map(|t| {
// in actix-web, paths which have {} denote a path param
if t.starts_with('{') && t.ends_with('}') {
Expand Down
2 changes: 1 addition & 1 deletion create-rust-app_cli/qsync/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn has_qsync_attribute(
if has_actix_attribute && has_qsync_attribute {
Some(QsyncAttributeProps {
is_mutation: is_mutation.unwrap_or_default(),
return_type: return_type,
return_type,
})
} else {
None
Expand Down
5 changes: 5 additions & 0 deletions create-rust-app_cli/src/content/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ use crate::inflector::Inflector;
use anyhow::Result;
use indoc::indoc;

#[allow(dead_code)]
pub struct Model {
pub config: ModelConfig,
pub file_contents: String,
}

#[allow(dead_code)]
pub struct ModelConfig {
pub model_name: String,
pub table_name: String,
pub file_name: String,
}

#[allow(dead_code)]
pub fn create(resource_name: &str) -> Result<Model> {
let resource = generate(resource_name);

Expand All @@ -25,6 +28,7 @@ pub fn create(resource_name: &str) -> Result<Model> {
Ok(resource)
}

#[allow(dead_code)]
fn config(resource_name: &str) -> ModelConfig {
let model_name = resource_name.to_pascal_case();
let file_name = model_name.to_snake_case();
Expand All @@ -37,6 +41,7 @@ fn config(resource_name: &str) -> ModelConfig {
}
}

#[allow(dead_code)]
fn generate(resource_name: &str) -> Model {
let config = config(resource_name);

Expand Down
Loading