sudo: required

branches:
  except:
    - unstable
    - weblate
services:
  - docker

dist: jammy
language: node_js
node_js:
  - 20
script:
  - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
  - docker run --rm -u $(id -u) -v $(pwd):/app opensourcepos/composer:ci4 composer install
  - version=$(grep application_version app/Config/App.php | sed "s/.*=\s'\(.*\)';/\1/g")
  - sed -i 's/production/development/g' .env
  - sed -i "s/commit_sha1 = 'dev'/commit_sha1 = '$rev'/g" app/Config/OSPOS.php
  - echo "$version-$branch-$rev"
  - npm version "$version-$branch-$rev" --force || true
  - sed -i 's/opensourcepos.tar.gz/opensourcepos.$version.tgz/g' package.json
  - npm ci && npm install -g gulp && npm run build
  - docker build . --target ospos -t ospos
  - docker build app/Database/ -t "jekkos/opensourcepos:sql-$TAG"
env:
  global:
  - BRANCH=$(echo ${TRAVIS_BRANCH} | sed s/feature\\///)
  - TAG=${TRAVIS_TAG:-$BRANCH}
  - date=`date +%Y%m%d%H%M%S` && branch=${TRAVIS_BRANCH} && rev=`git rev-parse --short=6 HEAD`
after_success:
  - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" && docker tag "ospos:latest"
    "jekkos/opensourcepos:$TAG" && docker push "jekkos/opensourcepos:$TAG" && docker push "jekkos/opensourcepos:sql-$TAG"
  - gulp compress
  - mv dist/opensourcepos.tar.gz "dist/opensourcepos.$version.$rev.tgz"
  - mv dist/opensourcepos.zip "dist/opensourcepos.$version.$rev.zip"
deploy:
  - provider: releases
    edge: true
    file: dist/opensourcepos.$version.$rev.zip
    name: "Unstable OpensourcePos"
    overwrite: true
    release_notes: "This is a build of the latest master which might contain bugs. Use at your own risk. Check releases section for the latest official release"
    prerelease: true
    tag_name: unstable
    user: jekkos

    api_key:
      secure: "KOukL8IFf/uL/BjMyCSKjf2vylydjcWqgEx0eMqFCg3nZ4ybMaOwPORRthIfyT72/FvGX/aoxxEn0uR/AEtb+hYQXHmNS+kZdX72JCe8LpGuZ7FJ5X+Eo9mhJcsmS+smd1sC95DySSc/GolKPo+0WtJYONY/xGCLxm+9Ay4HREg="

    on:
      branch: master
