---
variables:
  PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}"


build-debian:
  stage: build-debian-package
  image: logilab/infra/dockerfiles/buildpackage
  tags:
    - debian
  rules:
    - if: '$CI_MERGE_REQUEST_ID'
      when: never
    - if: '$CI_COMMIT_TAG'
      when: on_success
    - when: manual
  script:
    - buildpackage -d `pwd`
    - cp -r /repo .
  artifacts:
    paths:
      - repo

upload-deb-to-heptapod:
  stage: upload-deb-to-heptapod
  image: curlimages/curl:latest
  tags:
    - curl
    - debian
  # May be failling if the deb name is not ${CI_PROJECT_NAME}_${CI_COMMIT_TAG}-1_all.deb
  allow_failure: true
  rules:
    - if: '$CI_MERGE_REQUEST_ID'
      when: never
    - if: '$CI_COMMIT_TAG'
      when: on_success
  script:
    - |
      curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}"\
           --upload-file "repo/${CI_PROJECT_NAME}_${CI_COMMIT_TAG}-1_all.deb"\
                         "${PACKAGE_REGISTRY_URL}/${CI_COMMIT_TAG}/${CI_PROJECT_NAME}_${CI_COMMIT_TAG}-1_all.deb"
