diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..551bca2 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,37 @@ +# Use the official Rust image from Docker Hub +FROM rustlang/rust:nightly + +# Install essential tools and dependencies +RUN apt-get update && \ + apt-get install -y \ + build-essential \ + gdb \ + curl \ + sudo \ + fonts-firacode \ + && \ + rm -rf /var/lib/apt/lists/* + +# Install Rust Analyzer +RUN curl -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-linux -o /usr/local/bin/rust-analyzer \ + && chmod +x /usr/local/bin/rust-analyzer + +# Install Starship prompt +RUN curl -fsSL https://starship.rs/install.sh | sh -s -- -y + +# Set up Starship configuration +RUN mkdir ~/.config +RUN echo 'eval "$(starship init bash)"' >> ~/.bashrc +RUN starship preset nerd-font-symbols -o ~/.config/starship.toml + +# Configure font for terminal +ENV DEBIAN_FRONTEND=noninteractive +RUN echo 'export LANG=C.UTF-8' >> ~/.bashrc \ + && echo 'export LC_ALL=C.UTF-8' >> ~/.bashrc \ + && echo 'export TERM=xterm-256color' >> ~/.bashrc \ + && echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc \ + && echo 'export EDITOR=vim' >> ~/.bashrc \ + && echo 'export TZ="America/Sao_Paulo"' >> ~/.bashrc + +# Set up the workspace +WORKDIR /workspace diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..31bd03b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,16 @@ +{ + "name": "Rust Environment", + "dockerFile": "Dockerfile", + "customizations": { + "vscode": { + "extensions": [ + "rust-lang.rust-analyzer" + ], + "settings": { + "rust.target": "x86_64-unknown-linux-gnu", + "terminal.integrated.fontFamily": "FiraCode Nerd Font" + } + } + }, + "postCreateCommand": "chmod +x /usr/local/bin/rust-analyzer" +} \ No newline at end of file diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 0000000..dc9c851 --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,40 @@ +name: Code Coverage + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + +env: + CARGO_TERM_COLOR: always + +jobs: + check: + name: Check + runs-on: ubuntu-latest + + container: + image: xd009642/tarpaulin:develop-nightly + options: --security-opt seccomp=unconfined + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Run `cargo-tarpaulin` + run: | + cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --out xml --fail-under 50 + + - name: Upload to codecov.io + uses: codecov/codecov-action@v1.0.2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Archive Results + uses: actions/upload-artifact@v1 + with: + name: code-coverage-report + path: cobertura.xml diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 0000000..6918191 --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,80 @@ +name: Code Quality + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + +env: + CARGO_TERM_COLOR: always + +jobs: + rust: + name: Check + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Cache `cargo` Registry + uses: actions/cache@v2 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-registry- + + - name: Cache `cargo` Index + uses: actions/cache@v2 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-index- + + - name: Cache `cargo` Build + uses: actions/cache@v2 + with: + path: target + key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-build- + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + components: rustfmt, clippy + + - name: Install Tools + run: | + cargo install cargo-audit + cargo install cargo-udeps + cargo install cargo-sonar + + - name: Run `clippy` + run: cargo clippy --message-format=json > clippy.json || true + + - name: Run `cargo-audit` + run: cargo audit --json > audit.json || true + + - name: Run `cargo-udeps` + run: cargo +nightly udeps --quiet --workspace --output json > udeps.json || true + + - name: Run `cargo-sonar` + run: cargo sonar --clippy --audit --udeps + + - name: Upload to sonarcloud.io + uses: sonarsource/sonarqube-scan-action@v2.3.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} + + - name: Archive Results + uses: actions/upload-artifact@v1 + with: + name: code-quality-report + path: sonar-issues.json \ No newline at end of file diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 2513cdd..6c5a8a2 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -1,25 +1,48 @@ -name: Unit tests +name: Unit Tests +permissions: + checks: write on: - pull_request: + push: branches: - main + pull_request: + types: [opened, synchronize, reopened] env: CARGO_TERM_COLOR: always jobs: test: - name: coverage + name: Check runs-on: ubuntu-latest - container: - image: xd009642/tarpaulin:develop-nightly - options: --security-opt seccomp=unconfined + steps: - - name: Checkout repository - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + with: + fetch-depth: 0 - - name: Generate code coverage + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + + - name: Run `cargo test` run: | - cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --out xml --fail-under 50 + cargo test -- -Z unstable-options --format json --report-time | tee results.json + + - name: Prepare JUnit Report + id: report + uses: innoq/action-cargo-test-report@main + with: + cargo-test-report-json: 'results.json' + - name: Publish Test Report + uses: mikepenz/action-junit-report@main + if: always() + with: + check_name: Report + fail_on_failure: true + require_tests: true + summary: ${{ steps.report.outputs.summary }} diff --git a/Cargo.lock b/Cargo.lock index dfc196d..5b8891c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,7 +130,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -141,7 +141,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -218,9 +218,9 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "blake3" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" +checksum = "3d08263faac5cde2a4d52b513dadb80846023aade56fcd8fc99ba73ba8050e92" dependencies = [ "arrayref", "arrayvec", @@ -228,7 +228,7 @@ dependencies = [ "cfg-if", "constant_time_eq", "memmap2", - "rayon", + "rayon-core", ] [[package]] @@ -271,9 +271,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" [[package]] name = "camino" @@ -283,9 +283,9 @@ checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239" [[package]] name = "cc" -version = "1.0.106" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "066fce287b1d4eafef758e89e09d724a24808a9196fe9756b8ca90e86d0719a2" +checksum = "47de7e88bbbd467951ae7f5a6f34f70d1b4d9cfce53d5fd70f74ebe118b3db56" [[package]] name = "cfg-if" @@ -316,9 +316,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.8" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" +checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" dependencies = [ "clap_builder", "clap_derive", @@ -326,9 +326,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.8" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" +checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" dependencies = [ "anstream", "anstyle", @@ -339,9 +339,9 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.7" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d598e88f6874d4b888ed40c71efbcbf4076f1dfbae128a08a8c9e45f710605d" +checksum = "5b4be9c4c4b1f30b78d8a750e0822b6a6102d97e62061c583a6c1dea2dfb33ae" dependencies = [ "clap", ] @@ -355,7 +355,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -479,12 +479,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.9" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" dependencies = [ - "darling_core 0.20.9", - "darling_macro 0.20.9", + "darling_core 0.20.10", + "darling_macro 0.20.10", ] [[package]] @@ -503,16 +503,16 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.9" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -528,13 +528,13 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.9" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ - "darling_core 0.20.9", + "darling_core 0.20.10", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -588,7 +588,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -807,7 +807,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1041,9 +1041,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.29" +version = "0.14.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33" +checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" dependencies = [ "bytes", "futures-channel", @@ -1447,7 +1447,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1459,7 +1459,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1615,7 +1615,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1691,7 +1691,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1745,7 +1745,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1782,10 +1782,10 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16262fecc7ddfc0bc4969c3b88a7f374baaed607ec098e4c09980beeff03b0a6" dependencies = [ - "darling 0.20.9", + "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -1874,7 +1874,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", "version_check", "yansi", ] @@ -1918,16 +1918,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rayon" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" -dependencies = [ - "either", - "rayon-core", -] - [[package]] name = "rayon-core" version = "1.12.1" @@ -1984,7 +1974,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2139,7 +2129,7 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn 2.0.70", + "syn 2.0.71", "unicode-xid", "version_check", ] @@ -2154,7 +2144,7 @@ dependencies = [ "either", "futures", "http 0.2.12", - "hyper 0.14.29", + "hyper 0.14.30", "indexmap 2.2.6", "log", "memchr", @@ -2307,7 +2297,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2368,7 +2358,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2379,7 +2369,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2438,10 +2428,10 @@ version = "3.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b80d3d6b56b64335c0180e5ffde23b3c5e08c14c585b51a15bd0e95393f46703" dependencies = [ - "darling 0.20.9", + "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2543,7 +2533,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2622,7 +2612,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2644,9 +2634,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.70" +version = "2.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" dependencies = [ "proc-macro2", "quote", @@ -2739,22 +2729,22 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2839,7 +2829,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -2993,7 +2983,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", ] [[package]] @@ -3209,7 +3199,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", "wasm-bindgen-shared", ] @@ -3243,7 +3233,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.71", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..965e25f --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,6 @@ +sonar.host.url=https://sonarcloud.io +sonar.projectKey=postech-5soat-grupo-25_tech-challenge-pedido-produto +sonar.organization=postech-5soat-grupo-25 +sonar.sources=src +sonar.language=rust +sonar.externalIssuesReportPaths=sonar-issues.json diff --git a/src/entities/cpf.rs b/src/entities/cpf.rs index f388970..f23ca31 100644 --- a/src/entities/cpf.rs +++ b/src/entities/cpf.rs @@ -88,4 +88,4 @@ mod tests { let cpf = Cpf::new("wrong".to_string()); assert!(cpf.is_err()); } -} \ No newline at end of file +} diff --git a/src/external/postgres/table.rs b/src/external/postgres/table.rs index 4041670..df9dcaa 100644 --- a/src/external/postgres/table.rs +++ b/src/external/postgres/table.rs @@ -92,4 +92,4 @@ impl Table { let query = format!("{}{})", query, columns_query); query } -} \ No newline at end of file +}