Skip to content
Snippets Groups Projects
.gitlab-ci.yml 1.42 KiB
Newer Older
image: python:3.12

Ashis Ravindran's avatar
Ashis Ravindran committed
stages:
Ashis Ravindran's avatar
Ashis Ravindran committed
  - lint
variables:
  # Set the registry URL based on your GitLab project ID
  POETRY_REPOSITORY: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi"

.install_dependencies: &install_dependencies
  before_script:
    - pip install --upgrade pip
    - pip install poetry
    - poetry install --only main
Ashis Ravindran's avatar
Ashis Ravindran committed

lint:
  stage: lint
  extends: .install_dependencies
Ashis Ravindran's avatar
Ashis Ravindran committed
  script:
    - poetry run reporting lint
Ashis Ravindran's avatar
Ashis Ravindran committed

validate:
  stage: validate
  extends: .install_dependencies
Ashis Ravindran's avatar
Ashis Ravindran committed
  script:
    - poetry run reporting validate
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME == "main"
        #- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" && 
        #when: always
    - CURRENT_VERSION=$(grep version pyproject.toml | awk -F\" '{print $2}'); echo $CURRENT_VERSION
    - PREVIOUS_VERSION=$(git show HEAD~1:pyproject.toml | grep version | awk -F\" '{print $2}'); echo $PREVIOUS_VERSION
    - if [[ "$PREVIOUS_VERSION" != "$CURRENT_VERSION" ]]; then 
        *install_dependencies
        poetry build --format wheel;
        poetry config repositories.gitlab ${POETRY_REPOSITORY};
        poetry publish --username gitlab-ci-token --password ${CI_JOB_TOKEN} --repository gitlab;
        echo "Version has changed";
      else 
        echo "Nothing published.";
      fi
      #  only:
      #- main