Skip to content

Commit

Permalink
chore: add checks and formatting (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored Mar 12, 2024
1 parent 4d57156 commit ade668a
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 4,670 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
end_of_line = lf
charset = utf-8
indent_style = space
trim_trailing_whitespace = true
indent_size = 2

[*.rs]
indent_size = 4
14 changes: 14 additions & 0 deletions .github/actions/get-toolchain/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Get Rust toolchain configuration
description: Get the Rust toolchain configuration for the current project defined in the `rust-toolchain` file
outputs:
channel:
description: The Rust toolchain channel
value: ${{ steps.get-toolchain.outputs.channel }}
runs:
using: composite
steps:
- id: get-toolchain
shell: sh
run: |
echo "channel=$(grep channel -i rust-toolchain.toml | cut -d '"' -f2)" \
>> $GITHUB_OUTPUT
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: CI

on:
push:
branches:
- main
tags:
- v*
pull_request:
workflow_dispatch:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get toolchain
id: toolchain
uses: ./.github/actions/get-toolchain
- name: Setup Rust
uses: hecrj/setup-rust-action@v2
with:
rust-version: ${{ steps.toolchain.outputs.channel }}
targets: wasm32-unknown-unknown
- name: Install cargo binstall
uses: cargo-bins/cargo-binstall@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-make
run: cargo binstall -y cargo-make
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Lint
run: cargo make lint

build-example:
name: Build example
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- example: demo
builder: trunk
- example: ssr-demo
builder: cargo-leptos
steps:
- uses: actions/checkout@v4
- name: Get toolchain
id: toolchain
uses: ./.github/actions/get-toolchain
- name: Setup Rust
uses: hecrj/setup-rust-action@v2
with:
rust-version: ${{ steps.toolchain.outputs.channel }}
targets: wasm32-unknown-unknown
- name: Install cargo binstall
uses: cargo-bins/cargo-binstall@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install builder
run: cargo binstall -y ${{ matrix.builder }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ matrix.example }}-${{ matrix.builder }}-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
- name: Build with trunk
if: ${{ matrix.builder == 'trunk' }}
run: |
cd examples/${{ matrix.example }}
trunk build --release
- name: Build with cargo-leptos
if: ${{ matrix.builder == 'cargo-leptos' }}
run: |
cd examples/${{ matrix.example }}
cargo leptos build --release
22 changes: 0 additions & 22 deletions .github/workflows/csr.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/hydrate.yml

This file was deleted.

17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing guide

## Setup

In order to execute development tasks, you need to install [cargo-make](https://github.com/sagiegurari/cargo-make).

## Lint

```sh
cargo make lint
```

## Format

```sh
cargo make format
```
26 changes: 13 additions & 13 deletions Cargo.lock

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

74 changes: 74 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[config]
default_to_workspace = false

[tasks.lint]
description = "Check format of files and run linters"
run_task = { name = ["lint-rs"] }

[tasks.lint-rs]
description = "Lint Rust code"
run_task = { name = ["clippy", "cargo-check", "format-check"] }

[tasks.clippy]
clear = true
description = "Run clippy"
run_task = { name = [
"clippy-no-features",
"clippy-debug",
"clippy-ssr"
] }

# TODO: Remove ["-W", "clippy::empty-docs"] when the next issue is resolved:
# https://github.com/leptos-rs/leptos/issues/2406
[tasks.clippy-no-features]
install_crate = "clippy"
command = "cargo"
args = ["clippy", "--", "-Dwarnings", "-A", "clippy::empty-docs"]

[tasks.clippy-debug]
install_crate = "clippy"
command = "cargo"
args = ["clippy", "--features=debug", "--", "-Dwarnings", "-A", "clippy::empty-docs"]

[tasks.clippy-ssr]
install_crate = "clippy"
command = "cargo"
args = ["clippy", "--features=ssr", "--", "-Dwarnings", "-A", "clippy::empty-docs"]

[tasks.cargo-check]
clear = true
description = "Run cargo-check"
run_task = { name = [
"cargo-check-no-features",
"cargo-check-debug",
"cargo-check-ssr"
] }

[tasks.cargo-check-no-features]
command = "cargo"
args = ["check"]

[tasks.cargo-check-debug]
command = "cargo"
args = ["check", "--features=debug"]

[tasks.cargo-check-ssr]
command = "cargo"
args = ["check", "--features=ssr"]

[tasks.format-check]
description = "Check Rust code formatting with rustfmt"
install_crate = "rustfmt"
command = "cargo"
args = ["fmt", "--all", "--check"]

[tasks.format]
clear = true
description = "Format files"
run_task = { name = ["format-rs"] }

[tasks.format-rs]
description = "Format Rust code with rustfmt"
install_crate = "rustfmt"
command = "cargo"
args = ["fmt", "--all"]
Loading

0 comments on commit ade668a

Please sign in to comment.