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