---
stages:
  - sonarqube
  - upload_linux_shell
  - upload_linux_amd64_binary
  - upload_windows_amd64_binary

variables:
  ARTIFACTORY_BASE_URL: https://artifactory.software.geant.org/artifactory/acme-downloader
  ARTIFACT_NAME: acme-downloader

sonarqube:
  image: sonarsource/sonar-scanner-cli:${SONAR_SCANNER_CLI_VERSION}
  stage: sonarqube
  only:
    - master
  variables:
    SONAR_PROJECT_BASE_DIR: "$CI_PROJECT_DIR"
  script:
    - /usr/bin/entrypoint.sh sonar-scanner -Dsonar.projectKey="$CI_PROJECT_NAME"
  tags:
    - sonarqube

upload_linux_shell:
  stage: upload_linux_shell
  only:
    - tags
  image: curlimages/curl:7.76.1
  script:
    - 'curl -sSf -H "X-JFrog-Art-Api:${ARTIFACTORY_TOKEN}" -X PUT -T ./${ARTIFACT_NAME}.sh ${ARTIFACTORY_BASE_URL}/${ARTIFACT_NAME}.sh'
  tags:
    - sonarqube

upload_linux_amd64_binary:
  stage: upload_linux_amd64_binary
  only:
    - tags
  script:
    - ./build.sh --os=linux --arch=amd64 --version=$CI_COMMIT_TAG --upx
    - 'curl -sSf -H "X-JFrog-Art-Api:${ARTIFACTORY_TOKEN}" -X PUT -T ./$ARTIFACT_NAME ${ARTIFACTORY_BASE_URL}/${ARTIFACT_NAME}_linux_amd64'
  tags:
    - visnu_shell

upload_windows_amd64_binary:
  stage: upload_windows_amd64_binary
  only:
    - tags
  script:
    - ./build.sh --os=windows --arch=amd64 --version=$CI_COMMIT_TAG --upx
    - 'curl -sSf -H "X-JFrog-Art-Api:${ARTIFACTORY_TOKEN}" -X PUT -T ./${ARTIFACT_NAME}.exe ${ARTIFACTORY_BASE_URL}/${ARTIFACT_NAME}_windows_amd64.exe'
  tags:
    - visnu_shell
