ci.yml

  1name: CI
  2
  3on:
  4  push:
  5    branches:
  6      - main
  7      - "v[0-9]+.[0-9]+.x"
  8    tags:
  9      - "v*"
 10  pull_request:
 11    branches:
 12      - "**"
 13
 14concurrency:
 15  # Allow only one workflow per any non-`main` branch.
 16  group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}
 17  cancel-in-progress: true
 18
 19env:
 20  CARGO_TERM_COLOR: always
 21  CARGO_INCREMENTAL: 0
 22  RUST_BACKTRACE: 1
 23
 24jobs:
 25  style:
 26    name: Check formatting and spelling
 27    runs-on:
 28      - self-hosted
 29      - test
 30    steps:
 31      - name: Checkout repo
 32        uses: actions/checkout@v4
 33        with:
 34          clean: false
 35          submodules: "recursive"
 36          fetch-depth: 0
 37
 38      - name: Remove untracked files
 39        run: git clean -df
 40
 41      - name: Set up default .cargo/config.toml
 42        run: cp ./.cargo/ci-config.toml ~/.cargo/config.toml
 43
 44      - name: Check spelling
 45        run: |
 46          if ! which typos > /dev/null; then
 47            cargo install typos-cli
 48          fi
 49          typos
 50
 51      - name: Run style checks
 52        uses: ./.github/actions/check_style
 53
 54      - name: Ensure fresh merge
 55        shell: bash -euxo pipefail {0}
 56        run: |
 57          if [ -z "$GITHUB_BASE_REF" ];
 58          then
 59            echo "BUF_BASE_BRANCH=$(git merge-base origin/main HEAD)" >> $GITHUB_ENV
 60          else
 61            git checkout -B temp
 62            git merge -q origin/$GITHUB_BASE_REF -m "merge main into temp"
 63            echo "BUF_BASE_BRANCH=$GITHUB_BASE_REF" >> $GITHUB_ENV
 64          fi
 65
 66      - uses: bufbuild/buf-setup-action@v1
 67      - uses: bufbuild/buf-breaking-action@v1
 68        with:
 69          input: "crates/rpc/proto/"
 70          against: "https://github.com/${GITHUB_REPOSITORY}.git#branch=${BUF_BASE_BRANCH},subdir=crates/rpc/proto/"
 71
 72  macos_tests:
 73    name: (macOS) Run Clippy and tests
 74    runs-on:
 75      - self-hosted
 76      - test
 77    steps:
 78      - name: Checkout repo
 79        uses: actions/checkout@v4
 80        with:
 81          clean: false
 82          submodules: "recursive"
 83
 84      - name: cargo clippy
 85        shell: bash -euxo pipefail {0}
 86        run: script/clippy
 87
 88      - name: Run tests
 89        uses: ./.github/actions/run_tests
 90
 91      - name: Build collab
 92        run: cargo build -p collab
 93
 94      - name: Build other binaries and features
 95        run: cargo build --workspace --bins --all-features; cargo check -p gpui --features "macos-blade"
 96
 97  # todo!(linux): Actually run the tests
 98  linux_tests:
 99    name: (Linux) Run Clippy and tests
100    runs-on: ubuntu-latest
101    steps:
102      - name: Checkout repo
103        uses: actions/checkout@v4
104        with:
105          clean: false
106          submodules: "recursive"
107
108      - name: Restore from cache
109        uses: actions/cache@v4
110        with:
111          path: |
112            ~/.cargo/bin/
113            ~/.cargo/registry/index/
114            ~/.cargo/registry/cache/
115            ~/.cargo/git/db/
116            target/
117          key: ${{ runner.os }}-cargo-${{ hashFiles('**/rust-toolchain.toml') }}-${{ hashFiles('**/Cargo.lock') }}
118
119      - name: configure linux
120        shell: bash -euxo pipefail {0}
121        run: script/linux
122
123      - name: cargo clippy
124        shell: bash -euxo pipefail {0}
125        run: script/clippy
126
127      - name: Build Zed
128        run: cargo build -p zed
129
130  # todo!(windows): Actually run the tests
131  windows_tests:
132    name: (Windows) Run Clippy and tests
133    runs-on: windows-latest
134    steps:
135      - name: Checkout repo
136        uses: actions/checkout@v4
137        with:
138          clean: false
139          submodules: "recursive"
140
141      - name: Restore from cache
142        uses: actions/cache@v4
143        with:
144          path: |
145            ~/.cargo/bin/
146            ~/.cargo/registry/index/
147            ~/.cargo/registry/cache/
148            ~/.cargo/git/db/
149            target/
150          key: ${{ runner.os }}-cargo-${{ hashFiles('**/rust-toolchain.toml') }}-${{ hashFiles('**/Cargo.lock') }}
151      # todo!(windows): Actually run clippy
152      #- name: cargo clippy
153      #  shell: bash -euxo pipefail {0}
154      #  run: script/clippy
155
156      - name: Build Zed
157        run: cargo build -p zed
158
159  bundle:
160    name: Bundle macOS app
161    runs-on:
162      - self-hosted
163      - bundle
164    if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }}
165    needs: [macos_tests]
166    env:
167      MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
168      MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
169      APPLE_NOTARIZATION_USERNAME: ${{ secrets.APPLE_NOTARIZATION_USERNAME }}
170      APPLE_NOTARIZATION_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_PASSWORD }}
171      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
172      DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
173      DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
174    steps:
175      - name: Install Node
176        uses: actions/setup-node@v4
177        with:
178          node-version: "18"
179
180      - name: Checkout repo
181        uses: actions/checkout@v4
182        with:
183          clean: false
184          submodules: "recursive"
185
186      - name: Limit target directory size
187        run: script/clear-target-dir-if-larger-than 100
188
189      - name: Determine version and release channel
190        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
191        run: |
192          set -eu
193
194          version=$(script/get-crate-version zed)
195          channel=$(cat crates/zed/RELEASE_CHANNEL)
196          echo "Publishing version: ${version} on release channel ${channel}"
197          echo "RELEASE_CHANNEL=${channel}" >> $GITHUB_ENV
198
199          expected_tag_name=""
200          case ${channel} in
201            stable)
202              expected_tag_name="v${version}";;
203            preview)
204              expected_tag_name="v${version}-pre";;
205            nightly)
206              expected_tag_name="v${version}-nightly";;
207            *)
208              echo "can't publish a release on channel ${channel}"
209              exit 1;;
210          esac
211          if [[ $GITHUB_REF_NAME != $expected_tag_name ]]; then
212            echo "invalid release tag ${GITHUB_REF_NAME}. expected ${expected_tag_name}"
213            exit 1
214          fi
215
216      - name: Generate license file
217        run: script/generate-licenses
218
219      - name: Create app bundle
220        run: script/bundle
221
222      - name: Upload app bundle to workflow run if main branch or specific label
223        uses: actions/upload-artifact@v3
224        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }}
225        with:
226          name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.dmg
227          path: target/release/Zed.dmg
228
229      - uses: softprops/action-gh-release@v1
230        name: Upload app bundle to release
231        if: ${{ env.RELEASE_CHANNEL == 'preview' || env.RELEASE_CHANNEL == 'stable' }}
232        with:
233          draft: true
234          prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
235          files: target/release/Zed.dmg
236          body: ""
237        env:
238          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}