Skip to content
Snippets Groups Projects
package-build.template.yml 2.11 KiB
Newer Older
# CI Build Template
Daniel Lyons's avatar
Daniel Lyons committed
.build-package:
    image: python:3.10
    script:
Charlotte Hausman's avatar
Charlotte Hausman committed
        - apt-get update -y && apt-get install jq -y
Daniel Lyons's avatar
Daniel Lyons committed
        - echo building package in $PACKAGE_PATH
Daniel Lyons's avatar
Daniel Lyons committed
        - export CAPO_PATH=$PWD
        - export CAPO_PROFILE=docker
Daniel Lyons's avatar
Daniel Lyons committed
        - WD=$PWD
        # Make symbolic link of python3 install to where it's installed on dev
        - mkdir -p /home/ssa/bin
        - ln -s "$(which python3)" /home/ssa/bin/python3.10
        - export PATH=$PATH:/home/ssa/bin

        # Install build, poetry and pytest
        - pip install poetry
        - poetry env use /home/ssa/bin/python3.10

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

        # once tests pass, look to see if there is a conflicting version in pypi registry
Charlotte Hausman's avatar
Charlotte Hausman committed
        - PACKAGE_NAME=$(basename $PWD)
Charlotte Hausman's avatar
Charlotte Hausman committed
        - echo $PACKAGE_NAME version $RELEASE_VERSION
            DELETE_URL_RESPONSE=$(curl --header "PRIVATE-TOKEN: ${API_TOKEN}"
Charlotte Hausman's avatar
Charlotte Hausman committed
            "https://gitlab.nrao.edu/api/v4/projects/$CI_PROJECT_ID/packages?package_type=pypi&package_name=$PACKAGE_NAME"
            | jq -r --arg RELEASE_VERSION "$RELEASE_VERSION" '.[] | {"name": .name, "version": .version, "url":._links.delete_api_path}
Charlotte Hausman's avatar
Charlotte Hausman committed
            | select(.version==$RELEASE_VERSION) | .url')
        - echo $DELETE_URL_RESPONSE
        # if a conflicting version is present in pypi registry, remove it
        - |
            if [[ -n "$DELETE_URL_RESPONSE" ]]
            then
                $(curl --request DELETE --header "PRIVATE-TOKEN: ${API_TOKEN}" "$DELETE_URL_RESPONSE")
        # Now that package registry is cleared, 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
        - cd $WD
Brittany Faciane's avatar
Brittany Faciane committed
            - ${PACKAGE_PATH}/**/*