variables:
  GIT_STRATEGY: clone

stages:
  - generate-readme

generate_readme_job:
  stage: generate-readme
  image: python:3.10
  script:
    - pip install --upgrade pip
    - git checkout main
    - git status
    - python scripts/generate_readme.py
    - export NEEDS_UPDATE="false"
    - git diff --exit-code || export NEEDS_UPDATE="true"
    - echo $NEEDS_UPDATE
    - |
      if [ $NEEDS_UPDATE = "true" ]; then
        git remote set-url origin https://$CI_USER:$CI_TOKEN@gitlab.ms-ds.org/msds/icons.git
        git add README.md
        git config --global user.email "ci@gitlab.ms-ds.org"
        git config --global user.name "GitLab CI"
        git commit -m "Auto-updated README"
        git push -o ci.skip origin HEAD:main
      fi
  only:
    - main
