pipeline {
  agent any
  stages {
    stage('Pre-Build') {
      steps {
        sh '''mix local.hex --force
mix local.rebar --force'''
      }
    }
    stage('Build') {
      steps {
        sh '''mix deps.get
mix compile'''
      }
    }
    stage('Unit') {
      steps {
        sh '''mix ecto.create
mix ecto.migrate
mix coveralls.html --trace --preload-modules'''
        junit '_build/pleroma-junit.xml'
        archiveArtifacts(artifacts: 'cover/excoveralls.html', allowEmptyArchive: true)
      }
    }
    stage('Analysis') {
      parallel {
        stage('Credo') {
          steps {
            sh 'mix credo --strict --only=warnings,todo,fixme,consistency,readability'
          }
        }
        stage('Lint') {
          steps {
            sh 'mix format --check-formatted'
          }
        }
      }
    }
  }
  environment {
    MIX_ENV = 'test'
  }
}