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: Install cargo-component
 90        run: |
 91          if ! which cargo-component > /dev/null; then
 92            cargo install cargo-component
 93          fi
 94
 95      - name: cargo clippy
 96        shell: bash -euxo pipefail {0}
 97        run: script/clippy
 98
 99      - name: Run tests
100        uses: ./.github/actions/run_tests
101
102      - name: Build collab
103        run: cargo build -p collab
104
105      - name: Build other binaries and features
106        run: cargo build --workspace --bins --all-features; cargo check -p gpui --features "macos-blade"
107
108  # todo(linux): Actually run the tests
109  linux_tests:
110    name: (Linux) Run Clippy and tests
111    runs-on: ubuntu-latest
112    steps:
113      - name: Checkout repo
114        uses: actions/checkout@v4
115        with:
116          clean: false
117          submodules: "recursive"
118
119      - name: Cache dependencies
120        uses: swatinem/rust-cache@v2
121        with:
122          save-if: ${{ github.ref == 'refs/heads/main' }}
123
124      - name: configure linux
125        shell: bash -euxo pipefail {0}
126        run: script/linux
127
128      - name: cargo clippy
129        shell: bash -euxo pipefail {0}
130        run: script/clippy
131
132      - name: Build Zed
133        run: cargo build -p zed
134
135  # todo(windows): Actually run the tests
136  windows_tests:
137    name: (Windows) Run Clippy and tests
138    runs-on: windows-latest
139    steps:
140      - name: Checkout repo
141        uses: actions/checkout@v4
142        with:
143          clean: false
144          submodules: "recursive"
145
146      - name: Cache dependencies
147        uses: swatinem/rust-cache@v2
148        with:
149          save-if: ${{ github.ref == 'refs/heads/main' }}
150
151      - name: cargo clippy
152        shell: bash -euxo pipefail {0}
153        run: script/clippy
154
155      - name: Build Zed
156        run: cargo build -p zed
157
158  bundle:
159    name: Bundle macOS app
160    runs-on:
161      - self-hosted
162      - bundle
163    if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }}
164    needs: [macos_tests]
165    env:
166      MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
167      MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
168      APPLE_NOTARIZATION_USERNAME: ${{ secrets.APPLE_NOTARIZATION_USERNAME }}
169      APPLE_NOTARIZATION_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_PASSWORD }}
170      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
171      DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
172      DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
173    steps:
174      - name: Install Node
175        uses: actions/setup-node@v4
176        with:
177          node-version: "18"
178
179      - name: Checkout repo
180        uses: actions/checkout@v4
181        with:
182          clean: false
183          submodules: "recursive"
184
185      - name: Limit target directory size
186        run: script/clear-target-dir-if-larger-than 100
187
188      - name: Determine version and release channel
189        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
190        run: |
191          set -eu
192
193          version=$(script/get-crate-version zed)
194          channel=$(cat crates/zed/RELEASE_CHANNEL)
195          echo "Publishing version: ${version} on release channel ${channel}"
196          echo "RELEASE_CHANNEL=${channel}" >> $GITHUB_ENV
197
198          expected_tag_name=""
199          case ${channel} in
200            stable)
201              expected_tag_name="v${version}";;
202            preview)
203              expected_tag_name="v${version}-pre";;
204            nightly)
205              expected_tag_name="v${version}-nightly";;
206            *)
207              echo "can't publish a release on channel ${channel}"
208              exit 1;;
209          esac
210          if [[ $GITHUB_REF_NAME != $expected_tag_name ]]; then
211            echo "invalid release tag ${GITHUB_REF_NAME}. expected ${expected_tag_name}"
212            exit 1
213          fi
214
215      - name: Generate license file
216        run: script/generate-licenses
217
218      - name: Create app bundle
219        run: script/bundle
220
221      - name: Upload app bundle to workflow run if main branch or specific label
222        uses: actions/upload-artifact@v3
223        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }}
224        with:
225          name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.dmg
226          path: target/release/Zed.dmg
227
228      - uses: softprops/action-gh-release@v1
229        name: Upload app bundle to release
230        if: ${{ env.RELEASE_CHANNEL == 'preview' || env.RELEASE_CHANNEL == 'stable' }}
231        with:
232          draft: true
233          prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
234          files: target/release/Zed.dmg
235          body: ""
236        env:
237          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}