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: Check unused dependencies
 55        uses: bnjbvr/cargo-machete@main
 56
 57      - name: Ensure fresh merge
 58        shell: bash -euxo pipefail {0}
 59        run: |
 60          if [ -z "$GITHUB_BASE_REF" ];
 61          then
 62            echo "BUF_BASE_BRANCH=$(git merge-base origin/main HEAD)" >> $GITHUB_ENV
 63          else
 64            git checkout -B temp
 65            git merge -q origin/$GITHUB_BASE_REF -m "merge main into temp"
 66            echo "BUF_BASE_BRANCH=$GITHUB_BASE_REF" >> $GITHUB_ENV
 67          fi
 68
 69      - uses: bufbuild/buf-setup-action@v1
 70        with:
 71          version: v1.29.0
 72      - uses: bufbuild/buf-breaking-action@v1
 73        with:
 74          input: "crates/rpc/proto/"
 75          against: "https://github.com/${GITHUB_REPOSITORY}.git#branch=${BUF_BASE_BRANCH},subdir=crates/rpc/proto/"
 76
 77  macos_tests:
 78    name: (macOS) Run Clippy and tests
 79    runs-on:
 80      - self-hosted
 81      - test
 82    steps:
 83      - name: Checkout repo
 84        uses: actions/checkout@v4
 85        with:
 86          clean: false
 87          submodules: "recursive"
 88
 89      - name: cargo clippy
 90        run: cargo xtask clippy
 91
 92      - name: Install WASI dependencies
 93        run: script/setup-wasm
 94
 95      - name: Run tests
 96        uses: ./.github/actions/run_tests
 97
 98      - name: Build collab
 99        run: cargo build -p collab
100
101      - name: Build other binaries and features
102        run: cargo build --workspace --bins --all-features; cargo check -p gpui --features "macos-blade"
103
104  # todo(linux): Actually run the tests
105  linux_tests:
106    name: (Linux) Run Clippy and tests
107    runs-on: ubuntu-latest
108    steps:
109      - name: Checkout repo
110        uses: actions/checkout@v4
111        with:
112          clean: false
113          submodules: "recursive"
114
115      - name: Cache dependencies
116        uses: swatinem/rust-cache@v2
117        with:
118          save-if: ${{ github.ref == 'refs/heads/main' }}
119
120      - name: configure linux
121        shell: bash -euxo pipefail {0}
122        run: script/linux
123
124      - name: cargo clippy
125        run: cargo xtask 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: Cache dependencies
142        uses: swatinem/rust-cache@v2
143        with:
144          save-if: ${{ github.ref == 'refs/heads/main' }}
145
146      - name: cargo clippy
147        run: cargo xtask clippy
148
149      - name: Build Zed
150        run: cargo build -p zed
151
152  bundle-mac:
153    name: Create a macOS bundle
154    runs-on:
155      - self-hosted
156      - bundle
157    if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
158    needs: [macos_tests]
159    env:
160      MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
161      MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
162      APPLE_NOTARIZATION_USERNAME: ${{ secrets.APPLE_NOTARIZATION_USERNAME }}
163      APPLE_NOTARIZATION_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_PASSWORD }}
164      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
165      DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
166      DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
167    steps:
168      - name: Install Node
169        uses: actions/setup-node@v4
170        with:
171          node-version: "18"
172
173      - name: Checkout repo
174        uses: actions/checkout@v4
175        with:
176          clean: false
177          submodules: "recursive"
178
179      - name: Limit target directory size
180        run: script/clear-target-dir-if-larger-than 100
181
182      - name: Determine version and release channel
183        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
184        run: |
185          set -eu
186
187          version=$(script/get-crate-version zed)
188          channel=$(cat crates/zed/RELEASE_CHANNEL)
189          echo "Publishing version: ${version} on release channel ${channel}"
190          echo "RELEASE_CHANNEL=${channel}" >> $GITHUB_ENV
191
192          expected_tag_name=""
193          case ${channel} in
194            stable)
195              expected_tag_name="v${version}";;
196            preview)
197              expected_tag_name="v${version}-pre";;
198            nightly)
199              expected_tag_name="v${version}-nightly";;
200            *)
201              echo "can't publish a release on channel ${channel}"
202              exit 1;;
203          esac
204          if [[ $GITHUB_REF_NAME != $expected_tag_name ]]; then
205            echo "invalid release tag ${GITHUB_REF_NAME}. expected ${expected_tag_name}"
206            exit 1
207          fi
208
209      - name: Generate license file
210        run: script/generate-licenses
211
212      - name: Create macOS app bundle
213        run: script/bundle-mac
214
215      - name: Upload app bundle to workflow run if main branch or specific label
216        uses: actions/upload-artifact@v4
217        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
218        with:
219          name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.dmg
220          path: target/release/Zed.dmg
221
222      - uses: softprops/action-gh-release@v1
223        name: Upload app bundle to release
224        if: ${{ env.RELEASE_CHANNEL == 'preview' || env.RELEASE_CHANNEL == 'stable' }}
225        with:
226          draft: true
227          prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
228          files: target/release/Zed.dmg
229          body: ""
230        env:
231          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
232
233  bundle-deb:
234    name: Create a *.deb Linux bundle
235    runs-on: ubuntu-22.04 # keep the version fixed to avoid libc and dynamic linked library issues
236    if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
237    needs: [linux_tests]
238    env:
239      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
240      DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
241      DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
242    steps:
243      - name: Checkout repo
244        uses: actions/checkout@v4
245        with:
246          clean: false
247          submodules: "recursive"
248
249      - name: Cache dependencies
250        uses: swatinem/rust-cache@v2
251        with:
252          save-if: ${{ github.ref == 'refs/heads/main' }}
253
254      - name: Configure linux
255        shell: bash -euxo pipefail {0}
256        run: script/linux
257
258      - name: Determine version and release channel
259        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
260        run: |
261          set -eu
262
263          version=$(script/get-crate-version zed)
264          channel=$(cat crates/zed/RELEASE_CHANNEL)
265          echo "Publishing version: ${version} on release channel ${channel}"
266          echo "RELEASE_CHANNEL=${channel}" >> $GITHUB_ENV
267
268          expected_tag_name=""
269          case ${channel} in
270            stable)
271              expected_tag_name="v${version}";;
272            preview)
273              expected_tag_name="v${version}-pre";;
274            nightly)
275              expected_tag_name="v${version}-nightly";;
276            *)
277              echo "can't publish a release on channel ${channel}"
278              exit 1;;
279          esac
280          if [[ $GITHUB_REF_NAME != $expected_tag_name ]]; then
281            echo "invalid release tag ${GITHUB_REF_NAME}. expected ${expected_tag_name}"
282            exit 1
283          fi
284
285      # TODO linux : Find a way to add licenses to the final bundle
286      # - name: Generate license file
287      #   run: script/generate-licenses
288
289      - name: Create Linux *.deb bundle
290        run: script/bundle-linux
291
292      - name: Upload app bundle to workflow run if main branch or specific label
293        uses: actions/upload-artifact@v4
294        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
295        with:
296          name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.deb
297          path: target/release/*.deb
298
299      # TODO linux : make it stable enough to be uploaded as a release
300      # - uses: softprops/action-gh-release@v1
301      #   name: Upload app bundle to release
302      #   if: ${{ env.RELEASE_CHANNEL == 'preview' || env.RELEASE_CHANNEL == 'stable' }}
303      #   with:
304      #     draft: true
305      #     prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
306      #     files: target/release/Zed.dmg
307      #     body: ""
308      #   env:
309      #     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}