# CI Build Template
.build-package:
    image: python:3.10
    script:
        # Enter the package directory
        - echo building package in $PACKAGE_PATH
        - export CAPO_PATH=$PWD
        - export CAPO_PROFILE=docker
        - WD=$PWD
        - cd ${PACKAGE_PATH}

        # Install build, poetry and pytest
        - pip install poetry
        - poetry env use $(which python3)

        # Install the package for testing
        - poetry install --with test
        - $(poetry env info -p)/bin/pytest .

        # Build the package and push to the gitlab repo
        - poetry build
        - poetry config repositories.gitlab "https://gitlab.nrao.edu/api/v4/projects/$CI_PROJECT_ID/packages/pypi"
        - poetry config http-basic.gitlab gitlab-ci-token "$CI_JOB_TOKEN"
        - poetry publish --repository gitlab

        # Return to the parent directory
        - cd $WD