ci.yml

  1name: CI
  2
  3on:
  4  push:
  5    branches:
  6      - main
  7      - "v[0-9]+.[0-9]+.x"
  8    tags:
  9      - "v*"
 10
 11  pull_request:
 12    branches:
 13      - "**"
 14
 15concurrency:
 16  # Allow only one workflow per any non-`main` branch.
 17  group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}
 18  cancel-in-progress: true
 19
 20env:
 21  CARGO_TERM_COLOR: always
 22  CARGO_INCREMENTAL: 0
 23  RUST_BACKTRACE: 1
 24
 25jobs:
 26  migration_checks:
 27    name: Check Postgres and Protobuf migrations, mergability
 28    if: github.repository_owner == 'zed-industries'
 29    timeout-minutes: 60
 30    runs-on:
 31      - self-hosted
 32      - test
 33    steps:
 34      - name: Checkout repo
 35        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
 36        with:
 37          clean: false
 38          fetch-depth: 0 # fetch full history
 39
 40      - name: Remove untracked files
 41        run: git clean -df
 42
 43      - name: Find modified migrations
 44        shell: bash -euxo pipefail {0}
 45        run: |
 46          export SQUAWK_GITHUB_TOKEN=${{ github.token }}
 47          . ./script/squawk
 48
 49      - name: Ensure fresh merge
 50        shell: bash -euxo pipefail {0}
 51        run: |
 52          if [ -z "$GITHUB_BASE_REF" ];
 53          then
 54            echo "BUF_BASE_BRANCH=$(git merge-base origin/main HEAD)" >> $GITHUB_ENV
 55          else
 56            git checkout -B temp
 57            git merge -q origin/$GITHUB_BASE_REF -m "merge main into temp"
 58            echo "BUF_BASE_BRANCH=$GITHUB_BASE_REF" >> $GITHUB_ENV
 59          fi
 60
 61      - uses: bufbuild/buf-setup-action@v1
 62        with:
 63          version: v1.29.0
 64      - uses: bufbuild/buf-breaking-action@v1
 65        with:
 66          input: "crates/proto/proto/"
 67          against: "https://github.com/${GITHUB_REPOSITORY}.git#branch=${BUF_BASE_BRANCH},subdir=crates/proto/proto/"
 68
 69  style:
 70    timeout-minutes: 60
 71    name: Check formatting and spelling
 72    if: github.repository_owner == 'zed-industries'
 73    runs-on:
 74      - buildjet-8vcpu-ubuntu-2204
 75    steps:
 76      - name: Checkout repo
 77        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
 78
 79      # To support writing comments that they will certainly be revisited.
 80      - name: Check for todo! and FIXME comments
 81        run: script/check-todos
 82
 83      - name: Run style checks
 84        uses: ./.github/actions/check_style
 85
 86      - name: Check for typos
 87        uses: crate-ci/typos@8e6a4285bcbde632c5d79900a7779746e8b7ea3f # v1.24.6
 88        with:
 89          config: ./typos.toml
 90
 91  macos_tests:
 92    timeout-minutes: 60
 93    name: (macOS) Run Clippy and tests
 94    if: github.repository_owner == 'zed-industries'
 95    runs-on:
 96      - self-hosted
 97      - test
 98    steps:
 99      - name: Checkout repo
100        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
101        with:
102          clean: false
103
104      - name: Configure CI
105        run: |
106          mkdir -p ./../.cargo
107          cp ./.cargo/ci-config.toml ./../.cargo/config.toml
108
109      - name: cargo clippy
110        run: ./script/clippy
111
112      - name: Check unused dependencies
113        uses: bnjbvr/cargo-machete@main
114
115      - name: Check licenses
116        run: |
117          script/check-licenses
118          script/generate-licenses /tmp/zed_licenses_output
119
120      - name: Check for new vulnerable dependencies
121        if: github.event_name == 'pull_request'
122        uses: actions/dependency-review-action@3b139cfc5fae8b618d3eae3675e383bb1769c019 # v4
123        with:
124          license-check: false
125
126      - name: Run tests
127        uses: ./.github/actions/run_tests
128
129      - name: Build collab
130        run: cargo build -p collab
131
132      - name: Build other binaries and features
133        run: |
134          cargo build --workspace --bins --all-features
135          cargo check -p gpui --features "macos-blade"
136          cargo check -p workspace
137          cargo build -p remote_server
138          cargo check -p gpui --examples
139          script/check-rust-livekit-macos
140
141      # Since the macOS runners are stateful, so we need to remove the config file to prevent potential bug.
142      - name: Clean CI config file
143        if: always()
144        run: rm -rf ./../.cargo
145
146  linux_tests:
147    timeout-minutes: 60
148    name: (Linux) Run Clippy and tests
149    if: github.repository_owner == 'zed-industries'
150    runs-on:
151      - buildjet-16vcpu-ubuntu-2204
152    steps:
153      - name: Add Rust to the PATH
154        run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
155
156      - name: Checkout repo
157        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
158        with:
159          clean: false
160
161      - name: Cache dependencies
162        uses: swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2
163        with:
164          save-if: ${{ github.ref == 'refs/heads/main' }}
165          cache-provider: "buildjet"
166
167      - name: Install Linux dependencies
168        run: ./script/linux
169
170      - name: Configure CI
171        run: |
172          mkdir -p ./../.cargo
173          cp ./.cargo/ci-config.toml ./../.cargo/config.toml
174
175      - name: cargo clippy
176        run: ./script/clippy
177
178      - name: Run tests
179        uses: ./.github/actions/run_tests
180
181      - name: Build other binaries and features
182        run: |
183          cargo build -p zed
184          cargo check -p workspace
185          cargo check -p gpui --examples
186
187      # Even the Linux runner is not stateful, in theory there is no need to do this cleanup.
188      # But, to avoid potential issues in the future if we choose to use a stateful Linux runner and forget to add code
189      # to clean up the config file, I’ve included the cleanup code here as a precaution.
190      # While it’s not strictly necessary at this moment, I believe it’s better to err on the side of caution.
191      - name: Clean CI config file
192        if: always()
193        run: rm -rf ./../.cargo
194
195  build_remote_server:
196    timeout-minutes: 60
197    name: (Linux) Build Remote Server
198    if: github.repository_owner == 'zed-industries'
199    runs-on:
200      - buildjet-16vcpu-ubuntu-2204
201    steps:
202      - name: Add Rust to the PATH
203        run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
204
205      - name: Checkout repo
206        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
207        with:
208          clean: false
209
210      - name: Cache dependencies
211        uses: swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2
212        with:
213          save-if: ${{ github.ref == 'refs/heads/main' }}
214          cache-provider: "buildjet"
215
216      - name: Install Clang & Mold
217        run: ./script/remote-server && ./script/install-mold 2.34.0
218
219      - name: Configure CI
220        run: |
221          mkdir -p ./../.cargo
222          cp ./.cargo/ci-config.toml ./../.cargo/config.toml
223
224      - name: Build Remote Server
225        run: cargo build -p remote_server
226
227      - name: Clean CI config file
228        if: always()
229        run: rm -rf ./../.cargo
230
231  windows_tests:
232    timeout-minutes: 60
233    name: (Windows) Run Clippy and tests
234    if: github.repository_owner == 'zed-industries'
235    runs-on: hosted-windows-1
236    steps:
237      # more info here:- https://github.com/rust-lang/cargo/issues/13020
238      - name: Enable longer pathnames for git
239        run: git config --system core.longpaths true
240
241      - name: Checkout repo
242        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
243        with:
244          clean: false
245
246      - name: Create Dev Drive using ReFS
247        run: ./script/setup-dev-driver.ps1
248
249      # actions/checkout does not let us clone into anywhere outside ${{ github.workspace }}, so we have to copy the clone...
250      - name: Copy Git Repo to Dev Drive
251        run: |
252          Copy-Item -Path "${{ github.workspace }}" -Destination "${{ env.ZED_WORKSPACE }}" -Recurse
253
254      - name: Cache dependencies
255        uses: swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2
256        with:
257          save-if: ${{ github.ref == 'refs/heads/main' }}
258          workspaces: ${{ env.ZED_WORKSPACE }}
259          cache-provider: "github"
260
261      - name: Configure CI
262        run: |
263          mkdir -p ${{ env.CARGO_HOME }} -ErrorAction Ignore
264          cp ./.cargo/ci-config.toml ${{ env.CARGO_HOME }}/config.toml
265
266      - name: cargo clippy
267        working-directory: ${{ env.ZED_WORKSPACE }}
268        # Windows can't run shell scripts, so we need to use `cargo xtask`.
269        run: cargo xtask clippy
270
271      - name: Run tests
272        uses: ./.github/actions/run_tests_windows
273        with:
274          working-directory: ${{ env.ZED_WORKSPACE }}
275
276      - name: Build Zed
277        working-directory: ${{ env.ZED_WORKSPACE }}
278        run: cargo build
279
280      - name: Check dev drive space
281        working-directory: ${{ env.ZED_WORKSPACE }}
282        # `setup-dev-driver.ps1` creates a 100GB drive, with CI taking up ~45GB of the drive.
283        run: ./script/exit-ci-if-dev-drive-is-full.ps1 95
284
285      # Since the Windows runners are stateful, so we need to remove the config file to prevent potential bug.
286      - name: Clean CI config file
287        if: always()
288        run: Remove-Item -Path "${{ env.CARGO_HOME }}/config.toml"  -Force
289
290  bundle-mac:
291    timeout-minutes: 120
292    name: Create a macOS bundle
293    runs-on:
294      - self-hosted
295      - bundle
296    if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
297    needs: [macos_tests]
298    env:
299      MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
300      MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
301      APPLE_NOTARIZATION_KEY: ${{ secrets.APPLE_NOTARIZATION_KEY }}
302      APPLE_NOTARIZATION_KEY_ID: ${{ secrets.APPLE_NOTARIZATION_KEY_ID }}
303      APPLE_NOTARIZATION_ISSUER_ID: ${{ secrets.APPLE_NOTARIZATION_ISSUER_ID }}
304      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
305      ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON: ${{ secrets.ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON }}
306      DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
307      DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
308    steps:
309      - name: Install Node
310        uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
311        with:
312          node-version: "18"
313
314      - name: Checkout repo
315        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
316        with:
317          # We need to fetch more than one commit so that `script/draft-release-notes`
318          # is able to diff between the current and previous tag.
319          #
320          # 25 was chosen arbitrarily.
321          fetch-depth: 25
322          clean: false
323          ref: ${{ github.ref }}
324
325      - name: Limit target directory size
326        run: script/clear-target-dir-if-larger-than 100
327
328      - name: Determine version and release channel
329        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
330        run: |
331          # This exports RELEASE_CHANNEL into env (GITHUB_ENV)
332          script/determine-release-channel
333
334      - name: Draft release notes
335        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
336        run: |
337          mkdir -p target/
338          # Ignore any errors that occur while drafting release notes to not fail the build.
339          script/draft-release-notes "$RELEASE_VERSION" "$RELEASE_CHANNEL" > target/release-notes.md || true
340          script/create-draft-release target/release-notes.md
341        env:
342          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
343
344      - name: Create macOS app bundle
345        run: script/bundle-mac
346
347      - name: Rename binaries
348        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
349        run: |
350          mv target/aarch64-apple-darwin/release/Zed.dmg target/aarch64-apple-darwin/release/Zed-aarch64.dmg
351          mv target/x86_64-apple-darwin/release/Zed.dmg target/x86_64-apple-darwin/release/Zed-x86_64.dmg
352
353      - name: Upload app bundle (aarch64) to workflow run if main branch or specific label
354        uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
355        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
356        with:
357          name: Zed_${{ github.event.pull_request.head.sha || github.sha }}-aarch64.dmg
358          path: target/aarch64-apple-darwin/release/Zed-aarch64.dmg
359
360      - name: Upload app bundle (x86_64) to workflow run if main branch or specific label
361        uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
362        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
363        with:
364          name: Zed_${{ github.event.pull_request.head.sha || github.sha }}-x86_64.dmg
365          path: target/x86_64-apple-darwin/release/Zed-x86_64.dmg
366
367      - uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1
368        name: Upload app bundle to release
369        if: ${{ env.RELEASE_CHANNEL == 'preview' || env.RELEASE_CHANNEL == 'stable' }}
370        with:
371          draft: true
372          prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
373          files: |
374            target/zed-remote-server-macos-x86_64.gz
375            target/zed-remote-server-macos-aarch64.gz
376            target/aarch64-apple-darwin/release/Zed-aarch64.dmg
377            target/x86_64-apple-darwin/release/Zed-x86_64.dmg
378        env:
379          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
380
381  bundle-linux-x86_x64:
382    timeout-minutes: 60
383    name: Linux x86_x64 release bundle
384    runs-on:
385      - buildjet-16vcpu-ubuntu-2004
386    if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
387    needs: [linux_tests]
388    env:
389      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
390      ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON: ${{ secrets.ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON }}
391      DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
392      DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
393    steps:
394      - name: Checkout repo
395        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
396        with:
397          clean: false
398
399      - name: Install Linux dependencies
400        run: ./script/linux && ./script/install-mold 2.34.0
401
402      - name: Determine version and release channel
403        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
404        run: |
405          # This exports RELEASE_CHANNEL into env (GITHUB_ENV)
406          script/determine-release-channel
407
408      - name: Create Linux .tar.gz bundle
409        run: script/bundle-linux
410
411      - name: Upload Linux bundle to workflow run if main branch or specific label
412        uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
413        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
414        with:
415          name: zed-${{ github.event.pull_request.head.sha || github.sha }}-x86_64-unknown-linux-gnu.tar.gz
416          path: target/release/zed-*.tar.gz
417
418      - name: Upload app bundle to release
419        uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1
420        with:
421          draft: true
422          prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
423          files: |
424            target/zed-remote-server-linux-x86_64.gz
425            target/release/zed-linux-x86_64.tar.gz
426        env:
427          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
428
429  bundle-linux-aarch64: # this runs on ubuntu22.04
430    timeout-minutes: 60
431    name: Linux arm64 release bundle
432    runs-on:
433      - buildjet-16vcpu-ubuntu-2204-arm
434    if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
435    needs: [linux_tests]
436    env:
437      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
438      ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON: ${{ secrets.ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON }}
439      DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
440      DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
441    steps:
442      - name: Checkout repo
443        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
444        with:
445          clean: false
446
447      - name: Install Linux dependencies
448        run: ./script/linux
449
450      - name: Determine version and release channel
451        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
452        run: |
453          # This exports RELEASE_CHANNEL into env (GITHUB_ENV)
454          script/determine-release-channel
455
456      - name: Create and upload Linux .tar.gz bundle
457        run: script/bundle-linux
458
459      - name: Upload Linux bundle to workflow run if main branch or specific label
460        uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
461        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
462        with:
463          name: zed-${{ github.event.pull_request.head.sha || github.sha }}-aarch64-unknown-linux-gnu.tar.gz
464          path: target/release/zed-*.tar.gz
465
466      - name: Upload app bundle to release
467        uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1
468        with:
469          draft: true
470          prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
471          files: |
472            target/zed-remote-server-linux-aarch64.gz
473            target/release/zed-linux-aarch64.tar.gz
474        env:
475          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
476
477  auto-release-preview:
478    name: Auto release preview
479    if: ${{ startsWith(github.ref, 'refs/tags/v') && endsWith(github.ref, '-pre') && !endsWith(github.ref, '.0-pre') }}
480    needs: [bundle-mac, bundle-linux-x86_x64, bundle-linux-aarch64]
481    runs-on:
482      - self-hosted
483      - bundle
484    steps:
485      - name: gh release
486        run: gh release edit $GITHUB_REF_NAME --draft=true
487        env:
488          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}