image: debian

stages:
  - build
  - release
  - releasetag

build:
  stage: build
  before_script:
    - apt-get update && apt-get -qq install git make zip > /dev/null
  script:
    - make
  artifacts:
    name: "$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
    paths:
      - build

release:
  stage: release
  variables:
    GIT_STRATEGY: none
  dependencies:
    - build
  before_script:
    - apt-get update && apt-get -qq install zip > /dev/null
  script:
    - mv build/bemanitools-supplements.zip ./bemanitools-supplements.zip
    - find . -mindepth 1 ! -regex '^./bemanitools-supplements.zip' -delete
    - unzip bemanitools-supplements.zip
    - rm bemanitools-supplements.zip
  artifacts:
    name: "$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
    paths:
      - ./*
      
releasetag:
  stage: releasetag
  dependencies: []
  before_script:
    - apt-get update && apt-get -qq install curl > /dev/null
  script:
    - |
      curl --silent --show-error \
        --data "{\"tag_name\": \"${CI_COMMIT_TAG}\", \"name\": \"${CI_PROJECT_NAME}-${CI_COMMIT_TAG}\", \"description\": \"${CI_COMMIT_TAG_MESSAGE:-No release notes.}\"}" \
        --header "Content-Type: application/json" \
        --header "Private-Token: ${CI_PRIVATE_TOKEN}" \
        --request POST \
        "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/releases"
  only:
    - tags
