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
 14env:
 15  CARGO_TERM_COLOR: always
 16  CARGO_INCREMENTAL: 0
 17  RUST_BACKTRACE: 1
 18
 19jobs:
 20  rustfmt:
 21    name: Check formatting
 22    runs-on:
 23      - self-hosted
 24      - test
 25    steps:
 26      - name: Checkout repo
 27        uses: actions/checkout@v3
 28        with:
 29          clean: false
 30          submodules: "recursive"
 31
 32      - name: Run rustfmt
 33        uses: ./.github/actions/check_formatting
 34
 35  tests:
 36    name: Run tests
 37    runs-on:
 38      - self-hosted
 39      - test
 40    needs: rustfmt
 41    steps:
 42      - name: Checkout repo
 43        uses: actions/checkout@v3
 44        with:
 45          clean: false
 46          submodules: "recursive"
 47
 48      - name: Run tests
 49        uses: ./.github/actions/run_tests
 50
 51      - name: Build collab
 52        run: cargo build -p collab
 53
 54      - name: Build other binaries
 55        run: cargo build --workspace --bins --all-features
 56
 57  bundle:
 58    name: Bundle app
 59    runs-on:
 60      - self-hosted
 61      - bundle
 62    if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }}
 63    needs: tests
 64    env:
 65      MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
 66      MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
 67      APPLE_NOTARIZATION_USERNAME: ${{ secrets.APPLE_NOTARIZATION_USERNAME }}
 68      APPLE_NOTARIZATION_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_PASSWORD }}
 69    steps:
 70      - name: Install Rust
 71        run: |
 72          rustup set profile minimal
 73          rustup update stable
 74          rustup target add aarch64-apple-darwin
 75          rustup target add x86_64-apple-darwin
 76          rustup target add wasm32-wasi
 77
 78      - name: Install Node
 79        uses: actions/setup-node@v3
 80        with:
 81          node-version: "18"
 82
 83      - name: Checkout repo
 84        uses: actions/checkout@v3
 85        with:
 86          clean: false
 87          submodules: "recursive"
 88
 89      - name: Limit target directory size
 90        run: script/clear-target-dir-if-larger-than 70
 91
 92      - name: Determine version and release channel
 93        if: ${{ startsWith(github.ref, 'refs/tags/v') }}
 94        run: |
 95          set -eu
 96
 97          version=$(script/get-crate-version zed)
 98          channel=$(cat crates/zed/RELEASE_CHANNEL)
 99          echo "Publishing version: ${version} on release channel ${channel}"
100          echo "RELEASE_CHANNEL=${channel}" >> $GITHUB_ENV
101
102          expected_tag_name=""
103          case ${channel} in
104            stable)
105              expected_tag_name="v${version}";;
106            preview)
107              expected_tag_name="v${version}-pre";;
108            nightly)
109              expected_tag_name="v${version}-nightly";;
110            *)
111              echo "can't publish a release on channel ${channel}"
112              exit 1;;
113          esac
114          if [[ $GITHUB_REF_NAME != $expected_tag_name ]]; then
115            echo "invalid release tag ${GITHUB_REF_NAME}. expected ${expected_tag_name}"
116            exit 1
117          fi
118
119      - name: Generate license file
120        run: script/generate-licenses
121
122      - name: Create app bundle
123        run: script/bundle
124
125      - name: Upload app bundle to workflow run if main branch or specific label
126        uses: actions/upload-artifact@v3
127        if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }}
128        with:
129          name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.dmg
130          path: target/release/Zed.dmg
131
132      - uses: softprops/action-gh-release@v1
133        name: Upload app bundle to release
134        # TODO kb seems that zed.dev relies on GitHub releases for release version tracking.
135        # Find alternatives for `nightly` or just go on with more releases?
136        if: ${{ env.RELEASE_CHANNEL == 'preview' || env.RELEASE_CHANNEL == 'stable' }}
137        with:
138          draft: true
139          prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
140          files: target/release/Zed.dmg
141          body: ""
142        env:
143          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}