# Generated from xtask::workflows::release_nightly
# Rebuild with `cargo xtask workflows`.
name: release_nightly
env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: '0'
  RUST_BACKTRACE: '1'
  ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
  ZED_MINIDUMP_ENDPOINT: ${{ secrets.ZED_SENTRY_MINIDUMP_ENDPOINT }}
  DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
  DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
on:
  push:
    tags:
    - nightly
  schedule:
  - cron: 0 7 * * *
jobs:
  check_style:
    if: github.repository_owner == 'zed-industries'
    runs-on: self-mini-macos
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
        fetch-depth: 0
    - name: steps::cargo_fmt
      run: cargo fmt --all -- --check
      shell: bash -euxo pipefail {0}
    - name: ./script/clippy
      run: ./script/clippy
      shell: bash -euxo pipefail {0}
    timeout-minutes: 60
  run_tests_mac:
    if: github.repository_owner == 'zed-industries'
    runs-on: self-mini-macos
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
      shell: bash -euxo pipefail {0}
    - name: steps::setup_node
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
      with:
        node-version: '20'
    - name: steps::clippy
      run: ./script/clippy
      shell: bash -euxo pipefail {0}
    - name: steps::cargo_install_nextest
      run: cargo nextest || cargo install cargo-nextest --locked
      shell: bash -euxo pipefail {0}
    - name: steps::clear_target_dir_if_large
      run: ./script/clear-target-dir-if-larger-than 300
      shell: bash -euxo pipefail {0}
    - name: steps::cargo_nextest
      run: cargo nextest run --workspace --no-fail-fast --failure-output immediate-final
      shell: bash -euxo pipefail {0}
    - name: steps::cleanup_cargo_config
      if: always()
      run: |
        rm -rf ./../.cargo
      shell: bash -euxo pipefail {0}
    timeout-minutes: 60
  run_tests_windows:
    if: github.repository_owner == 'zed-industries'
    runs-on: self-32vcpu-windows-2022
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        New-Item -ItemType Directory -Path "./../.cargo" -Force
        Copy-Item -Path "./.cargo/ci-config.toml" -Destination "./../.cargo/config.toml"
      shell: pwsh
    - name: steps::setup_node
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
      with:
        node-version: '20'
    - name: steps::clippy
      run: ./script/clippy.ps1
      shell: pwsh
    - name: steps::cargo_install_nextest
      run: cargo nextest || cargo install cargo-nextest --locked
      shell: pwsh
    - name: steps::clear_target_dir_if_large
      run: ./script/clear-target-dir-if-larger-than.ps1 250
      shell: pwsh
    - name: steps::cargo_nextest
      run: cargo nextest run --workspace --no-fail-fast --failure-output immediate-final
      shell: pwsh
    - name: steps::cleanup_cargo_config
      if: always()
      run: |
        Remove-Item -Recurse -Path "./../.cargo" -Force -ErrorAction SilentlyContinue
      shell: pwsh
    timeout-minutes: 60
  bundle_mac_nightly_x86_64:
    needs:
    - check_style
    - run_tests_mac
    if: github.repository_owner == 'zed-industries'
    runs-on: self-mini-macos
    env:
      MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
      MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
      APPLE_NOTARIZATION_KEY: ${{ secrets.APPLE_NOTARIZATION_KEY }}
      APPLE_NOTARIZATION_KEY_ID: ${{ secrets.APPLE_NOTARIZATION_KEY_ID }}
      APPLE_NOTARIZATION_ISSUER_ID: ${{ secrets.APPLE_NOTARIZATION_ISSUER_ID }}
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: steps::setup_node
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
      with:
        node-version: '20'
    - name: steps::setup_sentry
      uses: matbour/setup-sentry-cli@3e938c54b3018bdd019973689ef984e033b0454b
      with:
        token: ${{ secrets.SENTRY_AUTH_TOKEN }}
    - name: steps::clear_target_dir_if_large
      run: ./script/clear-target-dir-if-larger-than 300
      shell: bash -euxo pipefail {0}
    - name: release_nightly::set_release_channel_to_nightly
      run: |
        set -eu
        version=$(git rev-parse --short HEAD)
        echo "Publishing version: ${version} on release channel nightly"
        echo "nightly" > crates/zed/RELEASE_CHANNEL
      shell: bash -euxo pipefail {0}
    - name: run_bundling::bundle_mac
      run: ./script/bundle-mac x86_64-apple-darwin
      shell: bash -euxo pipefail {0}
    - name: release_nightly::upload_zed_nightly
      run: script/upload-nightly macos x86_64
      shell: bash -euxo pipefail {0}
    timeout-minutes: 60
  bundle_mac_nightly_aarch64:
    needs:
    - check_style
    - run_tests_mac
    if: github.repository_owner == 'zed-industries'
    runs-on: self-mini-macos
    env:
      MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
      MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
      APPLE_NOTARIZATION_KEY: ${{ secrets.APPLE_NOTARIZATION_KEY }}
      APPLE_NOTARIZATION_KEY_ID: ${{ secrets.APPLE_NOTARIZATION_KEY_ID }}
      APPLE_NOTARIZATION_ISSUER_ID: ${{ secrets.APPLE_NOTARIZATION_ISSUER_ID }}
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: steps::setup_node
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
      with:
        node-version: '20'
    - name: steps::setup_sentry
      uses: matbour/setup-sentry-cli@3e938c54b3018bdd019973689ef984e033b0454b
      with:
        token: ${{ secrets.SENTRY_AUTH_TOKEN }}
    - name: steps::clear_target_dir_if_large
      run: ./script/clear-target-dir-if-larger-than 300
      shell: bash -euxo pipefail {0}
    - name: release_nightly::set_release_channel_to_nightly
      run: |
        set -eu
        version=$(git rev-parse --short HEAD)
        echo "Publishing version: ${version} on release channel nightly"
        echo "nightly" > crates/zed/RELEASE_CHANNEL
      shell: bash -euxo pipefail {0}
    - name: run_bundling::bundle_mac
      run: ./script/bundle-mac aarch64-apple-darwin
      shell: bash -euxo pipefail {0}
    - name: release_nightly::upload_zed_nightly
      run: script/upload-nightly macos aarch64
      shell: bash -euxo pipefail {0}
    timeout-minutes: 60
  bundle_linux_nightly_x86_64:
    needs:
    - check_style
    - run_tests_mac
    if: github.repository_owner == 'zed-industries'
    runs-on: namespace-profile-32x64-ubuntu-2004
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: steps::setup_sentry
      uses: matbour/setup-sentry-cli@3e938c54b3018bdd019973689ef984e033b0454b
      with:
        token: ${{ secrets.SENTRY_AUTH_TOKEN }}
    - name: release_nightly::add_rust_to_path
      run: echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
      shell: bash -euxo pipefail {0}
    - name: ./script/linux
      run: ./script/linux
      shell: bash -euxo pipefail {0}
    - name: ./script/install-mold
      run: ./script/install-mold
      shell: bash -euxo pipefail {0}
    - name: steps::clear_target_dir_if_large
      run: ./script/clear-target-dir-if-larger-than 100
      shell: bash -euxo pipefail {0}
    - name: release_nightly::set_release_channel_to_nightly
      run: |
        set -eu
        version=$(git rev-parse --short HEAD)
        echo "Publishing version: ${version} on release channel nightly"
        echo "nightly" > crates/zed/RELEASE_CHANNEL
      shell: bash -euxo pipefail {0}
    - name: ./script/bundle-linux
      run: ./script/bundle-linux
      shell: bash -euxo pipefail {0}
    - name: release_nightly::upload_zed_nightly
      run: script/upload-nightly linux-targz x86_64
      shell: bash -euxo pipefail {0}
    timeout-minutes: 60
  bundle_linux_nightly_aarch64:
    needs:
    - check_style
    - run_tests_mac
    if: github.repository_owner == 'zed-industries'
    runs-on: namespace-profile-8x32-ubuntu-2004-arm-m4
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: steps::setup_sentry
      uses: matbour/setup-sentry-cli@3e938c54b3018bdd019973689ef984e033b0454b
      with:
        token: ${{ secrets.SENTRY_AUTH_TOKEN }}
    - name: release_nightly::add_rust_to_path
      run: echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
      shell: bash -euxo pipefail {0}
    - name: ./script/linux
      run: ./script/linux
      shell: bash -euxo pipefail {0}
    - name: steps::clear_target_dir_if_large
      run: ./script/clear-target-dir-if-larger-than 100
      shell: bash -euxo pipefail {0}
    - name: release_nightly::set_release_channel_to_nightly
      run: |
        set -eu
        version=$(git rev-parse --short HEAD)
        echo "Publishing version: ${version} on release channel nightly"
        echo "nightly" > crates/zed/RELEASE_CHANNEL
      shell: bash -euxo pipefail {0}
    - name: ./script/bundle-linux
      run: ./script/bundle-linux
      shell: bash -euxo pipefail {0}
    - name: release_nightly::upload_zed_nightly
      run: script/upload-nightly linux-targz aarch64
      shell: bash -euxo pipefail {0}
    timeout-minutes: 60
  bundle_windows_nightly_x86_64:
    needs:
    - check_style
    - run_tests_windows
    if: github.repository_owner == 'zed-industries'
    runs-on: self-32vcpu-windows-2022
    env:
      AZURE_TENANT_ID: ${{ secrets.AZURE_SIGNING_TENANT_ID }}
      AZURE_CLIENT_ID: ${{ secrets.AZURE_SIGNING_CLIENT_ID }}
      AZURE_CLIENT_SECRET: ${{ secrets.AZURE_SIGNING_CLIENT_SECRET }}
      ACCOUNT_NAME: ${{ vars.AZURE_SIGNING_ACCOUNT_NAME }}
      CERT_PROFILE_NAME: ${{ vars.AZURE_SIGNING_CERT_PROFILE_NAME }}
      ENDPOINT: ${{ vars.AZURE_SIGNING_ENDPOINT }}
      FILE_DIGEST: SHA256
      TIMESTAMP_DIGEST: SHA256
      TIMESTAMP_SERVER: http://timestamp.acs.microsoft.com
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: steps::setup_sentry
      uses: matbour/setup-sentry-cli@3e938c54b3018bdd019973689ef984e033b0454b
      with:
        token: ${{ secrets.SENTRY_AUTH_TOKEN }}
    - name: release_nightly::set_release_channel_to_nightly
      run: |
        $ErrorActionPreference = "Stop"
        $version = git rev-parse --short HEAD
        Write-Host "Publishing version: $version on release channel nightly"
        "nightly" | Set-Content -Path "crates/zed/RELEASE_CHANNEL"
      shell: pwsh
      working-directory: ${{ env.ZED_WORKSPACE }}
    - name: release_nightly::build_zed_installer
      run: script/bundle-windows.ps1 -Architecture x86_64
      shell: pwsh
      working-directory: ${{ env.ZED_WORKSPACE }}
    - name: release_nightly::upload_zed_nightly_windows
      run: script/upload-nightly.ps1 -Architecture x86_64
      shell: pwsh
      working-directory: ${{ env.ZED_WORKSPACE }}
    timeout-minutes: 60
  bundle_windows_nightly_aarch64:
    needs:
    - check_style
    - run_tests_windows
    if: github.repository_owner == 'zed-industries'
    runs-on: self-32vcpu-windows-2022
    env:
      AZURE_TENANT_ID: ${{ secrets.AZURE_SIGNING_TENANT_ID }}
      AZURE_CLIENT_ID: ${{ secrets.AZURE_SIGNING_CLIENT_ID }}
      AZURE_CLIENT_SECRET: ${{ secrets.AZURE_SIGNING_CLIENT_SECRET }}
      ACCOUNT_NAME: ${{ vars.AZURE_SIGNING_ACCOUNT_NAME }}
      CERT_PROFILE_NAME: ${{ vars.AZURE_SIGNING_CERT_PROFILE_NAME }}
      ENDPOINT: ${{ vars.AZURE_SIGNING_ENDPOINT }}
      FILE_DIGEST: SHA256
      TIMESTAMP_DIGEST: SHA256
      TIMESTAMP_SERVER: http://timestamp.acs.microsoft.com
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: steps::setup_sentry
      uses: matbour/setup-sentry-cli@3e938c54b3018bdd019973689ef984e033b0454b
      with:
        token: ${{ secrets.SENTRY_AUTH_TOKEN }}
    - name: release_nightly::set_release_channel_to_nightly
      run: |
        $ErrorActionPreference = "Stop"
        $version = git rev-parse --short HEAD
        Write-Host "Publishing version: $version on release channel nightly"
        "nightly" | Set-Content -Path "crates/zed/RELEASE_CHANNEL"
      shell: pwsh
      working-directory: ${{ env.ZED_WORKSPACE }}
    - name: release_nightly::build_zed_installer
      run: script/bundle-windows.ps1 -Architecture aarch64
      shell: pwsh
      working-directory: ${{ env.ZED_WORKSPACE }}
    - name: release_nightly::upload_zed_nightly_windows
      run: script/upload-nightly.ps1 -Architecture aarch64
      shell: pwsh
      working-directory: ${{ env.ZED_WORKSPACE }}
    timeout-minutes: 60
  build_nix_linux_x86_64:
    needs:
    - check_style
    - run_tests_mac
    if: github.repository_owner == 'zed-industries'
    runs-on: namespace-profile-32x64-ubuntu-2004
    env:
      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
      ZED_MINIDUMP_ENDPOINT: ${{ secrets.ZED_SENTRY_MINIDUMP_ENDPOINT }}
      ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON: ${{ secrets.ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON }}
      GIT_LFS_SKIP_SMUDGE: '1'
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: nix_build::install_nix
      uses: cachix/install-nix-action@02a151ada4993995686f9ed4f1be7cfbb229e56f
      with:
        github_access_token: ${{ secrets.GITHUB_TOKEN }}
    - name: nix_build::cachix_action
      uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad
      with:
        name: zed
        authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
        cachixArgs: -v
    - name: nix_build::build
      run: nix build .#default -L --accept-flake-config
      shell: bash -euxo pipefail {0}
    timeout-minutes: 60
    continue-on-error: true
  build_nix_mac_aarch64:
    needs:
    - check_style
    - run_tests_mac
    if: github.repository_owner == 'zed-industries'
    runs-on: self-mini-macos
    env:
      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
      ZED_MINIDUMP_ENDPOINT: ${{ secrets.ZED_SENTRY_MINIDUMP_ENDPOINT }}
      ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON: ${{ secrets.ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON }}
      GIT_LFS_SKIP_SMUDGE: '1'
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
    - name: nix_build::set_path
      run: |
        echo "/nix/var/nix/profiles/default/bin" >> "$GITHUB_PATH"
        echo "/Users/administrator/.nix-profile/bin" >> "$GITHUB_PATH"
      shell: bash -euxo pipefail {0}
    - name: nix_build::cachix_action
      uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad
      with:
        name: zed
        authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
        cachixArgs: -v
    - name: nix_build::build
      run: nix build .#default -L --accept-flake-config
      shell: bash -euxo pipefail {0}
    - name: nix_build::limit_store
      run: |-
        if [ "$(du -sm /nix/store | cut -f1)" -gt 50000 ]; then
            nix-collect-garbage -d || true
        fi
      shell: bash -euxo pipefail {0}
    timeout-minutes: 60
    continue-on-error: true
  update_nightly_tag:
    needs:
    - bundle_mac_nightly_x86_64
    - bundle_mac_nightly_aarch64
    - bundle_linux_nightly_x86_64
    - bundle_linux_nightly_aarch64
    - bundle_windows_nightly_x86_64
    - bundle_windows_nightly_aarch64
    if: github.repository_owner == 'zed-industries'
    runs-on: namespace-profile-2x4-ubuntu-2404
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        clean: false
        fetch-depth: 0
    - name: release_nightly::update_nightly_tag
      run: |
        if [ "$(git rev-parse nightly)" = "$(git rev-parse HEAD)" ]; then
          echo "Nightly tag already points to current commit. Skipping tagging."
          exit 0
        fi
        git config user.name github-actions
        git config user.email github-actions@github.com
        git tag -f nightly
        git push origin nightly --force
      shell: bash -euxo pipefail {0}
    - name: release_nightly::create_sentry_release
      uses: getsentry/action-release@526942b68292201ac6bbb99b9a0747d4abee354c
      with:
        environment: production
      env:
        SENTRY_ORG: zed-dev
        SENTRY_PROJECT: zed
        SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
    timeout-minutes: 60
