image: node:20-alpine3.18

stages:
  - publish

appwrite-database-repository:publish-pre:
  stage: publish
  variables:
    PROJECT_DIR: appwrite-database-repository
  only:
    - develop
  script:
    - apk add --no-cache git
    - cd $PROJECT_DIR
    - npm i
    - npm run build
    - npm config set //registry.npmjs.org/:_authToken ${NPM_PUBLSH_KEY}
    - VERSION=$(npm version prerelease --preid=develop)-$CI_PIPELINE_ID
    - git tag $VERSION
    - npm config set git-tag-version=false
    - npm version $(git describe --tags)
    - npm publish

appwrite-database-repository:publish-release:
  stage: publish
  variables:
    PROJECT_DIR: appwrite-database-repository
  only:
    - main
  script:
    - cd $PROJECT_DIR
    - npm i
    - npm run build
    - npm config set //registry.npmjs.org/:_authToken ${NPM_PUBLSH_KEY}
    - npm publish
