# CI Build Template
.push-packages:
    image: python:3.10-slim
    before_script:
      - mkdir -p ~/.ssh
      - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
      - eval $(ssh-agent -s)
      - chmod 400 "$SSH_PRIVATE_KEY"
      - ssh-add "$SSH_PRIVATE_KEY"
      - chmod 700 ~/.ssh
      - '[[ -f /.dockerenv ]] && echo -e "Host *\\n\\tStrictHostKeyChecking no\\n\\n" > ~/.ssh/config'
    script:
      - mkdir -p /home/ssa/bin
      - ln -s "$(which python3)" /home/ssa/bin/python3.10
      - export PATH=$PATH:/home/ssa/bin
      - pip install pex
      - pex ${PIP_NAME} -c ${PACKAGE_NAME} -o ./${PACKAGE_NAME} -i https://gitlab.nrao.edu/api/v4/projects/621/packages/pypi/simple --python-shebang /home/ssa/bin/python3.10 --disable-cache
      - echo "Releasing PEX to sbin area - ${PACKAGE_NAME}"
      - scp ${PACKAGE_NAME} root@shipman.aoc.nrao.edu:/lustre/aoc/cluster/pipeline/dsoc-${DEPLOY_ENV}/workspaces/sbin/
    rules:
      - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /(^[0-9]\.[0-9]|^[0-9]\.[0-9]\.[0-9])-DEVELOPMENT/'
        variables:
          DEPLOY_ENV: "dev"
        changes:
          - apps/cli/executables/pexable/${PACKAGE_NAME}/**/*
      - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
        variables:
          DEPLOY_ENV: "dev"
        changes:
          - apps/cli/executables/pexable/${PACKAGE_NAME}/**/*
      - if: '$CI_COMMIT_TAG =~ /^end-of-sprint-[0-9]+/'
        variables:
          DEPLOY_ENV: "test"
        changes:
          - apps/cli/executables/pexable/${PACKAGE_NAME}/**/*
      - if: '$CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+/'
        variables:
          DEPLOY_ENV: "test"
        changes:
          - apps/cli/executables/pexable/${PACKAGE_NAME}/**/*
      - if: '$CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+$/'
        variables:
          DEPLOY_ENV: "prod"
        changes:
          - apps/cli/executables/pexable/${PACKAGE_NAME}/**/*
