From 775f05d696514863c436a513330367bae481ad46 Mon Sep 17 00:00:00 2001 From: goose Date: Sun, 15 Feb 2026 19:57:03 -0300 Subject: [PATCH] feat(ci): Add Forgejo CI/CD pipeline for linting and building - Automated linting with rustfmt and clippy - Automated building and testing - Automated Docker image builds - Clippy and rustfmt configuration files --- .forgejo/workflows/lint-and-build.yml | 123 ++++++++++++++++++++++++++ FORGEJO-CI-CD-PIPELINE.md | 73 +++++++++++++++ backend/clippy.toml | 27 ++++++ backend/rustfmt.toml | 15 ++++ 4 files changed, 238 insertions(+) create mode 100644 .forgejo/workflows/lint-and-build.yml create mode 100644 FORGEJO-CI-CD-PIPELINE.md create mode 100644 backend/clippy.toml create mode 100644 backend/rustfmt.toml diff --git a/.forgejo/workflows/lint-and-build.yml b/.forgejo/workflows/lint-and-build.yml new file mode 100644 index 0000000..879c653 --- /dev/null +++ b/.forgejo/workflows/lint-and-build.yml @@ -0,0 +1,123 @@ +name: Lint and Build + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: rustfmt, clippy + override: true + + - name: Cache cargo registry + uses: actions/cache@v3 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo index + uses: actions/cache@v3 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo build + uses: actions/cache@v3 + with: + path: backend/target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + - name: Run rustfmt + working-directory: ./backend + run: | + cargo fmt --all -- --check + + - name: Run clippy + working-directory: ./backend + run: | + cargo clippy --all-targets --all-features -- -D warnings + + build: + name: Build + runs-on: ubuntu-latest + needs: lint + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Cache cargo registry + uses: actions/cache@v3 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo index + uses: actions/cache@v3 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo build + uses: actions/cache@v3 + with: + path: backend/target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + - name: Build project + working-directory: ./backend + run: | + cargo build --verbose + + - name: Run tests + working-directory: ./backend + run: | + cargo test --verbose + + docker-build: + name: Docker Build + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + working-directory: ./backend + run: | + docker build -f docker/Dockerfile -t normogen-backend:test . + + - name: Build Docker image (dev) + working-directory: ./backend + run: | + docker build -f docker/Dockerfile.dev -t normogen-backend:dev-test . diff --git a/FORGEJO-CI-CD-PIPELINE.md b/FORGEJO-CI-CD-PIPELINE.md new file mode 100644 index 0000000..c6832d9 --- /dev/null +++ b/FORGEJO-CI-CD-PIPELINE.md @@ -0,0 +1,73 @@ +# Forgejo CI/CD Pipeline + +## Status: ✅ Implemented + +**Date**: 2026-02-15 19:55:00 UTC + +--- + +## Pipeline Stages + +### 1. Lint Job +- Check code formatting with rustfmt +- Run clippy linter with strict rules + +### 2. Build Job +- Build all targets with cargo +- Run all tests + +### 3. Docker Build Job +- Build production Docker image +- Build development Docker image + +--- + +## Trigger Events + +- Push to main branch +- Push to develop branch +- Pull requests to main/develop + +--- + +## Configuration Files + +- .forgejo/workflows/lint-and-build.yml +- backend/clippy.toml +- backend/rustfmt.toml + +--- + +## Running Locally + +### Check formatting +```bash +cd backend +cargo fmt --all -- --check +cargo fmt --all # to fix +``` + +### Run clippy +```bash +cd backend +cargo clippy --all-targets --all-features -- -D warnings +``` + +### Build +```bash +cd backend +cargo build --verbose +``` + +### Run tests +```bash +cd backend +cargo test --verbose +``` + +--- + +## Viewing Results + +After pushing, go to: +http://gitea.soliverez.com.ar/alvaro/normogen/actions diff --git a/backend/clippy.toml b/backend/clippy.toml new file mode 100644 index 0000000..11b23ad --- /dev/null +++ b/backend/clippy.toml @@ -0,0 +1,27 @@ +# Clippy configuration + +# Allow certain warnings for development +ambiguous-glob-reexports = "allow" +cast-lossless = "allow" +doc-markdown = "warn" +empty-structs-with-brackets = "warn" +explicit-auto-deref = "warn" +if-then-some-else-none = "warn" +match-wildcard-for-single-variants = "warn" +missing-errors-doc = "warn" +missing-panics-doc = "warn" +missing-safety-doc = "warn" +semicolon-if-nothing-returned = "warn" +unreadable-literal = "warn" +unused-self = "warn" +used-underscore-binding = "warn" + +# Deny certain lints +missing-docs-in-private-items = "warn" +unwrap-used = "warn" +expect-used = "warn" +indexing-slicing = "warn" +panic = "deny" +unimplemented = "warn" +todo = "warn" +unreachable = "warn" diff --git a/backend/rustfmt.toml b/backend/rustfmt.toml new file mode 100644 index 0000000..e8840c9 --- /dev/null +++ b/backend/rustfmt.toml @@ -0,0 +1,15 @@ +# Rustfmt configuration + +max_width = 100 +hard_tabs = false +tab_spaces = 4 +newline_style = "Unix" +use_small_heuristics = "Default" +reorder_imports = true +reorder_modules = true +remove_nested_parens = true +edition = "2021" +merge_derives = true +use_try_shorthand = true +use_field_init_shorthand = true +force_explicit_abi = true