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, Clippy lints, 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: Set up default .cargo/config.toml
 39        run: cp ./.cargo/ci-config.toml ~/.cargo/config.toml
 40
 41      - name: Check spelling
 42        run: |
 43          if ! which typos > /dev/null; then
 44            cargo install typos-cli
 45          fi
 46          typos
 47
 48      - name: Run style checks
 49        uses: ./.github/actions/check_style
 50
 51  tests:
 52    name: Run tests
 53    runs-on:
 54      - self-hosted
 55      - test
 56    steps:
 57      - name: Checkout repo
 58        uses: actions/checkout@v4
 59        with:
 60          clean: false
 61          submodules: "recursive"
 62
 63      - name: Run tests
 64        uses: ./.github/actions/run_tests
 65
 66      - name: Build collab
 67        run: cargo build -p collab
 68
 69      - name: Build other binaries
 70        run: cargo build --workspace --bins --all-features
 71
 72  bundle:
 73    name: Bundle app
 74    runs-on:
 75      - self-hosted
 76      - bundle
 77    if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }}
 78    needs: tests
 79    env:
 80      MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
 81      MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
 82      APPLE_NOTARIZATION_USERNAME: ${{ secrets.APPLE_NOTARIZATION_USERNAME }}
 83      APPLE_NOTARIZATION_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_PASSWORD }}
 84      ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
 85    steps:
 86      - name: Install Node
 87        uses: actions/setup-node@v3
 88        with:
 89          node-version: "18"
 90
 91      - name: Checkout repo
 92        uses: actions/checkout@v4
 93        with:
 94          clean: false
 95          submodules: "recursive"
 96
 97      - name: Limit target directory size
 98        run: script/clear-target-dir-if-larger-than 100
 99
100      - name: Determine version and release channel
101        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
102        run: |
103          set -eu
104
105          version=$(script/get-crate-version zed)
106          channel=$(cat crates/zed/RELEASE_CHANNEL)
107          echo "Publishing version: ${version} on release channel ${channel}"
108          echo "RELEASE_CHANNEL=${channel}" >> $GITHUB_ENV
109
110          expected_tag_name=""
111          case ${channel} in
112            stable)
113              expected_tag_name="v${version}";;
114            preview)
115              expected_tag_name="v${version}-pre";;
116            nightly)
117              expected_tag_name="v${version}-nightly";;
118            *)
119              echo "can't publish a release on channel ${channel}"
120              exit 1;;
121          esac
122          if [[ $GITHUB_REF_NAME != $expected_tag_name ]]; then
123            echo "invalid release tag ${GITHUB_REF_NAME}. expected ${expected_tag_name}"
124            exit 1
125          fi
126
127      - name: Generate license file
128        run: script/generate-licenses
129
130      - name: Create app bundle
131        run: script/bundle
132
133      - name: Upload app bundle to workflow run if main branch or specific label
134        uses: actions/upload-artifact@v3
135        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }}
136        with:
137          name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.dmg
138          path: target/release/Zed.dmg
139
140      - uses: softprops/action-gh-release@v1
141        name: Upload app bundle to release
142        if: ${{ env.RELEASE_CHANNEL == 'preview' || env.RELEASE_CHANNEL == 'stable' }}
143        with:
144          draft: true
145          prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
146          files: target/release/Zed.dmg
147          body: ""
148        env:
149          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}