language: node_js

node_js:
  - 22

before_script:
  - export WS_APIKEY=${WS_APIKEY}
  - export WS_USERKEY=${WS_USERKEY}
  - export WS_PRODUCTNAME=${WS_PRODUCTNAME}
  - export WS_PROJECTNAME=Kubernetes-util
  - export WS_WSS_URL=https://ibmets.whitesourcesoftware.com/agent

script:
  - if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npx audit-ci --config audit-ci.json; else npx audit-ci --config audit-ci.json || true; fi
  - npm run lint
  - npm test
  - if [[ "${TRAVIS_TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then npm version --no-git-tag-version "${TRAVIS_TAG}"; fi
  # Perform UA scan on non-PR builds
  - if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then curl -LJO https://unified-agent.s3.amazonaws.com/wss-unified-agent.jar; java -jar wss-unified-agent.jar -d . || echo "UA Scan Error occurred"; fi

# Use npm v9 for deployments (v10 has problems with authentication with api_key)
before_deploy:
  - npm install -g npm@9
  - export NPMJS_API_KEY="${NPMJS_API_KEY_20250107}"

deploy:
  # Publish npm package with tag "next" on release candidates
  - provider: npm
    email: "${NPMJS_EMAIL}"
    api_key: "${NPMJS_API_KEY}"
    tag: next
    skip_cleanup: true
    on:
      tags: true
      condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)$
  # Publish npm package as "latest" on release
  - provider: npm
    email: "${NPMJS_EMAIL}"
    api_key: "${NPMJS_API_KEY}"
    skip_cleanup: true
    on:
      tags: true
      condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+$
