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