Skip to content

Commit 7a17178

Browse files
committed
ci: move to GitHub Actions
WORK IN PROGRESS Change-Id: I671dbbcbbe9d00a3ebf6f74edb01143fb2b05855
1 parent 5af8621 commit 7a17178

22 files changed

+578
-1059
lines changed

.github/workflows/test_runner.yml

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Perfetto CI
2+
on:
3+
# 1. continuous
4+
schedule:
5+
# Run every 6 hours
6+
- cron: "0 */6 * * *"
7+
8+
# 2. postsubmit
9+
push:
10+
branches:
11+
- main
12+
- test
13+
14+
# 3. presubmits
15+
pull_request:
16+
types: [opened, synchronize]
17+
branches:
18+
- main
19+
- test
20+
21+
22+
jobs:
23+
test:
24+
runs-on: self-hosted
25+
timeout-minutes: 45
26+
strategy:
27+
matrix:
28+
config:
29+
# - name: linux-clang-x86_64-debug
30+
# PERFETTO_TEST_GN_ARGS: 'is_debug=true is_hermetic_clang=false non_hermetic_clang_stdlib="libc++" enable_perfetto_merged_protos_check=true'
31+
# PERFETTO_TEST_SCRIPT: 'test/ci/linux_tests.sh'
32+
# PERFETTO_INSTALL_BUILD_DEPS_ARGS: ''
33+
# - name: linux-clang-x86_64-tsan
34+
# PERFETTO_TEST_GN_ARGS: 'is_debug=false is_tsan=true'
35+
# PERFETTO_TEST_SCRIPT: 'test/ci/linux_tests.sh'
36+
# PERFETTO_INSTALL_BUILD_DEPS_ARGS: ''
37+
# - name: linux-clang-x86_64-msan
38+
# PERFETTO_TEST_GN_ARGS: 'is_debug=false is_msan=true'
39+
# PERFETTO_TEST_SCRIPT: 'test/ci/linux_tests.sh'
40+
# PERFETTO_INSTALL_BUILD_DEPS_ARGS: ''
41+
# - name: linux-clang-x86_64-asan_lsan
42+
# PERFETTO_TEST_GN_ARGS: 'is_debug=false is_asan=true is_lsan=true'
43+
# PERFETTO_TEST_SCRIPT: 'test/ci/linux_tests.sh'
44+
# PERFETTO_INSTALL_BUILD_DEPS_ARGS: ''
45+
# - name: linux-clang-x86-release
46+
# PERFETTO_TEST_GN_ARGS: 'is_debug=false target_cpu="x86"'
47+
# PERFETTO_TEST_SCRIPT: 'test/ci/linux_tests.sh'
48+
# PERFETTO_INSTALL_BUILD_DEPS_ARGS: ''
49+
# - name: linux-gcc8-x86_64-release
50+
# PERFETTO_TEST_GN_ARGS: 'is_debug=false is_clang=false enable_perfetto_grpc=true cc="gcc-8" cxx="g++-8"'
51+
# PERFETTO_TEST_SCRIPT: 'test/ci/linux_tests.sh'
52+
# PERFETTO_INSTALL_BUILD_DEPS_ARGS: '--grpc'
53+
# - name: android-clang-arm-release
54+
# PERFETTO_TEST_GN_ARGS: 'is_debug=false target_os="android" target_cpu="arm"'
55+
# PERFETTO_TEST_SCRIPT: 'test/ci/android_tests.sh'
56+
# PERFETTO_INSTALL_BUILD_DEPS_ARGS: '--android'
57+
# - name: linux-clang-x86_64-libfuzzer
58+
# PERFETTO_TEST_GN_ARGS: 'is_debug=false is_fuzzer=true is_asan=true'
59+
# PERFETTO_TEST_SCRIPT: 'test/ci/fuzzer_tests.sh'
60+
# PERFETTO_INSTALL_BUILD_DEPS_ARGS: ''
61+
- name: linux-clang-x86_64-bazel
62+
PERFETTO_TEST_GN_ARGS: ''
63+
PERFETTO_TEST_SCRIPT: 'test/ci/bazel_tests.sh'
64+
PERFETTO_INSTALL_BUILD_DEPS_ARGS: '--bazel'
65+
- name: ui-clang-x86_64-release
66+
PERFETTO_TEST_GN_ARGS: 'is_debug=false'
67+
PERFETTO_TEST_SCRIPT: 'test/ci/ui_tests.sh'
68+
PERFETTO_INSTALL_BUILD_DEPS_ARGS: '--ui'
69+
70+
env:
71+
# /tmp/cache contains {ccache, bazelcache} and generally any other cache
72+
# that should be persisted across jobs, but only updated from the main
73+
# branch. This is populated by the "actions/cache/restore" step below.
74+
# TODO here check this between docker and this. DNS
75+
PERFETTO_CACHE_DIR: /tmp/cache
76+
PERFETTO_TEST_GN_ARGS: ${{ matrix.config.PERFETTO_TEST_GN_ARGS }}
77+
PERFETTO_TEST_SCRIPT: ${{ matrix.config.PERFETTO_TEST_SCRIPT }}
78+
PERFETTO_INSTALL_BUILD_DEPS_ARGS: ${{ matrix.config.PERFETTO_INSTALL_BUILD_DEPS_ARGS }}
79+
PERFETTO_TEST_JOB: gh-${{ github.run_id }}-${{ matrix.config.name }}
80+
PERFETTO_TEST_NINJA_ARGS: # Deliberately empty, set in some other env
81+
steps:
82+
- name: Set up artifacts
83+
run: |
84+
mkdir -p ${{ env.PERFETTO_CACHE_DIR }}
85+
PERFETTO_ARTIFACTS_DIR=/tmp/artifacts/$PERFETTO_TEST_JOB
86+
echo "PERFETTO_ARTIFACTS_DIR=$PERFETTO_ARTIFACTS_DIR" >> $GITHUB_ENV
87+
mkdir -p $PERFETTO_ARTIFACTS_DIR
88+
89+
# Check out code.
90+
- uses: actions/checkout@v4
91+
with:
92+
fetch-depth: 2
93+
94+
- name: Set up cache
95+
# By default ccache uses the mtime of the compiler. This doesn't work
96+
# because our compilers are hermetic and their mtime is the time when we
97+
# run install-build-deps. Given that the toolchain is rolled via
98+
# install-build-deps we use that file as an identity function for the
99+
# compiler check.
100+
run: |
101+
CCACHE_DIR=${{ env.PERFETTO_CACHE_DIR }}/ccache
102+
mkdir -p $CCACHE_DIR
103+
DEPS_SHA=$(shasum "tools/install-build-deps" | awk '{print $1}')
104+
echo "DEPS_SHA=$DEPS_SHA" >> $GITHUB_ENV
105+
echo "CCACHE_COMPILERCHECK=string:$DEPS_SHA" >> $GITHUB_ENV
106+
echo "CCACHE_BASEDIR=${{ github.workspace }}" >> $GITHUB_ENV
107+
echo "CCACHE_DIR=$CCACHE_DIR" >> $GITHUB_ENV
108+
echo "CCACHE_MAXSIZE=8G" >> $GITHUB_ENV
109+
echo "CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime" >> $GITHUB_ENV
110+
echo "CCACHE_NOCOMPRESS=1" >> $GITHUB_ENV
111+
echo "CCACHE_COMPILERCHECK=string:$(shasum tools/install-build-deps)" >> $GITHUB_ENV
112+
echo "CCACHE_UMASK=000" >> $GITHUB_ENV
113+
echo "CCACHE_DEPEND=1" >> $GITHUB_ENV
114+
115+
# TODO remove this
116+
- name: Print env vars
117+
run: env;
118+
119+
- name: Restore cache and buildtools from GitHub cache
120+
uses: actions/cache/restore@v4
121+
with:
122+
path: |
123+
${{ env.PERFETTO_CACHE_DIR }}
124+
buildtools
125+
key: cache-${{ matrix.config.name }}-${{ env.DEPS_SHA }}
126+
127+
- name: ls cache
128+
run: ls -laR ${{ env.PERFETTO_CACHE_DIR }}
129+
130+
- name: Build and test
131+
run: ${{ env.PERFETTO_TEST_SCRIPT }}
132+
shell: bash
133+
134+
- name: ccache stats
135+
run: ccache --show-stats
136+
137+
- name: Upload artifacts to GCS
138+
if: ${{ always() }}
139+
run: /opt/ci/artifacts_uploader --rm ${{ env.PERFETTO_ARTIFACTS_DIR }}
140+
141+
- name: Update cache (if on main)
142+
if: github.ref == 'refs/heads/main'
143+
uses: actions/cache/save@v4
144+
with:
145+
path: |
146+
${{ env.PERFETTO_CACHE_DIR }}
147+
buildtools
148+
key: cache-${{ matrix.config.name }}-${{ env.DEPS_SHA }}

docs/design-docs/continuous-integration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ docker run worker-N ...
265265
- Sets up Docker and `iptables` (for the sandboxed network).
266266
- Starts `N` worker containers in Docker.
267267

268-
### [worker.py](/infra/ci/worker/worker.py)
268+
### worker.py
269269

270270
- It polls the DB to retrieve a job.
271271
- When a job is retrieved starts a sandbox container.
272272
- It streams the container stdout/stderr to the DB.
273273
- It upload the build artifacts to GCS.
274274

275-
### [testrunner.sh](/infra/ci/sandbox/testrunner.sh)
275+
### testrunner.sh
276276

277277
- It is pinned in the container image. Does NOT depend on the particular
278278
revision being tested.

infra/ci/Makefile

+8-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ clean:
5858
touch $@
5959

6060
.deps/${BUILDER}-sandbox: sandbox/* ${COMMON_DEPS}
61+
mkdir -p sandbox/tmp
62+
cp -a config.py common_utils.py sandbox/tmp/
6163
${BUILDER} build --rm --force-rm -t ${SANDBOX_IMG} sandbox
64+
rm -rf sandbox/tmp/
6265
touch $@
6366

6467
.deps/upload-startup-script: ${GCE_LOCAL_STARTUP_SCRIPT} ${COMMON_DEPS}
@@ -77,11 +80,10 @@ clean:
7780
--maintenance-policy=MIGRATE \
7881
--service-account=gce-ci-worker@${PROJECT}.iam.gserviceaccount.com \
7982
--scopes=${GCE_SCOPES} \
80-
--image=cos-85-13310-1209-10 \
81-
--image-project=cos-cloud \
83+
--image=projects/cos-cloud/global/images/cos-117-18613-164-81 \
8284
--boot-disk-size=100GB \
8385
--boot-disk-type=pd-ssd \
84-
--boot-disk-device-name=ci-worker-template \
86+
--boot-disk-device-name=${GCE_TEMPLATE} \
8587
--local-ssd=interface=NVME \
8688
--local-ssd=interface=NVME
8789
touch $@
@@ -102,7 +104,7 @@ gcloud compute --project=${PROJECT} \
102104
instance-groups managed create ${GCE_GROUP_NAME}-$1 \
103105
--region=$1 \
104106
--base-instance-name=ci-$1 \
105-
--template=ci-worker-template \
107+
--template=${GCE_TEMPLATE} \
106108
--size=1
107109
gcloud compute --quiet --project=$(PROJECT) \
108110
instance-groups managed set-autoscaling ${GCE_GROUP_NAME}-$1 \
@@ -137,14 +139,14 @@ stop-worker-for-testing:
137139
gcloud compute --quiet \
138140
--project ${PROJECT} \
139141
instances delete ${GCE_VM_NAME} \
140-
--zone us-central1-f
142+
--zone us-west1-c
141143

142144
.PHONY: start-worker-for-testing
143145
start-worker-for-testing: .deps/gce-template
144146
gcloud compute --quiet \
145147
--project ${PROJECT} \
146148
instances create ${GCE_VM_NAME} \
147-
--zone us-central1-f \
149+
--zone us-west1-c \
148150
--source-instance-template=${GCE_TEMPLATE}
149151

150152
# Debugging client to make OAuth2 authenticated requests manually.

infra/ci/config.py

+16-65
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@
3030
GERRIT_VOTING_ENABLED = True
3131
LOGLEVEL = 'info'
3232

33+
34+
# IDs for the Perfetto CI GitHub app.
35+
GITHUB_REPO = 'google/perfetto'
36+
GITHUB_APP_ID = 1184402
37+
GITHUB_APP_INSTALLATION_ID = 62928975
38+
3339
# Cloud config (GCE = Google Compute Engine, GAE = Google App Engine)
3440
PROJECT = 'perfetto-ci'
3541

3642
GAE_VERSION = 'prod'
3743
DB_ROOT = 'https://%s.firebaseio.com' % PROJECT
3844
DB = DB_ROOT + '/ci'
39-
SANDBOX_IMG = 'us-docker.pkg.dev/%s/containers/sandbox' % PROJECT
40-
WORKER_IMG = 'us-docker.pkg.dev/%s/containers/worker' % PROJECT
45+
SANDBOX_IMG = 'us-docker.pkg.dev/%s/containers/gh-sandbox' % PROJECT
46+
WORKER_IMG = 'us-docker.pkg.dev/%s/containers/gh-worker' % PROJECT
4147
CI_SITE = 'https://ci.perfetto.dev'
4248
GCS_ARTIFACTS = 'perfetto-ci-artifacts'
4349

@@ -47,11 +53,12 @@
4753
TRUSTED_EMAILS = '^.*@google.com$'
4854

4955
GCE_REGIONS = 'us-west1'
50-
GCE_VM_NAME = 'ci-worker'
56+
GCE_VM_NAME = 'gh-worker'
5157
GCE_VM_TYPE = 'c2d-standard-32'
52-
GCE_TEMPLATE = 'ci-worker-template'
58+
GCE_TEMPLATE = 'gh-worker-template'
5359
GCE_GROUP_NAME = 'ci'
54-
MAX_VMS_PER_REGION = 8
60+
# MAX_VMS_PER_REGION = 8 TODO restore to 8 after killing old CI
61+
MAX_VMS_PER_REGION = 1
5562
NUM_WORKERS_PER_VM = 4
5663

5764
GCE_SCOPES = [
@@ -64,66 +71,10 @@
6471
'https://www.googleapis.com/auth/userinfo.email',
6572
]
6673

67-
# Only variables starting with PERFETTO_ are propagated into the sandbox.
68-
JOB_CONFIGS = {
69-
'linux-clang-x86_64-debug': {
70-
'PERFETTO_TEST_GN_ARGS': 'is_debug=true is_hermetic_clang=false '
71-
'non_hermetic_clang_stdlib="libc++" '
72-
'enable_perfetto_merged_protos_check=true',
73-
'PERFETTO_TEST_SCRIPT': 'test/ci/linux_tests.sh',
74-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS': '',
75-
},
76-
'linux-clang-x86_64-tsan': {
77-
'PERFETTO_TEST_GN_ARGS': 'is_debug=false is_tsan=true',
78-
'PERFETTO_TEST_SCRIPT': 'test/ci/linux_tests.sh',
79-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS': '',
80-
},
81-
'linux-clang-x86_64-msan': {
82-
'PERFETTO_TEST_GN_ARGS': 'is_debug=false is_msan=true',
83-
'PERFETTO_TEST_SCRIPT': 'test/ci/linux_tests.sh',
84-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS': '',
85-
},
86-
'linux-clang-x86_64-asan_lsan': {
87-
'PERFETTO_TEST_GN_ARGS': 'is_debug=false is_asan=true is_lsan=true',
88-
'PERFETTO_TEST_SCRIPT': 'test/ci/linux_tests.sh',
89-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS': '',
90-
},
91-
'linux-clang-x86-release': {
92-
'PERFETTO_TEST_GN_ARGS': 'is_debug=false target_cpu="x86"',
93-
'PERFETTO_TEST_SCRIPT': 'test/ci/linux_tests.sh',
94-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS': '',
95-
},
96-
'linux-gcc8-x86_64-release': {
97-
'PERFETTO_TEST_GN_ARGS':
98-
'is_debug=false is_clang=false enable_perfetto_grpc=true '
99-
'cc="gcc-8" cxx="g++-8"',
100-
'PERFETTO_TEST_SCRIPT': 'test/ci/linux_tests.sh',
101-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS': '--grpc',
102-
},
103-
'android-clang-arm-release': {
104-
'PERFETTO_TEST_GN_ARGS':
105-
'is_debug=false target_os="android" target_cpu="arm"',
106-
'PERFETTO_TEST_SCRIPT':
107-
'test/ci/android_tests.sh',
108-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS':
109-
'--android',
110-
},
111-
'linux-clang-x86_64-libfuzzer': {
112-
'PERFETTO_TEST_GN_ARGS': 'is_debug=false is_fuzzer=true is_asan=true',
113-
'PERFETTO_TEST_SCRIPT': 'test/ci/fuzzer_tests.sh',
114-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS': '',
115-
},
116-
'linux-clang-x86_64-bazel': {
117-
'PERFETTO_TEST_GN_ARGS': '',
118-
'PERFETTO_TEST_SCRIPT': 'test/ci/bazel_tests.sh',
119-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS': '--bazel',
120-
},
121-
'ui-clang-x86_64-release': {
122-
'PERFETTO_TEST_GN_ARGS': 'is_debug=false',
123-
'PERFETTO_TEST_SCRIPT': 'test/ci/ui_tests.sh',
124-
'PERFETTO_INSTALL_BUILD_DEPS_ARGS': '--ui',
125-
},
126-
}
74+
SANDBOX_SVC_ACCOUNT = 'gce-ci-sandbox@perfetto-ci.iam.gserviceaccount.com'
75+
76+
# TODO remove this
77+
JOB_CONFIGS = {}
12778

12879
if __name__ == '__main__':
12980
import os

infra/ci/sandbox/Dockerfile

+37-16
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,12 @@ RUN set -ex; \
3030
openjdk-11-jdk; \
3131
apt-get -y install libc++-8-dev libc++abi-8-dev clang-8; \
3232
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1; \
33+
pip3 install protobuf pandas grpcio; \
3334
gcc-8 --version; \
3435
g++-8 --version; \
3536
clang-8 --version; \
3637
clang++-8 --version; \
37-
java --version; \
38-
pip3 install protobuf pandas grpcio; \
39-
groupadd -g 1337 perfetto; \
40-
useradd -d /ci/ramdisk -u 1337 -g perfetto perfetto; \
41-
apt-get -y autoremove; \
42-
rm -rf /var/lib/apt/lists/* /usr/share/man/* /usr/share/doc/*;
38+
java --version;
4339

4440
# Chrome/puppeteer deps.
4541
RUN set -ex; \
@@ -55,16 +51,41 @@ RUN set -ex; \
5551
xdg-utils fonts-liberation fonts-ipafont-gothic fonts-wqy-zenhei \
5652
fonts-thai-tlwg fonts-kacst fonts-freefont-ttf
5753

58-
# Cleanup to reduce image size
59-
RUN apt-get -y autoremove; \
60-
rm -rf /var/lib/apt/lists/* /usr/share/man/* /usr/share/doc/*; \
61-
rm -rf /root/.cache/;
54+
RUN set -ex; \
55+
export DEBIAN_FRONTEND=noninteractive; \
56+
apt-get -y install \
57+
procps jq python3-jwt python3-requests python3 python3-oauth2client \
58+
python3-httplib2 python3-google-auth \
59+
python3-googleapi
6260

63-
COPY testrunner.sh /ci/testrunner.sh
64-
COPY init.sh /ci/init.sh
65-
RUN chmod -R a+rx /ci/
6661

67-
VOLUME [ "/ci/cache", "/ci/ramdisk", "/ci/artifacts" ]
68-
ENTRYPOINT [ "tini", "-g", "--" ]
69-
CMD [ "bash", "/ci/init.sh" ]
62+
RUN set -ex; \
63+
groupadd -g 1986 perfetto; \
64+
useradd -m -d /opt/ci -u 1986 -g perfetto perfetto; \
65+
apt-get -y autoremove; \
66+
rm -rf /root/.cache/ /usr/share/man/* /usr/share/doc/*;
67+
68+
WORKDIR /opt/ci
7069

70+
COPY sandbox_entrypoint.sh ./
71+
COPY artifacts_uploader.py ./
72+
COPY tmp/config.py ./
73+
74+
# Download GitHub Actions runner.
75+
# We should upkeep GHAR_VER with the latest version in
76+
# https://api.github.com/repos/actions/runner/releases/latest
77+
# Failing to do so will slow down every sandbox execution, as the script
78+
# self-updates if it detects it's too old.
79+
RUN set -ex; \
80+
chmod 755 *; \
81+
mkdir github-action-runner; \
82+
cd github-action-runner; \
83+
GHAR_VER=2.323.0; \
84+
GHAR_URL=https://github.com/actions/runner/releases/download/v${GHAR_VER}/actions-runner-linux-x64-${GHAR_VER}.tar.gz; \
85+
curl -L $GHAR_URL | tar -xz; \
86+
chown -R perfetto:perfetto .;
87+
88+
89+
USER perfetto
90+
ENTRYPOINT [ "tini", "-g", "--" ]
91+
CMD [ "bash", "sandbox_entrypoint.sh" ]

0 commit comments

Comments
 (0)