From 27333e834169f37ff0754dcbcae5c7ea21d8ecd5 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Mon, 14 Sep 2026 14:47:32 -0300 Subject: [PATCH] [REFACTOR] [OPTIMIZATION] lint and test steps re-arranged [OPTIMIZATION] Docker: yamllint and Markdownlint removed from main Dockerfile [CONFIG] Docker: new steps to use markdownlint and yamllint from public images. [OPTIMIZATION] Using Docker dedicated images for markdownlint and yamllint --- .github/workflows/docker-image.yml | 92 ++++++++++++++++++++++-------- Dockerfile | 16 +----- Makefile | 22 +++++-- compose.yaml | 14 +++++ 4 files changed, 100 insertions(+), 44 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 8d6a53c4..17b0d0a3 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,5 +1,4 @@ --- - name: Docker Image CI on: # yamllint disable-line rule:truthy @@ -15,10 +14,9 @@ env: ARTIFACT_NAME: algorithm-exercises-py_${{ github.sha }} jobs: - - build: - name: "Build Docker images" - runs-on: ubuntu-24.04 + build-lint: + name: "Build Docker LINT image" + runs-on: ubuntu-26.04 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -39,6 +37,14 @@ jobs: with: name: ${{ env.ARTIFACT_NAME }}_lint path: /tmp/${{ env.ARTIFACT_NAME }}_lint.tar + build-test: + name: "Build Docker TEST image" + runs-on: ubuntu-26.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 - name: "TEST: Build and push" uses: docker/build-push-action@v7 @@ -55,6 +61,14 @@ jobs: name: ${{ env.ARTIFACT_NAME }}_test path: /tmp/${{ env.ARTIFACT_NAME }}_test.tar + build-prod: + name: "Build Docker PRODUCTION image" + runs-on: ubuntu-26.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 - name: "PRODUCTION: Build and push" uses: docker/build-push-action@v7 with: @@ -71,11 +85,33 @@ jobs: name: ${{ env.ARTIFACT_NAME }}_prod path: /tmp/${{ env.ARTIFACT_NAME }}_prod.tar - lint: + run-lint-markdown: + name: "Run in docker: Markdown LINT" + runs-on: ubuntu-26.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Run markdown lint + run: > + make compose/lint/markdown + + run-lint-yaml: + name: "Run in docker: YAML LINT" + runs-on: ubuntu-26.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Run YAML lint + run: > + make compose/lint/yaml + + run-lint: name: "Run in docker: LINT" - runs-on: ubuntu-24.04 - needs: build + runs-on: ubuntu-26.04 + needs: build-lint steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - name: Download artifact uses: actions/download-artifact@v8 with: @@ -88,14 +124,19 @@ jobs: docker image ls -a - name: Run lint - run: | - docker run --rm ${{ env.IMAGE_NAME }}:lint make lint + run: > + docker + compose --profile lint + run --rm ${{ env.IMAGE_NAME }}-lint + make lint - test: + run-test: name: "Run in docker: TEST" - runs-on: ubuntu-24.04 - needs: build + runs-on: ubuntu-26.04 + needs: build-test steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - name: Download artifact uses: actions/download-artifact@v8 with: @@ -108,14 +149,17 @@ jobs: docker image ls -a - name: Run test - run: | - docker run --rm ${{ env.IMAGE_NAME }}:test make test + run: > + docker + compose --profile test + run --rm ${{ env.IMAGE_NAME }}-test + make test # yamllint disable rule:line-length # security: # name: "Snyk Container" - # runs-on: ubuntu-24.04 - # needs: build + # runs-on: ubuntu-26.04 + # needs: build-prod # permissions: # actions: read # contents: read @@ -163,8 +207,8 @@ jobs: scan: name: "Trivy" - runs-on: ubuntu-24.04 - needs: build + runs-on: ubuntu-26.04 + needs: build-prod permissions: actions: read contents: read @@ -185,7 +229,7 @@ jobs: uses: aquasecurity/trivy-action@v0.36.0 with: image-ref: ${{ env.IMAGE_NAME }}:${{ github.sha }} - format: 'table' + format: "table" env: TRIVY_DB_REPOSITORY: ${{ vars.TRIVY_DB_REPOSITORY }} @@ -193,12 +237,12 @@ jobs: uses: aquasecurity/trivy-action@v0.36.0 with: image-ref: ${{ env.IMAGE_NAME }}:${{ github.sha }} - format: 'sarif' - output: 'trivy-results.sarif' + format: "sarif" + output: "trivy-results.sarif" env: TRIVY_DB_REPOSITORY: ${{ vars.TRIVY_DB_REPOSITORY }} - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v4 + uses: github/codeql-action/upload-sarif@v4.38.0 with: - sarif_file: 'trivy-results.sarif' + sarif_file: "trivy-results.sarif" diff --git a/Dockerfile b/Dockerfile index e76ea713..11dcea3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,10 +27,8 @@ FROM base AS lint ENV WORKDIR=/app WORKDIR ${WORKDIR} -RUN apk add --update --no-cache make nodejs npm \ - && apk add --update --no-cache yamllint \ - && npm install -g --ignore-scripts markdownlint-cli@0.49.1 \ - && npm install -g --ignore-scripts prettier@3.7.4 +# Node.js required by pyright as dependency +RUN apk add --update --no-cache nodejs # [!TIP] Use a bind-mount to "/app" to override following "copys" # for lint and test against "current" sources in this stage @@ -57,16 +55,6 @@ COPY ./.pylintrc ${WORKDIR}/ COPY ./.coveragerc ${WORKDIR}/ COPY ./setup.cfg ${WORKDIR}/ -# markdownlint conf -COPY ./.markdownlint.json ${WORKDIR}/ - -# yamllint conf -COPY ./.yamllint ${WORKDIR}/ -COPY ./.yamlignore ${WORKDIR}/ - -# JSON linting conf -COPY ./.prettierrc.yaml ${WORKDIR}/ - CMD ["make", "lint"] ############################################################################### diff --git a/Makefile b/Makefile index ef40f217..e869538e 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,9 @@ lint/markdown: lint/yaml: yamllint --strict . && echo '✔ Your code looks good.' -lint: lint/markdown lint/yaml lint/json test/styling test/static +lint: test/styling test/static + +lint/all: lint/markdown lint/yaml test/styling test/static format/json: prettier --write ./src/**/*.json @@ -162,11 +164,19 @@ compose/rebuild: env ${DOCKER_COMPOSE} --profile testing build --no-cache ${DOCKER_COMPOSE} --profile production build --no-cache -compose/lint/markdown: compose/build - ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make lint/markdown - -compose/lint/yaml: compose/build - ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make lint/yaml +compose/lint/markdown: + ${DOCKER_COMPOSE} --profile lint run --rm \ + --workdir /workspace \ + -v "$$(pwd):/workspace" \ + markdownlint --config /workspace/.markdownlint.json '/workspace/**/*.md' \ + && echo '✔ Your code looks good.' + +compose/lint/yaml: + ${DOCKER_COMPOSE} --profile lint run --rm \ + --workdir /workspace \ + -v "$$(pwd):/workspace" \ + yamllint --strict . \ + && echo '✔ Your code looks good.' compose/test/styling: compose/build ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make test/styling diff --git a/compose.yaml b/compose.yaml index 48c77f8b..3c1c6e4d 100644 --- a/compose.yaml +++ b/compose.yaml @@ -25,6 +25,20 @@ services: - ./:/app profiles: ["lint"] + markdownlint: + image: goncl/markdownlint-cli:latest + working_dir: /workspace + volumes: + - ./:/workspace + profiles: ["lint"] + + yamllint: + image: goncl/yamllint:latest + working_dir: /workspace + volumes: + - ./:/workspace + profiles: ["lint"] + algorithm-exercises-py-dev: image: algorithm-exercises-py:dev build: