From 901dacebef9af1e491759abfd9823a56baa1d610 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Sun, 9 Jun 2024 20:05:39 -0400 Subject: [PATCH 1/4] [CONFIG] [Docker] [make] New config file for yamllint tool --- .yamlignore | 1 + .yamllint | 19 +++++++++++++++++++ Dockerfile | 6 ++++-- Makefile | 22 +++++++++++++++------- compose.yaml | 4 ++-- 5 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 .yamlignore create mode 100644 .yamllint 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..32a0485 --- /dev/null +++ b/.yamllint @@ -0,0 +1,19 @@ +--- +extends: default + +ignore-from-file: .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 diff --git a/Dockerfile b/Dockerfile index 3bdcbc2..da8afec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,13 +5,15 @@ ENV WORKDIR=/app WORKDIR ${WORKDIR} ############################################################################### -FROM node:20.14.0-alpine3.20 AS mdlint +FROM base AS lint ENV WORKDIR=/app WORKDIR ${WORKDIR} COPY ./docs ${WORKDIR}/docs -RUN apk add --update --no-cache make +RUN apk add --update --no-cache make nodejs npm +RUN apk add --update --no-cache yamllint + RUN npm install -g --ignore-scripts markdownlint-cli ############################################################################### diff --git a/Makefile b/Makefile index 2147745..1997cc0 100644 --- a/Makefile +++ b/Makefile @@ -69,10 +69,12 @@ dependencies: ${PACKAGE_TOOL} restore --verbosity ${VERBOSITY_LEVEL} @echo "################################################################################" -mdlint: - markdownlint '**/*.md' --ignore '**/bin/*' && echo '✔ Your code looks good.' +lint/markdown: + markdownlint '**/*.md' --ignore node_modules && echo '✔ Your code looks good.' +lint/yaml: + yamllint --stric . && echo '✔ Your code looks good.' -lint: test/static test/styling mdlint +lint: lint/markdown lint/yaml test/styling test/static test/static: dependencies @@ -115,20 +117,26 @@ clean: find ${TEST_PROJECT_DIRECTORY} -path "*/obj/*" -print -exec rm -fr {} ';' || true compose/build: env + docker-compose --profile lint build docker-compose --profile testing build compose/rebuild: env docker-compose --profile lint build --no-cache docker-compose --profile testing build --no-cache -compose/mdlint: env - docker-compose --profile lint build - docker-compose --profile lint run --rm algorithm-exercises-csharp-mdlint make mdlint +compose/lint/markdown: compose/build + docker-compose --profile lint run --rm algorithm-exercises-csharp-lint make lint/markdown + +compose/lint/yaml: compose/build + docker-compose --profile lint run --rm algorithm-exercises-csharp-lint make lint/yaml + +compose/test/styling: compose/build + docker-compose --profile lint run --rm algorithm-exercises-csharp-lint make test/styling compose/test/static: compose/build docker-compose --profile testing run --rm algorithm-exercises-csharp make test/static -compose/lint: compose/test/static compose/mdlint +compose/lint: compose/lint/markdown compose/lint/yaml compose/test/styling compose/test/static compose/run: compose/build docker-compose --profile testing run --rm algorithm-exercises-csharp make test diff --git a/compose.yaml b/compose.yaml index 40bb81c..12f771d 100644 --- a/compose.yaml +++ b/compose.yaml @@ -11,8 +11,8 @@ services: - ./coverage:/app/coverage profiles: ["testing"] - algorithm-exercises-csharp-mdlint: - image: algorithm-exercises-csharp:mdlint + algorithm-exercises-csharp-lint: + image: algorithm-exercises-csharp:lint build: context: . target: mdlint From 14f4eef9e9e1fb9a3225786f696ef2f890a22fd1 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Mon, 10 Jun 2024 01:16:11 -0400 Subject: [PATCH 2/4] [CONFIG] [FIX] yamllint warnings and errors fixed. False positive in "on:" https://github.com/adrienverge/yamllint/issues/430#issuecomment-1879734522 Can't use "%YAML 1.2" directive because brakes Github Actions How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150 --- .github/dependabot.yml | 2 +- .github/workflows/docker-image.yml | 12 +++++-- .github/workflows/dotnet-coverage.yml | 46 +++++++++++++----------- .github/workflows/dotnet-snyk.yml | 15 +++++--- .github/workflows/dotnet.yml | 50 +++++++++++++++------------ .github/workflows/gitleaks.yml | 8 +++-- .github/workflows/markdown-lint.yml | 34 ++++++++++-------- .github/workflows/sonarcloud.yml | 22 ++++++++---- .markdownlint.yaml | 8 +++-- compose.yaml | 5 +-- 10 files changed, 123 insertions(+), 79 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index aa3e7cd..0b09350 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,7 +2,7 @@ # package ecosystems to update and where the package manifests are located. # Please see the documentation for all configuration options: # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - +--- version: 2 updates: # Maintain dependencies for GitHub Actions diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 29b55d9..dd89c30 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,6 +1,7 @@ +--- name: Docker Image CI -on: +on: # yamllint disable-line rule:truthy push: branches: [main, develop, feature/*] pull_request: @@ -23,7 +24,10 @@ jobs: - name: Run test in Docker image run: make compose/run - name: Tag Docker image - run: docker tag algorithm-exercises-csharp:latest algorithm-exercises-csharp:${{ github.sha }} + run: > + docker tag + algorithm-exercises-csharp:latest + algorithm-exercises-csharp:${{ github.sha }} - name: Run Snyk to check Docker image for vulnerabilities # Snyk can be used to break the build when it detects vulnerabilities. @@ -31,14 +35,18 @@ jobs: continue-on-error: true uses: snyk/actions/docker@master env: + # yamllint disable rule:line-length # In order to use the Snyk Action you will need to have a Snyk API token. # See https://docs.snyk.io/integrations/ci-cd-integrations/github-actions-integration#getting-your-snyk-token # or you can sign up for free at https://snyk.io/login + # yamllint enable rule:line-length SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} with: image: algorithm-exercises-csharp:latest args: --file=Dockerfile + # yamllint disable rule:comments-indentation # - name: Upload result to GitHub Code Scanning # uses: github/codeql-action/upload-sarif@v2 # with: # sarif_file: snyk.sarif + # yamllint enable rule:comments-indentation diff --git a/.github/workflows/dotnet-coverage.yml b/.github/workflows/dotnet-coverage.yml index 42137ce..960fedd 100644 --- a/.github/workflows/dotnet-coverage.yml +++ b/.github/workflows/dotnet-coverage.yml @@ -1,35 +1,39 @@ +# yamllint disable rule:line-length # This workflow will build a .NET project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net +# yamllint enable rule:line-length + +--- name: .NET Coverage -on: +on: # yamllint disable-line rule:truthy push: - branches: [ main, develop, feature/* ] + branches: ["main", "develop", "feature/*"] pull_request: - branches: [ main ] + branches: ["main"] jobs: build: name: "Run CI" strategy: - fail-fast: false - matrix: - os: ["windows-latest"] + fail-fast: false + matrix: + os: ["windows-latest"] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore --verbosity normal - - name: Build - run: dotnet build --no-restore --verbosity normal - - name: Test - run: dotnet test --no-build --verbosity normal - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v4.4.1 - with: - token: ${{ secrets.CODECOV_TOKEN }} + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore --verbosity normal + - name: Build + run: dotnet build --no-restore --verbosity normal + - name: Test + run: dotnet test --no-build --verbosity normal + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.4.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/dotnet-snyk.yml b/.github/workflows/dotnet-snyk.yml index b709452..f338cb2 100644 --- a/.github/workflows/dotnet-snyk.yml +++ b/.github/workflows/dotnet-snyk.yml @@ -1,13 +1,17 @@ +# yamllint disable rule:line-length # This workflow will build a .NET project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net +# yamllint enable rule:line-length + +--- name: .NET Snyk Code analysis -on: +on: # yamllint disable-line rule:truthy push: - branches: [ main, develop, feature/* ] + branches: ["main", "develop", "feature/*"] pull_request: - branches: [ main ] + branches: ["main"] jobs: security: @@ -22,6 +26,9 @@ jobs: - name: Restore dependencies run: dotnet restore algorithm-exercises-csharp.sln - name: Run Snyk to check for vulnerabilities - run: snyk test algorithm-exercises-csharp/ algorithm-exercises-csharp-test/ + run: > + snyk test + algorithm-exercises-csharp/ + algorithm-exercises-csharp-test/ env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index df17512..aa66cc4 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -1,37 +1,41 @@ +# yamllint disable rule:line-length # This workflow will build a .NET project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net +# yamllint enable rule:line-length + +--- name: .NET Tests -on: +on: # yamllint disable-line rule:truthy push: - branches: [ main, develop, feature/* ] + branches: ["main", "develop", "feature/*"] pull_request: - branches: [ main ] + branches: ["main"] jobs: build: name: "Run CI" strategy: - fail-fast: false - matrix: - os: [ - "windows-latest", - "ubuntu-latest", - "macOS-latest" - ] + fail-fast: false + matrix: + os: [ + "windows-latest", + "ubuntu-latest", + "macOS-latest" + ] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Lint (codestyle) - run: dotnet format --verify-no-changes --verbosity normal - - name: Test - run: dotnet test --no-build --verbosity normal + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Lint (codestyle) + run: dotnet format --verify-no-changes --verbosity normal + - name: Test + run: dotnet test --no-build --verbosity normal diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml index 39f6532..66820ed 100644 --- a/.github/workflows/gitleaks.yml +++ b/.github/workflows/gitleaks.yml @@ -1,5 +1,8 @@ +--- + name: gitleaks -on: + +on: # yamllint disable-line rule:truthy pull_request: push: workflow_dispatch: @@ -16,4 +19,5 @@ jobs: - uses: gitleaks/gitleaks-action@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE}} # Only required for Organizations, not personal accounts. + # 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 index 342dd72..075db96 100644 --- a/.github/workflows/markdown-lint.yml +++ b/.github/workflows/markdown-lint.yml @@ -1,10 +1,12 @@ +--- + name: Markdown Lint -on: +on: # yamllint disable-line rule:truthy push: - branches: [ main, develop, feature/* ] + branches: ["main", "develop", "feature/*"] pull_request: - branches: [ main ] + branches: ["main"] permissions: read-all @@ -17,20 +19,22 @@ jobs: matrix: os: [ubuntu-latest] node-version: [22.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + # See supported Node.js release schedule + # at https://nodejs.org/en/about/releases/ steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} + - name: Checkout repository + uses: actions/checkout@v4 - - name: Install dependencies - run: npm install -g markdownlint-cli + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} - - name: Lint - run: markdownlint '**/*.md' --ignore node_modules && echo '✔ Your code looks good.' + - 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/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 9329361..a253fbb 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -1,6 +1,8 @@ +--- + name: SonarCloud -on: +on: # yamllint disable-line rule:truthy push: branches: - main @@ -16,10 +18,12 @@ jobs: uses: actions/setup-java@v4 with: java-version: 21 - distribution: 'temurin' # Alternative distribution options are available. + # Alternative distribution options are available. + distribution: 'temurin' - uses: actions/checkout@v4 with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + # Shallow clones should be disabled for a better relevancy of analysis + fetch-depth: 0 - name: Cache SonarCloud packages uses: actions/cache@v4 with: @@ -41,13 +45,19 @@ jobs: dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner - name: Build and analyze env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + # Needed to get PR information, if any + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} shell: powershell run: | - .\.sonar\scanner\dotnet-sonarscanner begin /k:"sir-gon_algorithm-exercises-csharp" /o:"sir-gon" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml + .\.sonar\scanner\dotnet-sonarscanner begin ` + /k:"sir-gon_algorithm-exercises-csharp" ` + /o:"sir-gon" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" ` + /d:sonar.host.url="https://sonarcloud.io" ` + /d:sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml dotnet restore dotnet build --no-restore dotnet test --no-build --verbosity normal - .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" + .\.sonar\scanner\dotnet-sonarscanner end ` + /d:sonar.token="${{ secrets.SONAR_TOKEN }}" diff --git a/.markdownlint.yaml b/.markdownlint.yaml index b7a8040..c5264b5 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -1,3 +1,6 @@ +--- +# yamllint disable rule:line-length + # Example markdownlint configuration with all properties set to their default value # Default state for all rules @@ -203,9 +206,7 @@ MD042: true # MD043/required-headings/required-headers - Required heading structure MD043: # List of headings - headings: [ - "*" - ] + headings: ["*"] # Match case of headings match_case: false @@ -255,3 +256,4 @@ MD053: # Ignored definitions ignored_definitions: - "//" +# yamllint enable rule:line-length diff --git a/compose.yaml b/compose.yaml index 12f771d..830d8ea 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,3 +1,4 @@ +--- services: algorithm-exercises-csharp: image: algorithm-exercises-csharp:latest @@ -17,8 +18,8 @@ services: context: . target: mdlint # environment: - # LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug - # BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false + #  LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug + #  BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false volumes: - ./:/app profiles: ["lint"] From 76de216c31f3655cc8a7179f37572454f5d16c21 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Mon, 10 Jun 2024 01:25:37 -0400 Subject: [PATCH 3/4] [CONFIG] [Github Actions] new tool added: yamllint --- .github/workflows/yamllint.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/yamllint.yml diff --git a/.github/workflows/yamllint.yml b/.github/workflows/yamllint.yml new file mode 100644 index 0000000..e88812b --- /dev/null +++ b/.github/workflows/yamllint.yml @@ -0,0 +1,23 @@ +--- +name: YAML lint + +on: # yamllint disable-line rule:truthy + push: + branches: ["main", "develop", "feature/*"] + pull_request: + branches: ["main"] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + + - name: Install yamllint + run: pip install yamllint + + - name: Lint YAML files + run: > + yamllint --strict . + && echo '✔ Your code looks good.' From ebf3c694ad94dfc1de5efbd5a3b9193fab7cb247 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Mon, 10 Jun 2024 01:28:44 -0400 Subject: [PATCH 4/4] [CONFIG] [Docker] [make] New config file for yamllint tool --- compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose.yaml b/compose.yaml index 830d8ea..796d2a3 100644 --- a/compose.yaml +++ b/compose.yaml @@ -16,7 +16,7 @@ services: image: algorithm-exercises-csharp:lint build: context: . - target: mdlint + target: lint # environment: #  LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug #  BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false