# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0

version: 2.1

jobs:
  dummy:
    docker:
     - image: alpine
    steps:
      - checkout
      - run:
          name: dummy
          command: "echo 'not building gh-pages'"

  build:
    docker:
     - image: jsii/superchain
    steps:
      - run:
          name: fix ssh permissions
          command: chmod 600 /root/.ssh/config
      - checkout
      - run:
          name: install
          command: npm install
      - run:
          name: test
          command: npm run build && npm test
      - run:
          name: package
          command: npm run build && npm run package

  deploy:
    docker:
     - image: jsii/superchain
    steps:
      - run:
          name: fix ssh permissions
          command: chmod 600 /root/.ssh/config
      - checkout
      - run:
          name: install
          command: npm install
      - run:
          name: test
          command: npm run build && npm test
      - run:
          name: package
          command: npm run build && npm run package
      - run:
          name: publish to npm
          command: |
            npx jsii-release-npm dist/js
      - run:
          name: publish to pypi
          command: |
            npx jsii-release-pypi dist/python
      - run:
          name: publish to nuget
          command: |
            npx jsii-release-nuget dist/dotnet
      - run:
          name: publish to maven
          command: |
            npx jsii-release-maven dist/java

workflows:
  version: 2
  validate_build:
    jobs:
      - build:
          filters:
            tags:
              ignore: /.*/
            branches:
              only: master
  build_and_deploy:
    jobs:
      - deploy:
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/
