image: node:16.20

publish-on-gitlab-project:
    stage: deploy
    only:
        - tags
    variables:
        GITLAB_REGISTRY: ${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/
        GITLAB_TOKEN: ${CI_JOB_TOKEN}
    script:
        - echo "//${GITLAB_REGISTRY}:_authToken=${GITLAB_TOKEN}" > .npmrc
        - npm publish --registry=https://${GITLAB_REGISTRY}

publish-on-gitlab-public-registry:
    stage: deploy
    only:
        - tags
    variables:
        GITLAB_REGISTRY: ${CI_SERVER_HOST}/api/v4/projects/1375/packages/npm/
        GITLAB_TOKEN: ${CI_JOB_TOKEN}
    script:
          - echo "//${GITLAB_REGISTRY}:_authToken=${GITLAB_TOKEN}" > .npmrc
          - npm publish --registry=https://${GITLAB_REGISTRY}

publish-on-nexus:
    stage: deploy
    only:
        - tags
    variables:
        NEXUS_REGISTRY: nexus.adito.cloud/repository/xrm/
        NEXUS_TOKEN: ${NEXUS_TOKEN}
    script:
        - echo "//${NEXUS_REGISTRY}:_authToken=${NEXUS_TOKEN}" > .npmrc
        - npm publish --registry=https://${NEXUS_REGISTRY}

trigger-root:
    stage: deploy
    needs:
        - publish-on-gitlab-public-registry
    script:
        - apt update && apt install -y curl
        - 'curl --fail --request POST --form "variables[ADITO_COMMIT_MESSAGE]=$CI_COMMIT_MESSAGE" --form "token=$PUSH_TRIGGER_TOKEN" --form "ref=$CI_COMMIT_BRANCH" "https://gitlab.adito.de/api/v4/projects/676/trigger/pipeline"'
    only:
        - tags