# Build, test and deploy project

image: amsolucionesweb/bitbucket-php81-pipeline:1.0.0


pipelines:
  pull-requests:
    '**':
      - step:
          name: Build & Test
          script:
            - curl ifconfig.me
            - export COMPOSER_ALLOW_SUPERUSER=1
            - export XDEBUG_MODE=coverage
            - export PIP_BREAK_SYSTEM_PACKAGES=1
            - php composer.phar install -o --ignore-platform-reqs
            - pip install djlint
            - npm install
            - chmod +x node_modules/.bin/mjml
            - npm run build
            - npx stylelint assets/web/**/*.vue
            - npx eslint assets/web/components/**/*.vue
            - djlint --check --format-css --format-js ./templates/*.twig ./templates/**/*.twig ./templates/**/**/*.twig
            - djlint --lint ./templates/*.twig ./templates/**/*.twig ./templates/**/**/*.twig
            - php vendor/bin/ecs check --output-format=junit > ./test-reports/cs.xml
            - php vendor/bin/phpstan --error-format=junit > ./test-reports/phpstan.xml
            - php bin/phpunit --log-junit ./test-reports/phpunit.xml --coverage-html="test-reports/coverage"
          caches:
            - composer
            - node
            - pip
          artifacts:
            - test-reports/**
            - var/log/**
  branches:
    develop:
      - step:
          name: Build & Test Develop
          script:
            - curl ifconfig.me
            - export COMPOSER_ALLOW_SUPERUSER=1
            - export XDEBUG_MODE=coverage
            - export PIP_BREAK_SYSTEM_PACKAGES=1
            - php composer.phar install -o --ignore-platform-reqs
            - pip install djlint
            - npm install
            - chmod +x node_modules/.bin/mjml
            - npm run build
            - npx stylelint assets/web/**/*.vue
            - npx eslint assets/web/components/**/*.vue
            - djlint --check --format-css --format-js ./templates/*.twig ./templates/**/*.twig ./templates/**/**/*.twig
            - djlint --lint ./templates/*.twig ./templates/**/*.twig ./templates/**/**/*.twig
            - php vendor/bin/ecs check --output-format=junit > ./test-reports/cs.xml
            - php vendor/bin/phpstan --error-format=junit > ./test-reports/phpstan.xml
            - php bin/phpunit --log-junit ./test-reports/phpunit.xml --coverage-html="test-reports/coverage"
          caches:
            - composer
            - node
            - pip
          artifacts:
            - test-reports/**
            - var/log/**
    stage:
      - step:
          name: Build & Test Staging
          script:
            - curl ifconfig.me
            - export COMPOSER_ALLOW_SUPERUSER=1
            - export XDEBUG_MODE=coverage
            - export PIP_BREAK_SYSTEM_PACKAGES=1
            - php composer.phar install -o --ignore-platform-reqs
            - pip install djlint
            - npm install
            - chmod +x node_modules/.bin/mjml
            - npm run build
            - npx stylelint assets/web/**/*.vue
            - npx eslint assets/web/components/**/*.vue
            - djlint --check --format-css --format-js ./templates/*.twig ./templates/**/*.twig ./templates/**/**/*.twig
            - djlint --lint ./templates/*.twig ./templates/**/*.twig ./templates/**/**/*.twig
            - php vendor/bin/ecs check --output-format=junit > ./test-reports/cs.xml
            - php vendor/bin/phpstan --error-format=junit > ./test-reports/phpstan.xml
            - php bin/phpunit --log-junit ./test-reports/phpunit.xml --coverage-html="test-reports/coverage"
          caches:
            - composer
            - node
            - pip
          artifacts:
              - test-reports/**
              - var/log/**
      - step:
          name: Deployment to Staging
          deployment: staging
          script:
            - pipe: atlassian/rsync-deploy:0.12.0
              variables:
                USER: 'lederjust'
                SERVER: 'stage.lederjust.com'
                REMOTE_PATH: '/home/lederjust/stage'
                LOCAL_PATH: './'
                SSH_PORT: '2200'
                DELETE_FLAG: 'false'
            - pipe: atlassian/ssh-run:0.8.0
              variables:
                SSH_USER: 'lederjust'
                SERVER: 'stage.lederjust.com'
                PORT: '2200'
                COMMAND: 'cd /home/lederjust/stage; /usr/local/bin/ea-php81 composer.phar install -o -n --no-dev; /usr/local/bin/ea-php81 bin/console messenger:stop-workers; npm install --omit=optional; npm run build; rm -rf .bitbucket; rm -rf test-reports; rm -rf .git'
    master:
      - step:
          name: Build & Test Production
          script:
            - curl ifconfig.me
            - export COMPOSER_ALLOW_SUPERUSER=1
            - export XDEBUG_MODE=coverage
            - export PIP_BREAK_SYSTEM_PACKAGES=1
            - php composer.phar install -o --ignore-platform-reqs
            - pip install djlint
            - npm install
            - chmod +x node_modules/.bin/mjml
            - npm run build
            - npx stylelint assets/web/**/*.vue
            - npx eslint assets/web/components/**/*.vue
            - djlint --check --format-css --format-js ./templates/*.twig ./templates/**/*.twig ./templates/**/**/*.twig
            - djlint --lint ./templates/*.twig ./templates/**/*.twig ./templates/**/**/*.twig
            - php vendor/bin/ecs check --output-format=junit > ./test-reports/cs.xml
            - php vendor/bin/phpstan --error-format=junit > ./test-reports/phpstan.xml
            - php bin/phpunit --log-junit ./test-reports/phpunit.xml --coverage-html="test-reports/coverage"
          caches:
            - composer
            - node
            - pip
          artifacts:
            - test-reports/**
            - var/log/**
      - step:
          name: Deployment to Production
          deployment: production
          script:
            - pipe: atlassian/rsync-deploy:0.12.0
              variables:
                USER: 'justicialistas'
                SERVER: 'justicialistas.com.ar'
                REMOTE_PATH: '/home/justicialistas/public_html'
                LOCAL_PATH: './'
                SSH_PORT: '2200'
                DELETE_FLAG: 'false'
            - pipe: atlassian/ssh-run:0.8.0
              variables:
                SSH_USER: 'justicialistas'
                SERVER: 'justicialistas.com.ar'
                PORT: '2200'
                COMMAND: 'cd /home/justicialistas/public_html; /usr/local/bin/ea-php81 composer.phar install -o -n --no-dev; /usr/local/bin/ea-php81 bin/console messenger:stop-workers; npm install --omit=optional; npm run build; rm -rf .bitbucket; rm -rf test-reports; rm -rf .git'