<commit_before>---
kind: pipeline
name: default

# Disable default clone
clone:
  disable: true

steps:
  # This clone step doesn't use "root" user
  - name: clone
    image: plugins/git:next

  # Restore cache of downloaded dependencies
  - name: restore-cache
    image: drillster/drone-volume-cache
    settings:
      restore: true
      mount:
        - .sbt
        - .ivy2
        - ui/node_modules
        - ui/bower_components
    volumes: [{name: cache, path: /cache}]

  # Run project tests
  - name: run-tests
    image: thehiveproject/drone-scala-node
    commands:
      - . ~/.nvm/nvm.sh
      - sbt -Duser.home=$PWD test stage

  # Build packages
  - name: build-packages
    image: thehiveproject/drone-scala-node
    settings:
      pgp_key: {from_secret: pgp_key}
    commands:
      - |
        . ~/.nvm/nvm.sh
        [ -n "$PLUGIN_PGP_KEY" ] && gpg --batch --import - <<< $PLUGIN_PGP_KEY
        sbt -Duser.home=$PWD docker:stage debian:packageBin rpm:packageBin universal:packageBin
    when:
      event: [tag]

  # Save external libraries in cache
  - name: save-cache
    image: drillster/drone-volume-cache
    settings:
      rebuild: true
      mount:
        - .sbt
        - .ivy2
        - ui/node_modules
        - ui/bower_components
    volumes: [{name: cache, path: /cache}]

  - name: publish-package
    image: thehiveproject/drone-bintray
    settings:
      user: {from_secret: bintray_user}
      key: {from_secret: bintray_key}
      subject: thehive-project
      package: thehive
    commands:
      - |
        export PLUGIN_USER
        export PLUGIN_KEY
        export PLUGIN_SUBJECT
        export PLUGIN_PACKAGE
        export PLUGIN_VERSION=$(cut -d\" -f2 version.sbt)
        echo "Publishing package version $PLUGIN_VERSION"

        if echo $PLUGIN_VERSION | grep -qvi -E \
            -e '^[0-9]+\.[0-9]+\.[0-9]+$' \
            -e '^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$' \
            -e '^[0-9]+\.[0-9]+\.[0-9]+-RC[0-9]+$'; then
          echo The version $PLUGIN_VERSION has invalid format
          exit 1
        fi

        CHANNEL=stable
        if $(echo $PLUGIN_VERSION | grep -qi rc)
        then
          CHANNEL=beta
          V=$(echo $PLUGIN_VERSION | sed -e 's/-\([rR][cC]\)/-0.1\1/')
          DEB_FILE=target/thehive_$${V}_all.deb
          RPM_FILE=target/rpm/RPMS/noarch/thehive-$${V}.noarch.rpm
        else
          DEB_FILE=target/thehive_$${PLUGIN_VERSION}_all.deb
          RPM_FILE=target/rpm/RPMS/noarch/thehive-$${PLUGIN_VERSION}.noarch.rpm
        fi

        ZIP_FILE=target/universal/thehive-$${PLUGIN_VERSION}.zip

        upload \
          --file $DEB_FILE \
          --repo debian-beta \
          --extra-param deb_distribution=any \
          --extra-param deb_component=main \
          --extra-param deb_architecture=all

        [ $CHANNEL = stable ] && upload \
          --file $DEB_FILE \
          --repo debian-stable \
          --extra-param deb_distribution=any \
          --extra-param deb_component=main \
          --extra-param deb_architecture=all

        upload \
          --file $RPM_FILE \
          --repo rpm-beta

        [ $CHANNEL = stable ] && upload \
          --file $RPM_FILE \
          --repo rpm-stable

        upload \
          --file $ZIP_FILE \
          --repo binary

        LATEST_VERSION=latest
        [ $CHANNEL = beta ] && LATEST_VERSION=latest-beta

        removeVersion \
          --repo binary \
          --version $LATEST_VERSION

        upload \
          --file $ZIP_FILE \
          --repo binary \
          --version $LATEST_VERSION \
          --dest-file thehive-$${LATEST_VERSION}.zip
    when:
      event: [tag]

  # Publish docker image
  - name: docker
    image: plugins/docker
    settings:
      context: target/docker/stage
      dockerfile: target/docker/stage/Dockerfile
      repo: thehiveproject/thehive
      auto_tag: true
      username: {from_secret: docker_username}
      password: {from_secret: docker_password}
    when:
      event: [tag]

  # Deploy binaries in integration environment
  - name: copy binaries in integration environment
    image: appleboy/drone-scp
    settings:
      host: {from_secret: deploy_beta_host}
      username: {from_secret: deploy_username}
      key: {from_secret: deploy_key}
      target: ./thehive-builds/${DRONE_BUILD_NUMBER}
      source: target/universal/stage
      strip_components: 3
    when:
      branch: [develop]

  - name: deploy binaries in integration environment
    image: appleboy/drone-ssh
    settings:
      host: {from_secret: deploy_beta_host}
      username: {from_secret: deploy_username}
      key: {from_secret: deploy_key}
      script:
        - ./start thehive ${DRONE_BUILD_NUMBER}
    when:
      branch: [develop]

  # Deploy binaries in staging environment
  - name: copy binaries in staging environment
    image: appleboy/drone-scp
    settings:
      host: {from_secret: deploy_stable_host}
      username: {from_secret: deploy_username}
      key: {from_secret: deploy_key}
      target: ./thehive-builds/${DRONE_BUILD_NUMBER}
      source: target/universal/stage
      strip_components: 3
    when:
      branch: [master]

  - name: deploy binaries in staging environment
    image: appleboy/drone-ssh
    settings:
      host: {from_secret: deploy_stable_host}
      username: {from_secret: deploy_username}
      key: {from_secret: deploy_key}
      script:
        - ./start thehive ${DRONE_BUILD_NUMBER}
    when:
      branch: [master]

volumes:
  - name: cache
    host:
      path: /opt/drone/cache<commit_msg>#882 Disable deployment on pull-requests<commit_after>---
kind: pipeline
name: default

# Disable default clone
clone:
  disable: true

steps:
  # This clone step doesn't use "root" user
  - name: clone
    image: plugins/git:next

  # Restore cache of downloaded dependencies
  - name: restore-cache
    image: drillster/drone-volume-cache
    settings:
      restore: true
      mount:
        - .sbt
        - .ivy2
        - ui/node_modules
        - ui/bower_components
    volumes: [{name: cache, path: /cache}]

  # Run project tests
  - name: run-tests
    image: thehiveproject/drone-scala-node
    commands:
      - . ~/.nvm/nvm.sh
      - sbt -Duser.home=$PWD test stage

  # Build packages
  - name: build-packages
    image: thehiveproject/drone-scala-node
    settings:
      pgp_key: {from_secret: pgp_key}
    commands:
      - |
        . ~/.nvm/nvm.sh
        [ -n "$PLUGIN_PGP_KEY" ] && gpg --batch --import - <<< $PLUGIN_PGP_KEY
        sbt -Duser.home=$PWD docker:stage debian:packageBin rpm:packageBin universal:packageBin
    when:
      event: [tag]

  # Save external libraries in cache
  - name: save-cache
    image: drillster/drone-volume-cache
    settings:
      rebuild: true
      mount:
        - .sbt
        - .ivy2
        - ui/node_modules
        - ui/bower_components
    volumes: [{name: cache, path: /cache}]

  - name: publish-package
    image: thehiveproject/drone-bintray
    settings:
      user: {from_secret: bintray_user}
      key: {from_secret: bintray_key}
      subject: thehive-project
      package: thehive
    commands:
      - |
        export PLUGIN_USER
        export PLUGIN_KEY
        export PLUGIN_SUBJECT
        export PLUGIN_PACKAGE
        export PLUGIN_VERSION=$(cut -d\" -f2 version.sbt)
        echo "Publishing package version $PLUGIN_VERSION"

        if echo $PLUGIN_VERSION | grep -qvi -E \
            -e '^[0-9]+\.[0-9]+\.[0-9]+$' \
            -e '^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$' \
            -e '^[0-9]+\.[0-9]+\.[0-9]+-RC[0-9]+$'; then
          echo The version $PLUGIN_VERSION has invalid format
          exit 1
        fi

        CHANNEL=stable
        if $(echo $PLUGIN_VERSION | grep -qi rc)
        then
          CHANNEL=beta
          V=$(echo $PLUGIN_VERSION | sed -e 's/-\([rR][cC]\)/-0.1\1/')
          DEB_FILE=target/thehive_$${V}_all.deb
          RPM_FILE=target/rpm/RPMS/noarch/thehive-$${V}.noarch.rpm
        else
          DEB_FILE=target/thehive_$${PLUGIN_VERSION}_all.deb
          RPM_FILE=target/rpm/RPMS/noarch/thehive-$${PLUGIN_VERSION}.noarch.rpm
        fi

        ZIP_FILE=target/universal/thehive-$${PLUGIN_VERSION}.zip

        upload \
          --file $DEB_FILE \
          --repo debian-beta \
          --extra-param deb_distribution=any \
          --extra-param deb_component=main \
          --extra-param deb_architecture=all

        [ $CHANNEL = stable ] && upload \
          --file $DEB_FILE \
          --repo debian-stable \
          --extra-param deb_distribution=any \
          --extra-param deb_component=main \
          --extra-param deb_architecture=all

        upload \
          --file $RPM_FILE \
          --repo rpm-beta

        [ $CHANNEL = stable ] && upload \
          --file $RPM_FILE \
          --repo rpm-stable

        upload \
          --file $ZIP_FILE \
          --repo binary

        LATEST_VERSION=latest
        [ $CHANNEL = beta ] && LATEST_VERSION=latest-beta

        removeVersion \
          --repo binary \
          --version $LATEST_VERSION

        upload \
          --file $ZIP_FILE \
          --repo binary \
          --version $LATEST_VERSION \
          --dest-file thehive-$${LATEST_VERSION}.zip
    when:
      event: [tag]

  # Publish docker image
  - name: docker
    image: plugins/docker
    settings:
      context: target/docker/stage
      dockerfile: target/docker/stage/Dockerfile
      repo: thehiveproject/thehive
      auto_tag: true
      username: {from_secret: docker_username}
      password: {from_secret: docker_password}
    when:
      event: [tag]

  # Deploy binaries in integration environment
  - name: copy binaries in integration environment
    image: appleboy/drone-scp
    settings:
      host: {from_secret: deploy_beta_host}
      username: {from_secret: deploy_username}
      key: {from_secret: deploy_key}
      target: ./thehive-builds/${DRONE_BUILD_NUMBER}
      source: target/universal/stage
      strip_components: 3
    when:
      branch: [develop]
      repo: TheHive-Project/TheHive

  - name: deploy binaries in integration environment
    image: appleboy/drone-ssh
    settings:
      host: {from_secret: deploy_beta_host}
      username: {from_secret: deploy_username}
      key: {from_secret: deploy_key}
      script:
        - ./start thehive ${DRONE_BUILD_NUMBER}
    when:
      branch: [develop]
      repo: TheHive-Project/TheHive

  # Deploy binaries in staging environment
  - name: copy binaries in staging environment
    image: appleboy/drone-scp
    settings:
      host: {from_secret: deploy_stable_host}
      username: {from_secret: deploy_username}
      key: {from_secret: deploy_key}
      target: ./thehive-builds/${DRONE_BUILD_NUMBER}
      source: target/universal/stage
      strip_components: 3
    when:
      branch: [master]
      repo: TheHive-Project/TheHive

  - name: deploy binaries in staging environment
    image: appleboy/drone-ssh
    settings:
      host: {from_secret: deploy_stable_host}
      username: {from_secret: deploy_username}
      key: {from_secret: deploy_key}
      script:
        - ./start thehive ${DRONE_BUILD_NUMBER}
    when:
      branch: [master]
      repo: TheHive-Project/TheHive

volumes:
  - name: cache
    host:
      path: /opt/drone/cache
{'fraction_non_alphanumeric': 0.11259626449499867, 'fraction_numerical': 0.005753739930955121, 'mean_word_length': 2.027331189710611, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1001547', 'n_tokens_mistral': 3787, 'n_tokens_neox': 3640, 'n_words': 795}