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