image: registry.hedenstroem.com/gitlab/gitlab-builder-erlang:19.1

cache:
  paths:
    - .rebar3

before_script:
  - export PATH=${ERL_HOME}/bin:$PATH

stages:
  - test
  - publish

test:
  stage: test
  script:
    - rebar3 test
    - coverage.escript _build/test/cover/eunit.coverdata

hex_publish:
  stage: publish
  only:
    - /^\d+[.]\d+[.]\d+$/ # Only publish HEAD tagged with semantic version
  script:
    - mkdir -p ~/.hex && printf "{key,<<\"$HEX_KEY\">>}.\n{username,<<\"$HEX_USERNAME\">>}.\n" > ~/.hex/hex.config
    - echo "Y" | rebar3 hex publish

aws_s3:
  stage: publish
  only:
    - /^\d+[.]\d+[.]\d+$/ # Only publish HEAD tagged with semantic version
  script:
    - rebar3 edoc
    - aws s3 cp doc s3://s3.erlang.ninja/tsuru/$CI_BUILD_REF_NAME/ --recursive
    - rebar3 as production do tar
    - aws s3 cp _build/production/rel/tsuru/tsuru-$CI_BUILD_REF_NAME.tar.gz s3://s3.erlang.ninja/tsuru/
    - aws s3 cp s3://s3.erlang.ninja/tsuru/tsuru-$CI_BUILD_REF_NAME.tar.gz s3://s3.erlang.ninja/tsuru/tsuru-latest.tar.gz
