name: Publish zed-extension CLI

on:
  push:
    tags:
      - extension-cli

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0

jobs:
  publish:
    name: Publish zed-extension CLI
    if: github.repository_owner == 'zed-industries'
    runs-on:
      - ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        with:
          clean: false

      - name: Cache dependencies
        uses: swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2
        with:
          save-if: ${{ github.ref == 'refs/heads/main' }}
          cache-provider: "github"

      - name: Configure linux
        shell: bash -euxo pipefail {0}
        run: script/linux

      - name: Build extension CLI
        run: cargo build --release --package extension_cli

      - name: Upload binary
        env:
          DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
          DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
        run: script/upload-extension-cli ${{ github.sha }}
