From f5dd3e8aef4c7a943eb6a8c009fd05aa4447ada3 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Thu, 4 Sep 2025 23:31:12 -0400 Subject: [PATCH 1/9] [Github Actions] coverage splitted --- .github/workflows/rust-coverage.yml | 47 ++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust-coverage.yml b/.github/workflows/rust-coverage.yml index 29cff7c..53a58e4 100644 --- a/.github/workflows/rust-coverage.yml +++ b/.github/workflows/rust-coverage.yml @@ -1,6 +1,13 @@ +--- name: Coverage -on: [pull_request, push] +on: # yamllint disable-line rule:truthy + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + workflow_dispatch: jobs: coverage: @@ -14,10 +21,36 @@ jobs: - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov - name: Generate code coverage - run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + run: > + cargo llvm-cov + --all-features + --workspace + --lcov + --output-path lcov.info + - name: Upload coverage artifact + uses: actions/upload-artifact@v4 with: - token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos - files: lcov.info - fail_ci_if_error: true + name: coverage-report + path: lcov.info + + codecov: + name: Upload to Codecov + runs-on: ubuntu-24.04 + needs: coverage + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + with: + fetch-depth: 0 + - name: Download coverage artifact + uses: actions/download-artifact@v5 + with: + name: coverage-report + + - name: Upload coverage reports to Codecov with GitHub Action + uses: codecov/codecov-action@v5 + with: + files: coverage.out + token: ${{ secrets.CODECOV_TOKEN }} # required + verbose: true # optional (default = false) From b8d024ff4a4e8d9c90ab38ab1116d58e287f9262 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Thu, 4 Sep 2025 23:43:23 -0400 Subject: [PATCH 2/9] [Github Actions] sonarcloud added. --- .github/workflows/rust-coverage.yml | 35 ++++++++++++++++++++++++++++- sonar-project.properties | 14 ++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/rust-coverage.yml b/.github/workflows/rust-coverage.yml index 53a58e4..a696798 100644 --- a/.github/workflows/rust-coverage.yml +++ b/.github/workflows/rust-coverage.yml @@ -20,6 +20,13 @@ jobs: run: rustup update stable - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov + - name: Install Clippy + run: rustup component add clippy + - name: Install cargo-sonar and run Clippy + run: | + cargo install cargo-sonar + cargo clippy --message-format json > my-clippy-report.json + cargo sonar --clippy --clippy-path my-clippy-report.json - name: Generate code coverage run: > cargo llvm-cov @@ -31,7 +38,9 @@ jobs: uses: actions/upload-artifact@v4 with: name: coverage-report - path: lcov.info + path: | + lcov.info + sonar-issues.json codecov: name: Upload to Codecov @@ -54,3 +63,27 @@ jobs: files: coverage.out token: ${{ secrets.CODECOV_TOKEN }} # required verbose: true # optional (default = false) + + sonarqube: + name: SonarQube + runs-on: ubuntu-latest + needs: coverage + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + with: + fetch-depth: 0 + - name: Download coverage artifact + uses: actions/download-artifact@v5 + with: + name: coverage-report + - name: SonarCloud Scan + uses: SonarSource/sonarqube-scan-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.externalIssuesReportPaths=sonar-issues.json + -Dcommunity.rust.lcov.reportPaths=lcov.info diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..f78f75c --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,14 @@ +sonar.projectKey=sir-gon_algorithm-exercises-rust +sonar.organization=sir-gon + + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=algorithm-exercises-rust +#sonar.projectVersion=1.0 + + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +#sonar.sources=. + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 \ No newline at end of file From 096780103d4e66583c109f56849b7dccfe47daee Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Fri, 5 Sep 2025 01:01:27 -0400 Subject: [PATCH 3/9] [CONFIG] minimal config files --- .dockerignore | 2 + .editorconfig | 45 ++++++++ .gitignore | 2 + .markdownlint.yaml | 262 +++++++++++++++++++++++++++++++++++++++++++++ .yamlignore | 1 + .yamllint | 19 ++++ 6 files changed, 331 insertions(+) create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 .markdownlint.yaml create mode 100644 .yamlignore create mode 100644 .yamllint diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5874b8c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +target diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f884e93 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,45 @@ +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +trim_trailing_whitespace = true +indent_size = 2 +max_line_length = 80 + +# # Already default setting +# [*.sh] +# indent_size = 4 + +# # Already default setting +# Same as in .clang-format +# [{*.cpp, *.hpp, *.S}] +# indent_size = 4 + +# # Already default setting +# [{*.ld, *.lds}] +# indent_size = 4 + +[*.nix] +indent_size = 2 + +[*.toml] +indent_size = 2 + +[*.yml] +indent_size = 2 + +[*.json] +indent_size = 2 + +[{CMakeLists.txt,*.cmake}] +indent_size = 2 + +[{Makefile,**.mk}] +# Use tabs for indentation (Makefiles require tabs) +indent_style = tab +indent_size = 2 diff --git a/.gitignore b/.gitignore index c8edfc3..59192eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +my-clippy-report.json +sonar-issues.json /target diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..372a750 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,262 @@ +# yamllint disable rule:line-length +--- + +# Example markdownlint configuration with all properties set to their default value + +# Default state for all rules +default: true + +# Path to configuration file to extend +extends: null + +# MD001/heading-increment/header-increment - Heading levels should only increment by one level at a time +MD001: true + +# MD002/first-heading-h1/first-header-h1 - First heading should be a top-level heading +MD002: + # Heading level + level: 1 + +# MD003/heading-style/header-style - Heading style +MD003: + # Heading style + style: "consistent" + +# MD004/ul-style - Unordered list style +MD004: + # List style + style: "consistent" + +# MD005/list-indent - Inconsistent indentation for list items at the same level +MD005: true + +# MD006/ul-start-left - Consider starting bulleted lists at the beginning of the line +MD006: true + +# MD007/ul-indent - Unordered list indentation +MD007: + # Spaces for indent + indent: 2 + # Whether to indent the first level of the list + start_indented: false + # Spaces for first level indent (when start_indented is set) + start_indent: 2 + +# MD009/no-trailing-spaces - Trailing spaces +MD009: + # Spaces for line break + br_spaces: 2 + # Allow spaces for empty lines in list items + list_item_empty_lines: false + # Include unnecessary breaks + strict: false + +# MD010/no-hard-tabs - Hard tabs +MD010: + # Include code blocks + code_blocks: true + # Fenced code languages to ignore + ignore_code_languages: [] + # Number of spaces for each hard tab + spaces_per_tab: 1 + +# MD011/no-reversed-links - Reversed link syntax +MD011: true + +# MD012/no-multiple-blanks - Multiple consecutive blank lines +MD012: + # Consecutive blank lines + maximum: 1 + +# MD013/line-length - Line length +MD013: + # Number of characters + line_length: 80 + # Number of characters for headings + heading_line_length: 80 + # Number of characters for code blocks + code_block_line_length: 80 + # Include code blocks + code_blocks: false + # Include tables + tables: true + # Include headings + headings: true + # Strict length checking + strict: false + # Stern length checking + stern: false + +# MD014/commands-show-output - Dollar signs used before commands without showing output +MD014: true + +# MD018/no-missing-space-atx - No space after hash on atx style heading +MD018: true + +# MD019/no-multiple-space-atx - Multiple spaces after hash on atx style heading +MD019: true + +# MD020/no-missing-space-closed-atx - No space inside hashes on closed atx style heading +MD020: true + +# MD021/no-multiple-space-closed-atx - Multiple spaces inside hashes on closed atx style heading +MD021: true + +# MD022/blanks-around-headings/blanks-around-headers - Headings should be surrounded by blank lines +MD022: + # Blank lines above heading + lines_above: 1 + # Blank lines below heading + lines_below: 1 + +# MD023/heading-start-left/header-start-left - Headings must start at the beginning of the line +MD023: true + +# MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content +MD024: + # Only check sibling headings + siblings_only: false + +# MD025/single-title/single-h1 - Multiple top-level headings in the same document +MD025: + # Heading level + level: 1 + # RegExp for matching title in front matter + front_matter_title: "^\\s*title\\s*[:=]" + +# MD026/no-trailing-punctuation - Trailing punctuation in heading +MD026: + # Punctuation characters not allowed at end of headings + punctuation: ".,;:!。,;:!" + +# MD027/no-multiple-space-blockquote - Multiple spaces after blockquote symbol +MD027: true + +# MD028/no-blanks-blockquote - Blank line inside blockquote +MD028: true + +# MD029/ol-prefix - Ordered list item prefix +MD029: + # List style + style: "one_or_ordered" + +# MD030/list-marker-space - Spaces after list markers +MD030: + # Spaces for single-line unordered list items + ul_single: 1 + # Spaces for single-line ordered list items + ol_single: 1 + # Spaces for multi-line unordered list items + ul_multi: 1 + # Spaces for multi-line ordered list items + ol_multi: 1 + +# MD031/blanks-around-fences - Fenced code blocks should be surrounded by blank lines +MD031: + # Include list items + list_items: true + +# MD032/blanks-around-lists - Lists should be surrounded by blank lines +MD032: true + +# MD033/no-inline-html - Inline HTML +MD033: + # Allowed elements + allowed_elements: [] + +# MD034/no-bare-urls - Bare URL used +MD034: true + +# MD035/hr-style - Horizontal rule style +MD035: + # Horizontal rule style + style: "consistent" + +# MD036/no-emphasis-as-heading/no-emphasis-as-header - Emphasis used instead of a heading +MD036: + # Punctuation characters + punctuation: ".,;:!?。,;:!?" + +# MD037/no-space-in-emphasis - Spaces inside emphasis markers +MD037: true + +# MD038/no-space-in-code - Spaces inside code span elements +MD038: true + +# MD039/no-space-in-links - Spaces inside link text +MD039: true + +# MD040/fenced-code-language - Fenced code blocks should have a language specified +MD040: + # List of languages + allowed_languages: [] + # Require language only + language_only: false + +# MD041/first-line-heading/first-line-h1 - First line in a file should be a top-level heading +MD041: + # Heading level + level: 1 + # RegExp for matching title in front matter + front_matter_title: "^\\s*title\\s*[:=]" + +# MD042/no-empty-links - No empty links +MD042: true + +# MD043/required-headings/required-headers - Required heading structure +MD043: + # List of headings + headings: [ + "*" + ] + # Match case of headings + match_case: false + +# MD044/proper-names - Proper names should have the correct capitalization +MD044: + # List of proper names + names: [] + # Include code blocks + code_blocks: true + # Include HTML elements + html_elements: true + +# MD045/no-alt-text - Images should have alternate text (alt text) +MD045: true + +# MD046/code-block-style - Code block style +MD046: + # Block style + style: "consistent" + +# MD047/single-trailing-newline - Files should end with a single newline character +MD047: true + +# MD048/code-fence-style - Code fence style +MD048: + # Code fence style + style: "consistent" + +# MD049/emphasis-style - Emphasis style should be consistent +MD049: + # Emphasis style should be consistent + style: "consistent" + +# MD050/strong-style - Strong style should be consistent +MD050: + # Strong style should be consistent + style: "consistent" + +# MD051/link-fragments - Link fragments should be valid +MD051: true + +# MD052/reference-links-images - Reference links and images should use a label that is defined +MD052: true + +# MD053/link-image-reference-definitions - Link and image reference definitions should be needed +MD053: + # Ignored definitions + ignored_definitions: + - "//" + +# yamllint enable rule:line-length diff --git a/.yamlignore b/.yamlignore new file mode 100644 index 0000000..544b4c7 --- /dev/null +++ b/.yamlignore @@ -0,0 +1 @@ +.trunk/* diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..b628837 --- /dev/null +++ b/.yamllint @@ -0,0 +1,19 @@ +--- +extends: default + +ignore-from-file: [.gitignore, .yamlignore] + +rules: + comments: + min-spaces-from-content: 1 + +# yamllint disable rule:line-length +# +# References: +# False positive: interpreting GitHub actions "on:" as a truthy value #430 +# https://github.com/adrienverge/yamllint/issues/430 +# +# YAML formatting not compliant with yamllint "spaces before comments" requirement #433 +# https://github.com/redhat-developer/vscode-yaml/issues/433#issuecomment-1235681987 +# +# yamllint enable rule:line-length From 7667bda7e10715eaa4e24beffcf98bfd5d1aab8b Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Fri, 5 Sep 2025 01:01:56 -0400 Subject: [PATCH 4/9] [CONFIG] License file added. --- LICENSE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..ddf374d --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2023 Gonzalo Diaz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 585a531a45f9561522e0116398db69a1b976646f Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Fri, 5 Sep 2025 01:05:10 -0400 Subject: [PATCH 5/9] [CONFIG] [Github Actions] new basic tests --- .github/workflows/gitleaks.yml | 32 +++++++++++++++++++++++ .github/workflows/markdown-lint.yml | 40 +++++++++++++++++++++++++++++ .github/workflows/yamllint.yml | 27 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 .github/workflows/gitleaks.yml create mode 100644 .github/workflows/markdown-lint.yml create mode 100644 .github/workflows/yamllint.yml diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml new file mode 100644 index 0000000..e804ea2 --- /dev/null +++ b/.github/workflows/gitleaks.yml @@ -0,0 +1,32 @@ +--- + +name: gitleaks + +on: # yamllint disable-line rule:truthy + pull_request: + push: + workflow_dispatch: + schedule: + # ┌───────────── minute (0 - 59) + # │ ┌───────────── hour (0 - 23) + # │ │ ┌───────────── day of the month (1 - 31) + # │ │ │ ┌───────────── month (1 - 12 or JAN-DEC) + # │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) + # │ │ │ │ │ + # │ │ │ │ │ + # │ │ │ │ │ + # * * * * * + - cron: "0 6 * * *" # run once a day at 6 AM +jobs: + scan: + name: gitleaks + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + - uses: gitleaks/gitleaks-action@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Only required for Organizations, not personal accounts. + # GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE}} diff --git a/.github/workflows/markdown-lint.yml b/.github/workflows/markdown-lint.yml new file mode 100644 index 0000000..81fe472 --- /dev/null +++ b/.github/workflows/markdown-lint.yml @@ -0,0 +1,40 @@ +--- +name: Markdown Lint + +on: # yamllint disable-line rule:truthy + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + workflow_dispatch: + +permissions: read-all + +jobs: + markdownlint: + name: Markdown Lint + runs-on: ubuntu-24.04 + + strategy: + matrix: + node-version: [22.x] + # See supported Node.js release schedule + # at https://nodejs.org/en/about/releases/ + + steps: + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v5 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install -g markdownlint-cli + + - name: Lint + run: > + markdownlint '**/*.md' --ignore node_modules + && echo '✔ Your code looks good.' diff --git a/.github/workflows/yamllint.yml b/.github/workflows/yamllint.yml new file mode 100644 index 0000000..32a44d5 --- /dev/null +++ b/.github/workflows/yamllint.yml @@ -0,0 +1,27 @@ +--- + +name: YAML lint + +on: # yamllint disable-line rule:truthy + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + workflow_dispatch: + +jobs: + lint: + name: YAML lint + runs-on: ubuntu-24.04 + steps: + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + + - name: Install yamllint + run: pip install yamllint + + - name: Lint YAML files + run: > + yamllint --strict . + && echo '✔ Your code looks good.' From 70ec1941d7eba933cdc11b53cfc79ace85acce05 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Fri, 5 Sep 2025 01:06:38 -0400 Subject: [PATCH 6/9] [CONFIG] [Github Actions] Rust test file fixed. --- .github/workflows/rust.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3874441..105b85e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,10 +1,13 @@ +--- name: Rust -on: +on: # yamllint disable-line rule:truthy push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + # The branches below must be a subset of the branches above + branches: ["main"] + workflow_dispatch: env: CARGO_TERM_COLOR: always @@ -15,8 +18,8 @@ jobs: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v4 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - uses: actions/checkout@v4 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose From c5b735bf9609bdaad11d47314fcf3776c45d1ef8 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Fri, 5 Sep 2025 01:06:53 -0400 Subject: [PATCH 7/9] [CONFIG] Makefile added. --- Makefile | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6126b1b --- /dev/null +++ b/Makefile @@ -0,0 +1,129 @@ +## REFERENCES: +## (1) Passing environment variable with fallback value to Makefile: +## https://stackoverflow.com/a/70772707/6366150 +## (2) Export environment variables inside "make environment" +## https://stackoverflow.com/a/49524393/6366150 +## (3) Uppercase to lowercase and vice versa +## https://community.unix.com/t/uppercase-to-lowercase-and-vice-versa/285278/6 +## (4) How do I trim leading and trailing whitespace from each line of some output? +## https://unix.stackexchange.com/a/279222/233927 +############################################################################ + +## (1) ## Allowed values: info | warn | error | debug +LOG_LEVEL ?= info +## (3) (4) +LOG_LEVEL :=$(shell echo '${LOG_LEVEL}'| tr '[:lower:]' '[:upper:]'| tr -d '[:blank:]') + +## (1) ## Allowed values: true | false +BRUTEFORCE ?= false +## (3) (4) +BRUTEFORCE :=$(shell echo '${BRUTEFORCE}'| tr '[:lower:]' '[:upper:]'| tr -d '[:blank:]') + +# DOCKER +DOCKER_COMPOSE=docker compose + +# Package Manager +PACKAGE_MANAGER=cargo + +# DOCKER +# BUILDKIT_PROGRESS=plain +# CGO_ENABLED=0 + +.MAIN: test/coverage +.PHONY: all clean coverage dependencies help list test +.EXPORT_ALL_VARIABLES: # (2) + +help: list + +list: + @echo "Environment variables:" + @echo "LOG_LEVEL = info | warn | error | debug" + @echo "BRUTEFORCE = true | false" + @echo "" + @echo "Posible make commands:" + @LC_ALL=C $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' + +env: + @echo "################################################################################" + @echo "## Environment: ################################################################" + @echo "################################################################################" + @printenv | grep -E "LOG_LEVEL|BRUTEFORCE" + @echo "################################################################################" + +dependencies: + @echo "################################################################################" + @echo "## Dependencies: ###############################################################" + @echo "################################################################################" + $(PACKAGE_MANAGER) build --locked + @echo "################################################################################" + +lint/markdown: + markdownlint '**/*.md' --ignore node_modules && echo '✔ Your code looks good.' + +lint/yaml: + yamllint --stric . && echo '✔ Your code looks good.' + +lint: lint/markdown lint/yaml test/styling test/static + +test/static: dependencies + +test/styling: dependencies + +format: + +test: env dependencies + $(PACKAGE_MANAGER) test + +coverage: test + $(PACKAGE_MANAGER) llvm-cov --all-features --workspace --lcov --output-path lcov.info + +coverage/html: + +outdated: + +update: dependencies outdated + +upgrade: update + +clean: + rm -vfr ./target || true + mkdir -p ./target + touch ./target/.gitkeep + +build: env dependencies + $(PACKAGE_MANAGER) build + +# compose/build: env +# ${DOCKER_COMPOSE} --profile lint build +# ${DOCKER_COMPOSE} --profile testing build +# ${DOCKER_COMPOSE} --profile production build + +# compose/rebuild: env +# ${DOCKER_COMPOSE} --profile lint build --no-cache +# ${DOCKER_COMPOSE} --profile testing build --no-cache +# ${DOCKER_COMPOSE} --profile production build + +# compose/lint/markdown: compose/build +# ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-go-lint make lint/markdown + +# compose/lint/yaml: compose/build +# ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-go-lint make lint/yaml + +# compose/test/styling: compose/build +# ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-go-lint make test/styling + +# compose/test/static: compose/build +# ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-go-lint make test/static + +# compose/lint: compose/lint/markdown compose/lint/yaml compose/test/styling compose/test/static + +# compose/test: compose/build +# ${DOCKER_COMPOSE} --profile testing run --rm algorithm-exercises-go-test make test + +# compose/run: compose/build +# ${DOCKER_COMPOSE} --profile production run --rm algorithm-exercises-go + +all: test coverage + +run: + ls -alh From 89a1f89066dafe079c84dcf744be6bd7ac5fad4e Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Fri, 5 Sep 2025 01:10:02 -0400 Subject: [PATCH 8/9] [CONFIG] [Github Actions] Rust test on multiple OS. --- .github/workflows/rust.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 105b85e..11af230 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,8 +14,12 @@ env: jobs: build: - - runs-on: ubuntu-24.04 + name: "RUST Build and Test" + strategy: + fail-fast: false + matrix: + os: ["windows-2022", "ubuntu-24.04", "macos-14"] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 From e20997a9071c65d4432bd6af30b135c97527b43d Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Fri, 5 Sep 2025 01:07:10 -0400 Subject: [PATCH 9/9] Readme file added. --- README.md | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f4905c0 --- /dev/null +++ b/README.md @@ -0,0 +1,200 @@ +# Algorithm Exercises (Rust 🦀) + +[![Rust on Linux CI Test](https://github.com/sir-gon/algorithm-exercises-rust/actions/workflows/rust.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-rust/actions/workflows/rust.yml) + +[![Markdown Lint](https://github.com/sir-gon/algorithm-exercises-rust/actions/workflows/markdown-lint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-rust/actions/workflows/markdown-lint.yml) +[![YAML lint](https://github.com/sir-gon/algorithm-exercises-rust/actions/workflows/yamllint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-rust/actions/workflows/yamllint.yml) + +![GitHub](https://img.shields.io/github/license/sir-gon/algorithm-exercises-rust) +![GitHub language count](https://img.shields.io/github/languages/count/sir-gon/algorithm-exercises-rust) +![GitHub top language](https://img.shields.io/github/languages/top/sir-gon/algorithm-exercises-rust) + +[![codecov](https://codecov.io/gh/sir-gon/algorithm-exercises-rust/branch/main/graph/badge.svg?token=YZ41BE67E4)](https://codecov.io/gh/sir-gon/algorithm-exercises-rust) + +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-rust&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-rust&metric=coverage)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) +[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-rust&metric=bugs)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) +[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-rust&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) +[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-rust&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) + +## TL;DR + +Algorithms Exercises solved in [Rust](https://www.rust-lang.org/) +Developed with TDD. + +[![Rust]( https://img.shields.io/badge/Rust-000000?style=for-the-badge&logo=rust&logoColor=white)](https://gcc.gnu.org/onlinedocs/gcc/Standards.html#C-Language) +[![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)](https://www.docker.com/) + +Go to [Install and run](#install-and-run) + +## What is this? + +This repository is part of a series that share and solve the same [objectives](#objetives), +with the difference that each one is based on a different software ecosystem, +depending on the chosen programming language: + +- [Modern Javascript: algorithm-exercises-js](https://github.com/sir-gon/algorithm-exercises-js) +- [Typescript: algorithm-exercises-ts](https://github.com/sir-gon/algorithm-exercises-ts) + +- [Python 3.x: algorithm-exercises-py](https://github.com/sir-gon/algorithm-exercises-py) +- [Go / Golang: algorithm-exercises-go](https://github.com/sir-gon/algorithm-exercises-go) + +- [Java: algorithm-exercises-java](https://github.com/sir-gon/algorithm-exercises-java) +- [.NET / C#: algorithm-exercises-rustsharp](https://github.com/sir-gon/algorithm-exercises-rustsharp) +- [C++17: algorithm-exercises-rustpp](https://github.com/sir-gon/algorithm-exercises-rustsharp-cpp) + +## Objetives + +### Functional + +- For academic purposes, it is an backup of some algorithm exercises +(with their solutions), proposed by various sources: +[leetcode, hackerrank, projecteuler](#algorithm-excersices-sources), ... + +- The solutions must be written on "vanilla code", that is, +avoiding as much as possible the use of external libraries (in runtime). + +- Adoption of methodology and good practices. +Each exercise is implemented as a unit test set, +using TDD (Test-driven Development) and Clean Code ideas. + +### Technical + +Foundation of a project that supports: + +- Explicit **typing** when the language supports it, even when it is not mandatory. +- Static Code Analysis (**Lint**) of code, scripts and documentation. +- Uniform **Code Styling**. +- **Unit Test** framework. +- **Coverge** collection. High coverage percentage. Equal or close to 100%. +- **Pipeline** (Github Actions). Each command must take care of its +return status code. +- **Docker**-based workflow to replicate behavior in any environment. +- Other tools to support the reinforcement of software development **good practices**. + +## Install and Run + +- (⭐️) [Install and run directly with make](#install-and-run-directly-with-make) +require Rust tools installed in your SO. + + + + +### Install and run directly with make + +It is assumed that the following tools have already been installed: + +- [**Install Rust**](https://www.rust-lang.org/tools/install) + +Using Rust tools in your SO. You must install dependencies: + +```bash +make dependencies +make lint # optional +make build +make test +``` + + +## About development + +```sh +rustc --version +``` + +```text +rustc 1.89.0 (29483883e 2025-08-04) +``` + +--- + +```sh +cargo --version +``` + +```text +cargo 1.89.0 (c24e10642 2025-06-23) +``` + +--- + +```sh +rustup --version +``` + +```text +rustup 1.28.2 (e4f3ad6f8 2025-04-28) +info: This is the version for the rustup toolchain manager, not the rustc compiler. +info: The currently active `rustc` version is `rustc 1.89.0 (29483883e 2025-08-04)` +``` + +## Algorithm excersices sources + +- [Leetcode](https://leetcode.com/) online platform for +coding interview preparation. +- [HackerRank](https://www.hackerrank.com/) competitive programming challenges +for both consumers and businesses. +- [Project Euler](https://projecteuler.net/) a series of computational problems +intended to be solved with computer programs. + +Use these answers to learn some tip and tricks for algorithms tests. + +### Disclaimer. Why I publish solutions? + +As Project Euler says: + + + +```text +I learned so much solving problem XXX, so is it okay to publish my solution elsewhere? +It appears that you have answered your own question. There is thing quite like that "Aha!" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, that will rarely be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself. + +However, the rule about sharing solutions outside of Project Euler does not apply to the first one-hundred problems, as long as any discussion clearly aims to instruct methods, not just provide answers, and does not directly threaten to undermine the enjoyment of solving later problems. Problems 1 to 100 provide a wealth of helpful introductory teaching material and if you are able to respect our requirements, then we give permission for those problems and their solutions to be discussed elsewhere. +``` + +If you have better answers or optimal solutions, fork and PR-me + +Enjoy 😁 ! + +## Status + +### License + +[LICENSE.md](LICENSE.md) + +### Coverage + +[![Coverage](https://codecov.io/gh/sir-gon/algorithm-exercises-rust/graphs/tree.svg?token=Q3B4ZT87O5)](https://codecov.io/gh/sir-gon/algorithm-exercises-rust)