Commit c65771a9 authored by Davide Ricci's avatar Davide Ricci
Browse files

Update .gitlab-ci.yml file

parent c68f9221
Loading
Loading
Loading
Loading
Loading
+31 −60
Original line number Diff line number Diff line
@@ -4,14 +4,11 @@ image: python:3.12

variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  # We will apply formatting only to the 'noctua' package directory
  FORMAT_TARGETS: "noctua" # For sed, autopep8, isort
  PYLINT_TARGETS: "noctua" # For pylint
  # Git user for potential auto-commits (if added later)
  GIT_USER_EMAIL: "davide.ricci@inaf.it"
  GIT_USER_NAME: "Davide GitLab CI"
  # Branch for auto-committed changes (if added later)
  # FORMATTED_BRANCH_NAME: "ci-auto-formatted"
  FORMATTED_BRANCH_NAME: "ci-auto-formatted"

cache:
  key: "$CI_COMMIT_REF_SLUG" # Cache pip downloads per branch
@@ -20,33 +17,28 @@ cache:
    # - venv/

stages:
  - setup_and_format # A single stage to perform all modifications sequentially
  - setup_and_format 
  - lint # A stage for checks that don't modify code (like pylint)
  - auto_commit # Optional stage for committing changes
 # - auto_commit 

# Job 1: Install Noctua and its dependencies
install_noctua:
  stage: setup_and_format # Start of the sequential process
  stage: setup_and_format 
  tags:
    - git-run-ia2 # Your runner tag
    - git-run-ia2 
  script:
    - echo "Current directory $(pwd)"
    - ls -la
    - echo "Python version $(python -v)"
    - pip install --upgrade pip
    # Install the project in editable mode. This also installs its dependencies.
    # This makes the 'noctua' package available for subsequent steps if they
    # were to run python code that imports it, and for pylint to understand it.
    - echo "Installing project 'noctua' and its dependencies..."
    - pip install -e .
    - echo "Noctua installation complete."
  artifacts:
    paths:
      # Pass the entire workspace. This includes the checked-out code
      # and any environment changes if pip installed into a local venv (not default)
      # or if -e . modifies local files (e.g. .egg-info).
      - . # The current working directory state
    expire_in: 1 hour

# Job 2: Remove Trailing Whitespaces
fix_trailing_whitespaces:
@@ -54,24 +46,17 @@ fix_trailing_whitespaces:
  tags:
    - git-run-ia2
  needs:
    - job: install_noctua # Depends on the initial checkout and project setup
      artifacts: true # Use the workspace from the previous job
    - job: install_noctua
      artifacts: true
  script:
    - echo "Current directory $(pwd)"
    - ls -la
    - echo "Removing trailing whitespaces from '${FORMAT_TARGETS}' directory..."
    # Ensure FORMAT_TARGETS (e.g., "noctua") exists
    - |
      if [ -d "${FORMAT_TARGETS}" ]; then
        find "${FORMAT_TARGETS}" -type f -name "*.py" -exec sed -i 's/[[:space:]]*$//' {} \;
    - find "${FORMAT_TARGETS}" -type f -name "*.py" -exec sed -i 's/[[:space:]]*$//' {} \;
      echo "Trailing whitespaces removed."
      else
        echo "Warning: Directory '${FORMAT_TARGETS}' not found. Skipping whitespace removal."
      fi
  artifacts:
    paths:
      - . # Pass the modified workspace
    expire_in: 1 hour

# Job 3: Apply isort
apply_isort:
@@ -82,23 +67,17 @@ apply_isort:
    - job: fix_trailing_whitespaces
      artifacts: true
  before_script:
    - pip install isort # Install isort in this job's environment
    - pip install isort
  script:
    - echo "Current directory $(pwd)"
    - ls -la
    - echo "Applying isort to '${FORMAT_TARGETS}' directory..."
    # isort will use pyproject.toml for configuration
    - |
      if [ -d "${FORMAT_TARGETS}" ]; then
        isort "${FORMAT_TARGETS}"
    - isort "${FORMAT_TARGETS}"
      echo "isort formatting complete."
      else
        echo "Warning: Directory '${FORMAT_TARGETS}' not found. Skipping isort."
      fi
  artifacts:
    paths:
      - . # Pass the modified workspace
    expire_in: 1 hour

# Job 4: Apply autopep8
apply_autopep8:
@@ -109,40 +88,32 @@ apply_autopep8:
    - job: apply_isort
      artifacts: true
  before_script:
    - pip install autopep8 # Install autopep8 in this job's environment
    - pip install autopep8
  script:
    - echo "Current directory $(pwd)"
    - ls -la
    - echo "Applying autopep8 to '${FORMAT_TARGETS}' directory..."
    - |
      if [ -d "${FORMAT_TARGETS}" ]; then
        autopep8 --in-place --recursive --aggressive --aggressive "${FORMAT_TARGETS}"
    - autopep8 --in-place --recursive --aggressive --aggressive "${FORMAT_TARGETS}"
      echo "autopep8 formatting complete."
      else
        echo "Warning: Directory '${FORMAT_TARGETS}' not found. Skipping autopep8."
      fi
  artifacts:
    paths:
      - . # Pass the modified workspace (this is the fully formatted code)
    expire_in: 1 hour
      - . # Pass the modified workspace

## Job 5: Run Pylint
#run_pylint:
#  stage: lint
#  tags:
#    - git-run-ia2
#  needs:
#    - job: apply_autopep8 
#      artifacts: true
#  before_script:
#    - pip install pylint
#  script:
#    - echo "Current directory $(pwd)"
#    - ls -la
#    - echo "Running pylint on '${PYLINT_TARGETS}'..."
#    # .pylintrc should be at the project root, available from the artifact
#    - pylint --rcfile=.pylintrc "${PYLINT_TARGETS}"
#    - echo "Pylint check complete."
# Job 5: Run Pylint
run_pylint:
  stage: lint
  tags:
    - git-run-ia2
  needs:
    - job: apply_autopep8 
      artifacts: true
  before_script:
    - pip install pylint
  script:
    - echo "Current directory $(pwd)"
    - echo "Running pylint on '${PYLINT_TARGETS}'..."
    - pylint --rcfile=.pylintrc "${PYLINT_TARGETS}"
    - echo "Pylint check complete."
  #rules:
  #  - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  #  - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH