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