Commit e905b79d authored by Vojtěch Trefný's avatar Vojtěch Trefný
Browse files

Add linters and update description for HW 4

parent 65a1042c
Loading
Loading
Loading
Loading

.gitlab-ci.yml

0 → 100644
+35 −0
Original line number Diff line number Diff line
image: fedora:latest

before_script:
  - dnf install -y git

.mr_common:
  stage: test
  tags:
    - shared-fi

  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

  script:
    - |
      echo "╔══════════════════════════════════════════════════════════════════════════════╗"
      echo "║  This CI job is intended for Homework 4 evaluation.                          ║"
      echo "║  If you are working on a different assignment, you can ignore any errors     ║"
      echo "║  reported here.                                                              ║"
      echo "╚══════════════════════════════════════════════════════════════════════════════╝"
    - git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
    - CHANGED_FILES=$(git diff --name-only origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...$CI_COMMIT_SHA)
    - echo "Changed files:" && echo "$CHANGED_FILES"

lint_header:
  extends: .mr_common
  script:
    - !reference [.mr_common, script]
    - bash linters/lint_header.sh $CHANGED_FILES

lint_whitespace:
  extends: .mr_common
  script:
    - !reference [.mr_common, script]
    - bash linters/lint_whitespace.sh $CHANGED_FILES
+3 −4
Original line number Diff line number Diff line
@@ -113,10 +113,9 @@ Lesson 4 - Lesson 6
Lesson 5 - Lesson 7

* **Instructor prep**: Instructor adds GitLab CI/CD workflow with intentional validation bugs
* Students sync fork; pipeline fails on their branch
* Debug and fix the workflow file in a new branch
* Update your `123456.txt` to comply with new linting rules
* PR to upstream
* Sync your fork. Open a new MR updating your <uco>.txt file
* CI pipeline will fail on your MR
* Debug the issue and update your <uco>.txt to comply with new linting rules

**HW5 – GitLab CI/CD**
Lesson 6 - Lesson 8

linters/lint_header.sh

0 → 100644
+19 −0
Original line number Diff line number Diff line
#!/bin/bash

if [ $# -ne 1 ]; then
    echo "ERROR: Expected exactly 1 changed file, got $#"
    exit 1
fi

file="$1"
expected="Homework 4 solution by ${GITLAB_USER_NAME}:"
first_line=$(head -n 1 "$file")

if [ "$first_line" != "$expected" ]; then
    echo "ERROR: First line of '$file' does not match expected format."
    echo "  Expected: $expected"
    echo "  Got:      $first_line"
    exit 1
fi

echo "OK: '$file' passed lint check."
+24 −0
Original line number Diff line number Diff line
#!/bin/bash

file="$1"
rc=0

# Check for trailing whitespace
bad_lines=$(grep -n '[[:space:]]$' "$file")
if [ -n "$bad_lines" ]; then
    echo "ERROR: Trailing whitespace found in '$file':"
    echo "$bad_lines"
    rc=1
fi

# Check that file ends with a newline
if [ -n "$(tail -c 1 "$file")" ]; then
    echo "ERROR: '$file' does not end with a newline."
    rc=1
fi

if [ $rc -eq 0 ]; then
    echo "OK: '$file' passed whitespace check."
fi

exit $rc