| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 1 | # Copyright (C) 2025 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | # This workflow is triggered by analyze.yml |
| 16 | name: Perfetto CI [bazel] |
| 17 | on: |
| 18 | workflow_call: |
| 19 | env: |
| 20 | # /tmp/cache contains {ccache, bazelcache} and generally any other cache |
| 21 | # that should be persisted across jobs, but only updated from the main |
| Kirill Timofeev | 5cca791 | 2025-08-07 20:40:18 +0100 | [diff] [blame] | 22 | # branch. This is populated by the "Restore cache" step below. |
| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 23 | PERFETTO_CACHE_DIR: /tmp/cache |
| 24 | PERFETTO_ARTIFACTS_ROOT: /tmp/artifacts |
| 25 | PYTHONUNBUFFERED: 1 |
| 26 | jobs: |
| 27 | bazel: |
| 28 | runs-on: self-hosted |
| 29 | timeout-minutes: 45 |
| 30 | env: |
| Kirill Timofeev | 5cca791 | 2025-08-07 20:40:18 +0100 | [diff] [blame] | 31 | PERFETTO_CI_BUILD_CACHE_KEY: build-cache-bazel |
| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 32 | PERFETTO_CI_JOB_ID: gh-${{ github.run_id }}-bazel |
| 33 | steps: |
| 34 | - uses: actions/checkout@v4 |
| 35 | |
| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 36 | - name: Setup artifacts |
| Kirill Timofeev | 09d5f15 | 2025-08-06 15:49:16 +0100 | [diff] [blame] | 37 | shell: bash |
| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 38 | run: | |
| 39 | PERFETTO_ARTIFACTS_DIR=$PERFETTO_ARTIFACTS_ROOT/$PERFETTO_CI_JOB_ID |
| 40 | echo "PERFETTO_ARTIFACTS_DIR=$PERFETTO_ARTIFACTS_DIR" >> $GITHUB_ENV |
| 41 | mkdir -p $PERFETTO_ARTIFACTS_DIR |
| 42 | |
| 43 | - name: Restore cache |
| Kirill Timofeev | 5cca791 | 2025-08-07 20:40:18 +0100 | [diff] [blame] | 44 | uses: ./.github/actions/cache-on-google-cloud-storage/restore |
| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 45 | with: |
| Kirill Timofeev | 5cca791 | 2025-08-07 20:40:18 +0100 | [diff] [blame] | 46 | directory: ${{ env.PERFETTO_CACHE_DIR }} |
| 47 | cache_key: ${{ env.PERFETTO_CI_BUILD_CACHE_KEY }} |
| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 48 | |
| 49 | - uses: ./.github/actions/install-build-deps |
| 50 | with: |
| 51 | install-flags: --bazel |
| 52 | |
| 53 | - name: Build Bazel |
| Kirill Timofeev | 09d5f15 | 2025-08-06 15:49:16 +0100 | [diff] [blame] | 54 | shell: bash |
| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 55 | run: | |
| 56 | BAZEL_DISK_CACHE_FOLDER="$PERFETTO_CACHE_DIR/bazel-disk-cache" |
| 57 | # Cleanup the cache if any of the two conditions are true. |
| 58 | BAZEL_DISK_CACHE_GC_OPTIONS="--experimental_disk_cache_gc_max_age=7d --experimental_disk_cache_gc_max_size=10G" |
| 59 | # We don't run a bazel daemon in background, so we do a GC during the build, |
| 60 | # that's why we specify _idle_delay=0. |
| 61 | BAZEL_DISK_CACHE_GC_OPTIONS+=" --experimental_disk_cache_gc_idle_delay=0" |
| 62 | BAZEL_DISK_CACHE_FLAGS="--disk_cache=${BAZEL_DISK_CACHE_FOLDER} ${BAZEL_DISK_CACHE_GC_OPTIONS}" |
| 63 | tools/bazel build //:all ${BAZEL_DISK_CACHE_FLAGS} --verbose_failures |
| 64 | tools/bazel build //python:all ${BAZEL_DISK_CACHE_FLAGS} --verbose_failures |
| 65 | |
| 66 | - name: Smoke tests |
| Kirill Timofeev | 09d5f15 | 2025-08-06 15:49:16 +0100 | [diff] [blame] | 67 | shell: bash |
| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 68 | run: | |
| 69 | ./bazel-bin/traced & |
| 70 | ./bazel-bin/traced_probes & |
| 71 | sleep 5 |
| 72 | TRACE="$PERFETTO_ARTIFACTS_DIR/bazel.trace" |
| 73 | ./bazel-bin/perfetto -c :test -o $TRACE |
| 74 | kill $(jobs -p) |
| 75 | ./bazel-bin/trace_processor_shell -q <(echo 'select count(1) from sched') $TRACE |
| 76 | |
| 77 | - name: Update cache (if on main) |
| 78 | if: github.ref == 'refs/heads/main' |
| Kirill Timofeev | 5cca791 | 2025-08-07 20:40:18 +0100 | [diff] [blame] | 79 | uses: ./.github/actions/cache-on-google-cloud-storage/save |
| Primiano Tucci | 171b046 | 2025-03-27 15:20:24 +0000 | [diff] [blame] | 80 | with: |
| Kirill Timofeev | 5cca791 | 2025-08-07 20:40:18 +0100 | [diff] [blame] | 81 | directory: ${{ env.PERFETTO_CACHE_DIR }} |
| 82 | cache_key: ${{ env.PERFETTO_CI_BUILD_CACHE_KEY }} |