image: node:16

pipelines:
  default:
    - parallel:
        - step:
            name: Build and Test
            caches:
              - node
            script:
              - npm install
              - npm test
              - npm run eslint
        - step:
            name: Lint the node package
            script:
              - npm install eslint
              - npx eslint .
            caches:
              - node
  branches:
    main:
      - parallel:
          - step:
              name: Build and Test
              caches:
                - node
              script:
                - npm install
                # - npm test
          - step:
              name: Security Scan
              script:
                - pipe: atlassian/git-secrets-scan:0.5.1
      - step:
          name: Deploy to Production
          deployment: Production
          script:
            - npm --no-git-tag-version version "1.1.$BITBUCKET_BUILD_NUMBER" -m "Upgrade to new version"
            - npm install
            - npm run build
            - pipe: atlassian/npm-publish:0.3.2
              variables:
                NPM_TOKEN: $NPM_TOKEN
                EXTRA_ARGS: '--access public'
            - git tag -a "1.1.$BITBUCKET_BUILD_NUMBER" -m "Version 1.1.$BITBUCKET_BUILD_NUMBER"
            - git push origin "1.1.$BITBUCKET_BUILD_NUMBER"
