steps:
  - pwsh: |
      # OS specific env variables
      if ($env:AGENT_OS -eq "Windows_NT") {
        $env:SQUIRREL_TEMP="C:/tmp"
        $env:npm_config_build_from_source=true
      }
      elseif ($env:AGENT_OS -eq "Linux") {
        $env:CC=clang
        $env:CXX=clang++
        $env:npm_config_clang=1
        $env:LinuxArgs="--create-debian-package --create-rpm-package"
        $env:SHOULD_SIGN="false"
      }

      # Build Arguments
      ## Creation of Windows Installaer
      if ($env:AGENT_OS -eq "Windows_NT") {
        mkdir -f -p $env:SQUIRREL_TEMP
        if ($env:IS_RELEASE_BRANCH -eq "true") {
          $CreateWindowsInstallaer="--create-windows-installer"
        }
      }

      ## Code Sign
      if ( ($env:SHOULD_SIGN -eq "true") -and (($env:IS_RELEASE_BRANCH -eq "true")  -or ($env:IS_SIGNED_ZIP_BRANCH -eq "true")) ) {
        $CodeSign="--code-sign"
      }

      # Build
      $esc = '--%'
      script/build --no-bootstrap --compress-artifacts $esc $env:LinuxArgs $CodeSign $CreateWindowsInstallaer
    displayName: Build Atom
    env:
      GITHUB_TOKEN: $(GITHUB_TOKEN)
      IS_RELEASE_BRANCH: $(IsReleaseBranch)
      IS_SIGNED_ZIP_BRANCH: $(IsSignedZipBranch)
      ATOM_RELEASE_VERSION: $(ReleaseVersion)
      ATOM_MAC_CODE_SIGNING_CERT_DOWNLOAD_URL: $(ATOM_MAC_CODE_SIGNING_CERT_DOWNLOAD_URL)
      ATOM_MAC_CODE_SIGNING_CERT_PASSWORD: $(ATOM_MAC_CODE_SIGNING_CERT_PASSWORD)
      ATOM_MAC_CODE_SIGNING_KEYCHAIN: $(ATOM_MAC_CODE_SIGNING_KEYCHAIN)
      ATOM_MAC_CODE_SIGNING_KEYCHAIN_PASSWORD: $(ATOM_MAC_CODE_SIGNING_KEYCHAIN_PASSWORD)
      AC_USER: $(AC_USER)
      AC_PASSWORD: $(AC_PASSWORD)
      ATOM_WIN_CODE_SIGNING_CERT_DOWNLOAD_URL: $(ATOM_WIN_CODE_SIGNING_CERT_DOWNLOAD_URL)
      ATOM_WIN_CODE_SIGNING_CERT_PASSWORD: $(ATOM_WIN_CODE_SIGNING_CERT_PASSWORD)

  - script: |
      sudo chown root ./out/atom*-amd64/chrome-sandbox
      sudo chmod 4755 ./out/atom*-amd64/chrome-sandbox
    displayName: Tweaking chrome-sandbox binary
    condition: eq(variables['Agent.OS'], 'Linux')
