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    rustfmt:
 26        name: Check formatting
 27        runs-on:
 28            - self-hosted
 29            - test
 30        steps:
 31            - name: Checkout repo
 32              uses: actions/checkout@v3
 33              with:
 34                  clean: false
 35                  submodules: "recursive"
 36
 37            - name: Set up default .cargo/config.toml
 38              run: cp ./.cargo/ci-config.toml ~/.cargo/config.toml
 39
 40            - name: Run rustfmt
 41              uses: ./.github/actions/check_formatting
 42
 43    tests:
 44        name: Run tests
 45        runs-on:
 46            - self-hosted
 47            - test
 48        needs: rustfmt
 49        steps:
 50            - name: Checkout repo
 51              uses: actions/checkout@v3
 52              with:
 53                  clean: false
 54                  submodules: "recursive"
 55
 56            - name: Run tests
 57              uses: ./.github/actions/run_tests
 58
 59            - name: Build collab
 60              run: cargo build -p collab
 61
 62            - name: Build other binaries
 63              run: cargo build --workspace --bins --all-features
 64
 65    bundle:
 66        name: Bundle app
 67        runs-on:
 68            - self-hosted
 69            - bundle
 70        if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }}
 71        needs: tests
 72        env:
 73            MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
 74            MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
 75            APPLE_NOTARIZATION_USERNAME: ${{ secrets.APPLE_NOTARIZATION_USERNAME }}
 76            APPLE_NOTARIZATION_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_PASSWORD }}
 77        steps:
 78            - name: Install Rust
 79              run: |
 80                  rustup set profile minimal
 81                  rustup update stable
 82                  rustup target add aarch64-apple-darwin
 83                  rustup target add x86_64-apple-darwin
 84                  rustup target add wasm32-wasi
 85
 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@v3
 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 }}