From ed2fedd09c6b465bc747272f38c68c2a3494514b Mon Sep 17 00:00:00 2001 From: Phosphorus-M Date: Sat, 11 Jan 2025 12:52:42 -0300 Subject: [PATCH] feat: add GitHub Actions workflow for CloudFlare deployment and update main function for error handling --- .github/workflows/deploy.yml | 58 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 +++ src/main.rs | 36 ++++++++++++---------- 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e69de29..feadde2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -0,0 +1,58 @@ +name: Deploy to CloudFlare Pages +on: + workflow_dispatch: + push: + branches: + - main + paths: + - '.github/workflows/pages.yml' + - 'src/**.rs' + - 'build.rs' + - 'input.css' + - 'package.json' + - 'tailwind.config.js' + +permissions: + contents: read + pages: write + id-token: write + +jobs: + build: + runs-on: macos-15 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: "recursive" + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2025-01-10 + target: wasm32-unknown-unknown + + - uses: Swatinem/rust-cache@v2 + + - name: Pre Build + run: | + npm i + - name: Build + run: | + cargo install --locked cargo-leptos + cargo leptos serve -r + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + path: ./dist + + deploy: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/download-artifact@v4 + - name: Deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: pages deploy ./artifact --project-name=homepage \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 5239f49..0666c98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,10 @@ ssr = [ "leptos_meta/ssr", "leptos_router/ssr", ] +development = [] + +[target.aarch64-apple-darwin] +rustflags = [ "-C", "link-arg=-fuse-ld=lld"] # Defines a size-optimized profile for the WASM bundle in release mode [profile.wasm-release] diff --git a/src/main.rs b/src/main.rs index d03e3eb..73055a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #[cfg(feature = "ssr")] #[tokio::main] -async fn main() { +async fn main() -> Result<(), Box> { use axum::Router; use leptos::logging::log; use leptos::prelude::*; @@ -19,21 +19,27 @@ async fn main() { static_route_generator.generate(&leptos_options).await; - let app = Router::new() - .leptos_routes(&leptos_options, routes, { - let leptos_options = leptos_options.clone(); - move || shell(leptos_options.clone()) - }) - .fallback(leptos_axum::file_and_error_handler(shell)) - .with_state(leptos_options); + #[cfg(feature = "development")] + { + let app = Router::new() + .leptos_routes(&leptos_options, routes, { + let leptos_options = leptos_options.clone(); + move || shell(leptos_options.clone()) + }) + .fallback(leptos_axum::file_and_error_handler(shell)) + .with_state(leptos_options); - // run our app with hyper - // `axum::Server` is a re-export of `hyper::Server` - log!("listening on http://{}", &addr); - let listener = tokio::net::TcpListener::bind(&addr).await.unwrap(); - axum::serve(listener, app.into_make_service()) - .await - .unwrap(); + // run our app with hyper + // `axum::Server` is a re-export of `hyper::Server` + log!("listening on http://{}", &addr); + let listener = tokio::net::TcpListener::bind(&addr).await.unwrap(); + axum::serve(listener, app.into_make_service()) + .await + .unwrap(); + Ok(()) + } + #[cfg(not(feature = "development"))] + Ok(()) } #[cfg(not(feature = "ssr"))]