Commit dacce566 authored by vertighel's avatar vertighel
Browse files

Pipeline test

parent 57e8ddcd
Loading
Loading
Loading
Loading
Loading
+91 −38
Original line number Diff line number Diff line
image: python:3.12 # Use the Python version matching your requires-python

stages:
  - lint
  # - test # Future stage for unit tests
  # - build # Future stage for building the package
  # - deploy # Future stage

variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  PYLINT_TARGETS: "noctua" # Target your main package directory
  ISORT_TARGETS: "noctua tests" # Target package and tests directory
  # Define targets for linters and formatters
  # For a package 'noctua' and a 'tests' directory at the root:
  LINT_FORMAT_TARGETS: "noctua tests"
  PYLINT_TARGETS: "noctua" # Usually just the package itself

cache:
  key: "$CI_COMMIT_REF_SLUG" # Cache per branch
  paths:
    - .cache/pip
    - venv/
    - venv/ # If you choose to use a virtual environment within the CI job

stages:
  - setup # Combined installation of tools and project
  - lint_and_format
  # - test # Placeholder for future tests
  # - build # Placeholder
  # - deploy # Placeholder

before_script:
  - python -V # Print out python version for debugging
# Job to install linters, formatters, and the project itself
prepare_environment:
  stage: setup
  tags:
    - git-run-ia2 # Your specific runner tag
  script:
    - echo "Python version:"
    - python -V
    - echo "Pip version:"
    - pip -V
    - pip install --upgrade pip
  # Install isort, pylint, and project dependencies (for pylint to understand imports)
  # It's good practice to install project deps so pylint can resolve them.
  # Alternatively, install only linters if you don't need pylint to check against installed deps.
  - pip install isort pylint
  - pip install -e . # Install the project in editable mode so pylint can find 'noctua' and its deps
    # Install linters, formatters, and any build tools
    - pip install isort autopep8 pylint black # Added black as an option
    # Install the project in editable mode and its dependencies
    # This ensures linters understand your package structure and imports
    - echo "Installing project 'noctua' and its dependencies..."
    - pip install -e .
    - echo "Setup complete."
  artifacts:
    paths:
      - . # Pass the whole workspace if subsequent jobs depend on full checkout + venv
      # More fine-grained would be to only pass venv if used, and have other jobs checkout code
    expire_in: 1 hour # Keep artifacts for a limited time

isort_check:
  stage: lint
# Job for isort (check and apply/diff)
isort_check_and_format:
  stage: lint_and_format
  tags:
    - git-run-ia2
  needs: # GitLab 12.2+ feature for DAG pipelines; use 'dependencies' for older GitLab
    - job: prepare_environment
      artifacts: true # Inherit artifacts
  script:
    - echo "Running isort check..."
    # --check-only: exits with non-zero if files need formatting
    # --diff: shows differences
    # --profile black: if you use black for formatting, isort can align with it. Optional.
    - isort --check-only --diff ${ISORT_TARGETS}
    - echo "Running isort..."
    # Option 1: Check only (fails pipeline if changes are needed)
    - echo "Checking import order with isort..."
    - isort --check-only --diff ${LINT_FORMAT_TARGETS}
    # Option 2: Apply formatting (uncomment if you want CI to fix and commit, more complex)
    # - isort ${LINT_FORMAT_TARGETS}
    # - |
    #   # Check if isort made changes
    #   git diff --quiet || \
    #     (echo "isort made changes. Consider committing them." && exit 1) # Or auto-commit
    - echo "isort check complete."
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" # Run on merge requests
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run on commits to default branch (main/master)
    - when: manual # Allow manual trigger for other branches/tags
      allow_failure: true
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - when: manual
      allow_failure: true # Allow manual trigger to not fail pipeline

pylint_check:
  stage: lint
# Job for autopep8 (or black)
style_format_code:
  stage: lint_and_format
  tags:
    - git-run-ia2
  needs:
    - job: prepare_environment
      artifacts: true
  script:
    - echo "Running pylint check on '${PYLINT_TARGETS}'..."
    # PYLINT_TARGETS should be the package name or specific files/directories.
    # --rcfile=.pylintrc: specify your config file
    # --fail-under=N: Optional, set a minimum score for the build to pass.
    #                 Start without it or with a low N and increase over time.
    - pylint --rcfile=.pylintrc ${PYLINT_TARGETS} # || pylint-exit $? 
      # The `|| pylint-exit $?` part is if you use pylint-exit for custom exit codes based on message types.
      # For a basic setup, just `pylint ...` is fine. It will exit non-zero on errors.
    - echo "Running autopep8 to format Python code..."
    # Option 1: Check only (using --diff and exiting if changes needed)
    - echo "Checking code style with autopep8..."
    - autopep8 --diff --recursive ${LINT_FORMAT_TARGETS} > autopep8.diff || true # Capture diff, don't fail yet
    - |
      if [ -s autopep8.diff ]; then
        echo "autopep8 found style issues. Diff:"
        cat autopep8.diff
        # To make it a check that fails, exit 1.
        # For just reporting, don't exit 1.
        # exit 1 # Uncomment to fail the job if diff is not empty
      else
        echo "autopep8: No style changes needed."
      fi
    # Option 2: Apply formatting (uncomment if CI should fix, more complex)
    # - autopep8 --in-place --recursive --aggressive --aggressive ${LINT_FORMAT_TARGETS}
    # - |
    #   git diff --quiet || \
    #     (echo "autopep8 made changes. Consider committing them." && exit 1)
    - echo "autopep8 check complete."
  artifacts:
    when: always # Capture diff even on failure
    paths:
      - autopep8.diff
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH