resources:
- repo: self
steps:
- bash: |
    echo 'Non release VSTS builds do not run on older branches'
  displayName: Skip build on older branch
  condition: ne(variables['ELECTRON_RELEASE'], '1')

- bash: |
    git clean -fdx
  displayName: Clean unneeded git directories
  timeoutInMinutes: 2
  condition: eq(variables['ELECTRON_RELEASE'], '1')

- bash: |
    echo 'Bootstrapping Electron for release build'
    script/bootstrap.py --target_arch=$TARGET_ARCH
  name: Bootstrap
  condition: eq(variables['ELECTRON_RELEASE'], '1')

- bash: |
    echo 'Building Electron for release'
    script/build.py -c R
  name: Build
  condition: and(succeeded(), eq(variables['ELECTRON_RELEASE'], '1'))

- bash: |
    echo 'Creating Electron release distribution'
    script/create-dist.py
  name: Create_distribution
  condition: and(succeeded(), eq(variables['ELECTRON_RELEASE'], '1'))

- bash: |
    if [ "$UPLOAD_TO_S3" != "1" ]; then
      echo 'Uploading Electron release distribution to github releases'
      ELECTRON_S3_BUCKET="$(s3_bucket)" ELECTRON_S3_ACCESS_KEY="$(s3_access_key)" ELECTRON_S3_SECRET_KEY="$(s3_secret_key)" ELECTRON_GITHUB_TOKEN="$(github_token)" script/upload.py
    else
      echo 'Uploading Electron release distribution to s3'
      ELECTRON_S3_BUCKET="$(s3_bucket)" ELECTRON_S3_ACCESS_KEY="$(s3_access_key)" ELECTRON_S3_SECRET_KEY="$(s3_secret_key)" ELECTRON_GITHUB_TOKEN="$(github_token)" script/upload.py --upload_to_s3
    fi
  name: Upload_distribution
  condition: and(succeeded(), eq(variables['ELECTRON_RELEASE'], '1'))

- task: PublishBuildArtifacts@1
  displayName: Publish Build Artifacts
  inputs:
    PathtoPublish: '$(Build.SourcesDirectory)/out'
    ArtifactName: out
  condition: and(succeeded(), eq(variables['ELECTRON_RELEASE'], '1'))

- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3
