---
kind: pipeline
type: docker
name: snapshot

trigger:
  event:
    - push
  branch:
    exclude:
      - master

steps:
  - name: publish-snapshot
    image: node:18
    environment:
      GITEA_TOKEN:
        from_secret: gitea_token
    commands:
      - export VERSION=$(node -p "require('./package.json').version") || echo "1.0.0"
      - SNAPSHOT="$(echo $VERSION)-snapshot.${DRONE_BUILD_NUMBER}"
      - echo $VERSION
      - echo $SNAPSHOT
      - npm ci
      - npm version $SNAPSHOT
      - npm publish --tag snapshot
      # - npm dist-tag add @ioprojects/eslint-config@$SNAPSHOT snapshot

---
kind: pipeline
type: docker
name: checkup

trigger:
  event:
    - push
    - promote
  branch:
    - master

steps:
  - name: package-checkup
    image: node:18
    commands:
      - export DATA=$(node -p "require('./package.json')") || echo "No Data Found"
      - echo "Package Data :"
      - echo $DATA

---
kind: pipeline
type: docker
name: release

trigger:
  event:
    - promote
  branch:
    - master

depends_on:
  - checkup

environment:
  VERSION: ${VERSION}

steps:
  - name: publish-release
    image: node:18
    environment:
      GITEA_TOKEN:
        from_secret: gitea_token
    commands:
      - git fetch --tags
      - npm ci
      - echo $(node -p "require('./package.json').version")
      - echo $VERSION
      - npm version $VERSION
      - git push --set-upstream origin master
      - git tag -l
      - git push --set-upstream origin $(node -p "require('./package.json').version")
      - npm publish