# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages:
- release

release:
  stage: release
  script:
  - git config user.name "Ariel Quintana"
  - git config user.email "aquintana@focasoftware.com"
  - git checkout master
  - git pull origin master
  - version=$(git describe --tags --abbrev=0)
  - version=${version:-v0.0.0}
  - version=${version//v/}
  - version_array=(${version//./ })
  - major=${version_array[0]}
  - minor=${version_array[1]}
  - patch=${version_array[2]}
  - patch=$((patch+1))
  - new_version="$major.$minor.$patch"
  - last_commit_message=$(git log -1 --pretty=%B)
  - release_notes="Release Notes:$last_commit_message"
  - git tag -a "$new_version" -m "$release_notes"
  - git remote remove origin
  - git remote add origin https://oauth2:$OAUTH_TOKEN@foca-gitlab.focasoftware.com/php/clientes.git
  - git push origin "$new_version"
  only:
  - master
