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