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

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_anchor
  before_script:
    - pip install --upgrade pip
    - pip install poetry
    - poetry install --only main
Ashis Ravindran's avatar
Ashis Ravindran committed

Ashis Ravindran's avatar
Ashis Ravindran committed
lint:
  needs: []
  rules:
    - if: $CI_COMMIT_REF_NAME != "main"
  extends: .install_dependencies
Ashis Ravindran's avatar
Ashis Ravindran committed
  script:
    - poetry run reporting lint
Ashis Ravindran's avatar
Ashis Ravindran committed

Ashis Ravindran's avatar
Ashis Ravindran committed
validate:
  needs: []
  rules:
    - if: $CI_COMMIT_REF_NAME != "main"
  extends: .install_dependencies
Ashis Ravindran's avatar
Ashis Ravindran committed
  script:
    - poetry run reporting validate
  needs: []
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME == "main"
    - 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_anchor; fi
    - if [[ "$PREVIOUS_VERSION" != "$CURRENT_VERSION" ]]; then 
        pip install --upgrade pip
        pip install poetry
        poetry install --only main
        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