Skip to content

Commit 2d9cdd2

Browse files
committed
Execute build and e2e tests on push, not pr.
As configured, the same set of tests runs on pull request and on the merge queue. This is redundant, and flakes can cause large delays. Ideally, we should reduce the redundancy, either by pushing tests from pull request to merge, or vice versa. The consensus is on the former, to ensure that the code at HEAD is most likely to be passing tests. As I understand it, the `push` GitHub workflow event triggers on the merge queue, so the new pull request workflow triggers on the `pull_request` event. This workflow does not run any of the build or end-to-end checks, which can take a long time, only the static and unit checks.
1 parent cf3ba1d commit 2d9cdd2

File tree

2 files changed

+178
-1
lines changed

2 files changed

+178
-1
lines changed

.github/workflows/pr.yaml

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
name: Pull request
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
# limits the workflow to a single run per branch/PR
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
# previous runs are cancelled when a new run is started
10+
cancel-in-progress: true
11+
12+
jobs:
13+
buildozer:
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 # aka v2
18+
- name: Install go
19+
uses: actions/setup-go@v3
20+
with:
21+
go-version: '1.23.1'
22+
- name: Install buildozer
23+
run: go install github.com/bazelbuild/buildtools/buildozer@latest
24+
- name: Validate formatting
25+
working-directory: base/cvd
26+
if: '!cancelled()'
27+
run: |
28+
if [[ $(buildozer '//...:__pkg__' format 2>&1) ]]; then
29+
echo "Please format BUILD.bazel files with \"buildozer '//...:__pkg__' format\"";
30+
exit 1;
31+
fi
32+
- name: Validate no cc_binary targets under //cuttlefish
33+
if: '!cancelled()'
34+
working-directory: base/cvd
35+
run: |
36+
if [[ $(buildozer print '//cuttlefish/...:%cc_binary') ]]; then
37+
buildozer print '//cuttlefish/...:%cc_binary'
38+
echo "Please use cf_cc_binary rather than cc_binary";
39+
exit 1;
40+
fi
41+
- name: Validate no cc_library targets under //cuttlefish
42+
if: '!cancelled()'
43+
working-directory: base/cvd
44+
run: |
45+
if [[ $(buildozer print '//cuttlefish/...:%cc_library') ]]; then
46+
buildozer print '//cuttlefish/...:%cc_library'
47+
echo "Please use cf_cc_library rather than cc_library";
48+
exit 1;
49+
fi
50+
- name: Validate no cc_test targets under //cuttlefish
51+
if: '!cancelled()'
52+
working-directory: base/cvd
53+
run: |
54+
if [[ $(buildozer print '//cuttlefish/...:%cc_test') ]]; then
55+
buildozer print '//cuttlefish/...:%cc_test'
56+
echo "Please use cf_cc_test rather than cc_test";
57+
exit 1;
58+
fi;
59+
- name: Validate no unused loads
60+
if: '!cancelled()'
61+
working-directory: base/cvd
62+
run: |
63+
if [[ $(buildozer -stdout=true '//...:__pkg__' 'fix unusedLoads') ]]; then
64+
buildozer '//...:__pkg__' 'fix unusedLoads'
65+
echo "Please remove unused 'load' statements with \"buildozer '//...:__pkg__' 'fix unusedLoads'\"";
66+
exit 1;
67+
fi
68+
staticcheck:
69+
runs-on: ubuntu-22.04
70+
strategy:
71+
matrix:
72+
dir: ["e2etests", "frontend/src/host_orchestrator", "frontend/src/libhoclient", "frontend/src/liboperator", "frontend/src/operator", "tools/baseimage"]
73+
steps:
74+
- name: Checkout repository
75+
uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 # aka v2
76+
- name: Install dependencies
77+
uses: actions/setup-go@v3
78+
with:
79+
go-version: '1.24.2'
80+
- run: go version
81+
- name: Staticcheck
82+
uses: dominikh/[email protected]
83+
with:
84+
version: "latest"
85+
install-go: false
86+
working-directory: ${{ matrix.dir }}
87+
run-frontend-unit-tests:
88+
runs-on: ubuntu-22.04
89+
container:
90+
image: debian@sha256:9258a75a7e4323c9e5562b361effc84ee747920116d8adfc98a465a5cdc9150e # debian:bookworm-20250407 (amd64)
91+
env:
92+
GOPROJECTS: ('host_orchestrator' 'libhoclient' 'liboperator' 'operator')
93+
steps:
94+
- name: Checkout repository
95+
uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 # aka v2
96+
- name: Setup apt
97+
run: apt update -y && apt upgrade -y
98+
- name: Install dependencies
99+
run: apt install -y git golang
100+
- name: Go version
101+
run: go version
102+
- name: Run gofmt check
103+
shell: bash
104+
run: |
105+
projects=${{ env.GOPROJECTS }}
106+
for item in "${projects[@]}"; do
107+
pushd "frontend/src/${item}"
108+
gofmt -d -e . && test -z "$(gofmt -l .)"
109+
popd
110+
done
111+
- name: Run go tests
112+
shell: bash
113+
run: |
114+
projects=${{ env.GOPROJECTS }}
115+
for item in "${projects[@]}"; do
116+
pushd "frontend/src/${item}"
117+
go test ./...
118+
popd
119+
done
120+
run-frontend-api-documentation-check:
121+
runs-on: ubuntu-22.04
122+
container:
123+
image: debian@sha256:9258a75a7e4323c9e5562b361effc84ee747920116d8adfc98a465a5cdc9150e # debian:bookworm-20250407 (amd64)
124+
env:
125+
GOPROJECTS: ('host_orchestrator')
126+
steps:
127+
- name: Setup apt
128+
run: apt update -y && apt upgrade -y
129+
- name: Install dependencies
130+
run: apt install -y git golang
131+
- name: Setup git
132+
run: |
133+
git --version
134+
# Fixes fatal: detected dubious ownership in repository at '/__w/android-cuttlefish/android-cuttlefish'
135+
git config --global --add safe.directory /__w/android-cuttlefish/android-cuttlefish
136+
- name: Go version
137+
run: go version
138+
- name: Checkout repository
139+
uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 # aka v2
140+
- name: Install swag
141+
run: go install github.com/swaggo/swag/cmd/[email protected]
142+
- name: Run swag check
143+
shell: bash
144+
run: |
145+
$(go env GOPATH)/bin/swag --version
146+
projects=${{ env.GOPROJECTS }}
147+
for item in "${projects[@]}"; do
148+
pushd "frontend/src/${item}"
149+
$(go env GOPATH)/bin/swag fmt
150+
git diff --exit-code || ( echo "format error: see frontend/src/host_orchestrator/README.md" && false)
151+
$(go env GOPATH)/bin/swag init
152+
git diff --exit-code || ( echo "This change requires REST API documentation update: see frontend/src/host_orchestrator/README.md" && false)
153+
popd
154+
done
155+
run-cvd-unit-tests:
156+
runs-on: ubuntu-24.04
157+
steps:
158+
- name: Free disk space
159+
uses: jlumbroso/[email protected]
160+
with:
161+
large-packages: false
162+
swap-storage: false
163+
tool-cache: true
164+
- name: Checkout repository
165+
uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 # aka v2
166+
- name: Mount Bazel cache
167+
uses: ./.github/actions/mount-bazel-cache
168+
with:
169+
action-name: "run-cvd-unit-tests"
170+
- name: Run cvd unit tests
171+
uses: ./.github/actions/run-cvd-unit-tests
172+
- name: Upload test logs
173+
if: always()
174+
uses: actions/upload-artifact@v4
175+
with:
176+
name: cvd-unit-tests-logs
177+
path: base/cvd/bazel-out/k8-fastbuild/testlogs

.github/workflows/presubmit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Presubmit
22

33
on:
4-
pull_request:
4+
workflow_dispatch:
55
push:
66
branches-ignore:
77
- main # push events to main branch occur after PRs are merged, when the same checks were run

0 commit comments

Comments
 (0)