Skip to content
Merged
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
45 changes: 45 additions & 0 deletions .github/workflows/bundler-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Bundler Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
bundler-tests:
name: Bundler Integration Tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Docker image
run: docker build -f Dockerfile.dev -t metassr-test .

- name: Run bundler tests in Docker
run: |
docker run --rm -v $(pwd)/tests/web-app/dist:/root/tests/web-app/dist metassr-test bash -c "
# Run the build
cd /root/tests/web-app
npm run build

# Copy the test script into the container and run it
cp /root/tests/test-bundle.sh ./
chmod +x test-bundle.sh
./test-bundle.sh
"

- name: Upload dist artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: bundler-dist-output
path: tests/web-app/dist/
retention-days: 7
40 changes: 40 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Rust Clippy

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
clippy:
name: Run Clippy
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}

- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
29 changes: 29 additions & 0 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Rust Formatting

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
fmt:
name: Check Formatting
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Check formatting
run: cargo fmt --check
89 changes: 0 additions & 89 deletions .github/workflows/test.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Spell Checker action
on: [pull_request, push]

jobs:
run:
name: Start Spell Checking with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v2

- name: Check spelling of * Files
uses: crate-ci/typos@master
with:
files: ./*
31 changes: 31 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Rust Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test:
name: Run Rust Tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Docker image
run: docker build -f Dockerfile.dev -t metassr-test .

- name: Run Rust tests in Docker
run: |
docker run --rm metassr-test bash -c "
cd /root
cargo test --verbose
"
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## TODO

#### Main features
- [x] Serving staic files are located in ``./static/**``
- [x] Serving static files are located in ``./static/**``

- [x] the HTML builder

Expand Down
2 changes: 1 addition & 1 deletion crates/metassr-build/src/server/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl ManifestGenerator {
}
}
pub fn generate<H: AsRef<OsStr> + ?Sized>(&self, head: &H) -> Result<Manifest> {
let cache_path = self.cache.path();
let cache_path = self.cache.path();
let global = GlobalEntry::new(head, cache_path)?;
let mut manifest = Manifest::new(global);

Expand Down
5 changes: 1 addition & 4 deletions crates/metassr-build/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ impl Build for ServerSideBuilder {
};

let bundling_targets = targets.ready_for_bundling(&self.dist_path);
let bundler = WebBundler::new(
&bundling_targets,
&self.dist_path,
)?;
let bundler = WebBundler::new(&bundling_targets, &self.dist_path)?;

if let Err(e) = bundler.exec() {
return Err(anyhow!("Bundling failed: {e}"));
Expand Down
3 changes: 1 addition & 2 deletions crates/metassr-build/src/server/renderer/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ impl HeadRenderer {
let bundling_targets = self.bundling_target()?;
let bundler = WebBundler::new(&bundling_targets, self.cache_dir.path())?;

if let Err(e) = bundler.exec()
{
if let Err(e) = bundler.exec() {
return Err(anyhow!("Cannot bundling head: {e}"));
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/metassr-build/src/server/renderer/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use anyhow::Result;
use html_generator::{
builder::{HtmlBuilder, HtmlOutput},
html_props::{HtmlPropsBuilder},
html_props::HtmlPropsBuilder,
template::HtmlTemplate,
};
use metassr_fs_analyzer::dist_dir::PageEntry;
Expand Down
2 changes: 1 addition & 1 deletion crates/metassr-build/src/server/renderer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod head;
pub mod html;
pub mod page;
pub mod page;
7 changes: 4 additions & 3 deletions crates/metassr-build/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use std::{

pub fn setup_page_path(page: &str, ext: &str) -> PathBuf {
match Path::new(page) {
path if path.file_stem() != Some(OsStr::new("index")) => {
path.to_path_buf().with_extension("").join(format!("index.{ext}"))
}
path if path.file_stem() != Some(OsStr::new("index")) => path
.to_path_buf()
.with_extension("")
.join(format!("index.{ext}")),

path => path.to_path_buf().with_extension(ext),
}
Expand Down
10 changes: 5 additions & 5 deletions crates/metassr-bundler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ lazy_static! {
static ref IS_BUNDLING_SCRIPT_LOADED: Mutex<CheckerState> = Mutex::new(CheckerState::default());

/// A simple checker to check if the bundling function is done or not. It is used to block the program until bundling done.
static ref IS_COMPLIATION_WAIT: Arc<CompilationWait> = Arc::new(CompilationWait::default());
static ref IS_COMPILATION_WAIT: Arc<CompilationWait> = Arc::new(CompilationWait::default());
}
static BUILD_SCRIPT: &str = include_str!("./bundle.js");
const BUNDLING_FUNC: &str = "web_bundling";
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<'a> WebBundler<'a> {

// Resolve callback when the bundling process is completed successfully
fn resolve(result: Box<dyn MetaCallValue>, _: Box<dyn Any>) -> Box<dyn MetaCallValue> {
let compilation_wait = &*Arc::clone(&IS_COMPLIATION_WAIT);
let compilation_wait = &*Arc::clone(&IS_COMPILATION_WAIT);
let mut started = compilation_wait.checker.lock().unwrap();

// Mark the process as completed and notify waiting threads
Expand All @@ -123,7 +123,7 @@ impl<'a> WebBundler<'a> {

// Reject callback for handling errors during the bundling process
fn reject(err: Box<dyn MetaCallValue>, _: Box<dyn Any>) -> Box<dyn MetaCallValue> {
let compilation_wait = &*Arc::clone(&IS_COMPLIATION_WAIT);
let compilation_wait = &*Arc::clone(&IS_COMPILATION_WAIT);
let mut started = compilation_wait.checker.lock().unwrap();

// Log the bundling error and mark the process as completed
Expand Down Expand Up @@ -151,12 +151,12 @@ impl<'a> WebBundler<'a> {
future.then(resolve).catch(reject).await_fut();

// Lock the mutex and wait for the bundling process to complete
let compilation_wait = Arc::clone(&IS_COMPLIATION_WAIT);
let compilation_wait = Arc::clone(&IS_COMPILATION_WAIT);
let mut started = compilation_wait.checker.lock().unwrap();

// Block the current thread until the bundling process signals completion
while !started.is_true() {
started = Arc::clone(&IS_COMPLIATION_WAIT).cond.wait(started).unwrap();
started = Arc::clone(&IS_COMPILATION_WAIT).cond.wait(started).unwrap();
}

// Reset the checker state to false after the process completes
Expand Down
4 changes: 2 additions & 2 deletions crates/metassr-fs-analyzer/src/dist_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl PageEntry {
/// ```no_run
/// use metassr_fs_analyzer::dist_dir::PageEntry;
/// use std::path::PathBuf;
///
///
/// let page_entry = PageEntry::new(PathBuf::from("/dist/pages/home"));
/// println!("{:?}", page_entry.path);
/// ```
Expand Down Expand Up @@ -164,7 +164,7 @@ impl DistDir {
///
/// ```no_run
/// use metassr_fs_analyzer::{dist_dir::DistDir, DirectoryAnalyzer};
///
///
/// let dist_dir = DistDir::new("/path/to/dist").unwrap();
/// let result = dist_dir.analyze().unwrap();
/// for (page, entry) in result.pages {
Expand Down
4 changes: 3 additions & 1 deletion crates/metassr-server/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl<'a, S: Clone + Send + Sync + 'static> PagesHandler<'a, S> {
pub fn build(&mut self) -> Result<()> {
for (route, entries) in self.pages.iter() {
let html = match self.running_type {
RunningType::StaticSiteGeneration => Box::new(read_to_string(entries.path.join("index.html"))?),
RunningType::StaticSiteGeneration => {
Box::new(read_to_string(entries.path.join("index.html"))?)
}
RunningType::ServerSideRendering => {
Box::new(PageRenderer::from_manifest(&self.dist_dir, route)?.render()?)
}
Expand Down
Loading
Loading