Skip to content

Commit

Permalink
Merge pull request #2 from postech-5soat-grupo-25/test/fase-4/adding-…
Browse files Browse the repository at this point in the history
…code-quality-ci-jobs

adding new code-quality ci steps
  • Loading branch information
alanmmolina authored Jul 14, 2024
2 parents faeacdf + 8f91cc0 commit 5d4ce95
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 82 deletions.
37 changes: 37 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
40 changes: 40 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -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
80 changes: 80 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 33 additions & 10 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Loading

0 comments on commit 5d4ce95

Please sign in to comment.