-
Notifications
You must be signed in to change notification settings - Fork 527
274 lines (245 loc) · 11.5 KB
/
stats.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# Contains jobs corresponding to stats, including build stats due to changes in a PR.
name: Stats Checks & Reports
on:
workflow_dispatch:
schedule:
- cron: "30 02 * * *"
permissions:
pull-requests: write
jobs:
find_open_pull_requests:
name: Find open PRs
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.compute-pull-request-matrix.outputs.matrix }}
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- name: Compute PR matrix
id: compute-pull-request-matrix
# Remove spaces to ensure the matrix output is on one line. Reference:
# https://stackoverflow.com/a/3232433.
run: |
CURRENT_OPEN_PR_INFO="$(gh pr list --json number,baseRefName,headRefName,headRepository,headRepositoryOwner | tr -d '[:space:]')"
echo "matrix={\"prInfo\": $CURRENT_OPEN_PR_INFO}" >> "$GITHUB_OUTPUT"
build_stats:
name: Build Stats
needs: find_open_pull_requests
runs-on: ubuntu-20.04
# Reduce parallelization due to high build times, and allow individual PRs to fail.
strategy:
fail-fast: false
max-parallel: 5
matrix: ${{ fromJson(needs.find_open_pull_requests.outputs.matrix) }}
env:
ENABLE_CACHING: false
CACHE_DIRECTORY: ~/.bazel_cache
steps:
- name: Compute PR head owner/repo reference
env:
PR_HEAD_REPO: ${{ matrix.prInfo.headRepository.name }}
PR_HEAD_REPO_OWNER: ${{ matrix.prInfo.headRepositoryOwner.login }}
run: |
echo "PR_HEAD=$PR_HEAD_REPO_OWNER/$PR_HEAD_REPO" >> "$GITHUB_ENV"
- name: Print PR information for this run
env:
PR_BASE_REF_NAME: ${{ matrix.prInfo.baseRefName }}
PR_HEAD_REF_NAME: ${{ matrix.prInfo.headRefName }}
PR_NUMBER: ${{ matrix.prInfo.number }}
run: |
echo "PR $PR_NUMBER is merging into $PR_BASE_REF_NAME from https://github.com/$PR_HEAD branch $PR_HEAD_REF_NAME."
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Set up Bazel
uses: abhinavsingh/setup-bazel@v3
with:
version: 6.5.0
# For reference on this & the later cache actions, see:
# https://github.com/actions/cache/issues/239#issuecomment-606950711 &
# https://github.com/actions/cache/issues/109#issuecomment-558771281. Note that these work
# with Bazel since Bazel can share the most recent cache from an unrelated build and still
# benefit from incremental build performance (assuming that actions/cache aggressively removes
# older caches due to the 5GB cache limit size & Bazel's large cache size).
- uses: actions/cache@v2
id: cache
with:
path: ${{ env.CACHE_DIRECTORY }}
key: ${{ runner.os }}-${{ env.CACHE_DIRECTORY }}-bazel-binary-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ env.CACHE_DIRECTORY }}-bazel-binary-
${{ runner.os }}-${{ env.CACHE_DIRECTORY }}-bazel-
# This check is needed to ensure that Bazel's unbounded cache growth doesn't result in a
# situation where the cache never updates (e.g. due to exceeding GitHub's cache size limit)
# thereby only ever using the last successful cache version. This solution will result in a
# few slower CI actions around the time cache is detected to be too large, but it should
# incrementally improve thereafter.
- name: Ensure cache size
env:
BAZEL_CACHE_DIR: ${{ env.CACHE_DIRECTORY }}
run: |
# See https://stackoverflow.com/a/27485157 for reference.
EXPANDED_BAZEL_CACHE_PATH="${BAZEL_CACHE_DIR/#\~/$HOME}"
CACHE_SIZE_MB=$(du -smc $EXPANDED_BAZEL_CACHE_PATH | grep total | cut -f1)
echo "Total size of Bazel cache (rounded up to MBs): $CACHE_SIZE_MB"
# Use a 4.5GB threshold since actions/cache compresses the results, and Bazel caches seem
# to only increase by a few hundred megabytes across changes for unrelated branches. This
# is also a reasonable upper-bound (local tests as of 2021-03-31 suggest that a full build
# of the codebase (e.g. //...) from scratch only requires a ~2.1GB uncompressed/~900MB
# compressed cache).
if [[ "$CACHE_SIZE_MB" -gt 4500 ]]; then
echo "Cache exceeds cut-off; resetting it (will result in a slow build)"
rm -rf $EXPANDED_BAZEL_CACHE_PATH
fi
- name: Configure Bazel to use a local cache
env:
BAZEL_CACHE_DIR: ${{ env.CACHE_DIRECTORY }}
run: |
EXPANDED_BAZEL_CACHE_PATH="${BAZEL_CACHE_DIR/#\~/$HOME}"
echo "Using $EXPANDED_BAZEL_CACHE_PATH as Bazel's cache path"
echo "build --disk_cache=$EXPANDED_BAZEL_CACHE_PATH" >> $HOME/.bazelrc
shell: bash
# This checks out the actual true develop branch separately to ensure that the stats check is
# run from the latest develop rather than the base branch (which might be different for
# chained PRs).
- name: Check out develop repository
uses: actions/checkout@v4
with:
path: develop
- name: Set up build environment
uses: ./develop/.github/actions/set-up-android-bazel-build-environment
- name: Check Bazel environment
run: |
cd develop
bazel info
- name: Check out base repository and branch
env:
PR_BASE_REF_NAME: ${{ matrix.prInfo.baseRefName }}
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.PR_BASE_REF_NAME }}
path: base
- name: Check out head repository and branch
env:
PR_HEAD_REF_NAME: ${{ matrix.prInfo.headRefName }}
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ env.PR_HEAD }}
ref: ${{ env.PR_HEAD_REF_NAME }}
path: head
# Note that Bazel is shutdown between builds since multiple Bazel servers will otherwise end
# up being active (due to multiple repositories being used) and this can quickly overwhelm CI
# worker resources.
- name: Build Oppia dev, alpha, beta, and GA (feature branch)
run: |
cd head
git log -n 1
bazel build -- //:oppia_dev //:oppia_alpha //:oppia_beta //:oppia_ga
cp bazel-bin/oppia_dev.aab ../develop/oppia_dev_with_changes.aab
cp bazel-bin/oppia_alpha.aab ../develop/oppia_alpha_with_changes.aab
cp bazel-bin/oppia_beta.aab ../develop/oppia_beta_with_changes.aab
cp bazel-bin/oppia_ga.aab ../develop/oppia_ga_with_changes.aab
bazel shutdown
- name: Build Oppia dev, alpha, beta, and GA (base branch)
run: |
cd base
git log -n 1
bazel build -- //:oppia_dev //:oppia_alpha //:oppia_beta //:oppia_ga
cp bazel-bin/oppia_dev.aab ../develop/oppia_dev_without_changes.aab
cp bazel-bin/oppia_alpha.aab ../develop/oppia_alpha_without_changes.aab
cp bazel-bin/oppia_beta.aab ../develop/oppia_beta_without_changes.aab
cp bazel-bin/oppia_ga.aab ../develop/oppia_ga_without_changes.aab
bazel shutdown
- name: Run stats analysis tool (develop branch)
run: |
cd develop
git log -n 1
bazel run //scripts:compute_aab_differences -- \
$(pwd)/brief_build_summary.log $(pwd)/full_build_summary.log \
dev $(pwd)/oppia_dev_without_changes.aab $(pwd)/oppia_dev_with_changes.aab \
alpha $(pwd)/oppia_alpha_without_changes.aab $(pwd)/oppia_alpha_with_changes.aab \
beta $(pwd)/oppia_beta_without_changes.aab $(pwd)/oppia_beta_with_changes.aab \
ga $(pwd)/oppia_ga_without_changes.aab $(pwd)/oppia_ga_with_changes.aab
- name: Find CI workflow run for PR
id: find-workflow-run
uses: actions/github-script@v7
continue-on-error: true
with:
script: |
const { owner, repo } = context.repo;
const runsResponse = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id: 'stats.yml',
});
const runs = runsResponse.data.workflow_runs;
runs.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
const run = runs[1];
if(!run) {
core.setFailed('Could not find a succesful workflow run');
return;
}
console.log(run.id);
core.setOutput('run-id', run.id);
- name: Download previous build summary
uses: actions/download-artifact@v4
with:
name: brief_build_summary_${{ matrix.prInfo.number }}
path: ./previous_build_logs
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.find-workflow-run.outputs.run-id }}
continue-on-error: true # Ignore errors if the file doesn't exist (first run)
- name: Compare current build summary with the previous one
id: build-comparison
run: |
if [ -f ./develop/brief_build_summary.log ]; then
echo "Comparing current and previous build summaries..."
if diff ./develop/brief_build_summary.log ./previous_build_logs/brief_build_summary.log > /dev/null; then
echo "No changes detected; skipping comment."
echo "skip_comment=true" >> $GITHUB_ENV
else
echo "Changes detected; proceeding with the comment."
echo "skip_comment=false" >> $GITHUB_ENV
fi
else
echo "No previous summary found; proceeding with the comment."
echo "skip_comment=false" >> $GITHUB_ENV
fi
- name: Upload current build summary for future comparison
uses: actions/upload-artifact@v4
with:
name: brief_build_summary_${{ matrix.prInfo.number }}
path: ./develop/brief_build_summary.log
# Reference: https://github.com/peter-evans/create-or-update-comment#setting-the-comment-body-from-a-file.
# Also, for multi-line env values, see: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings.
- name: Extract reports for uploading & commenting
env:
PR_NUMBER: ${{ matrix.prInfo.number }}
id: compute-comment-body
run: |
{
echo 'comment_body<<EOF'
cat $GITHUB_WORKSPACE/develop/brief_build_summary.log
echo EOF
} >> "$GITHUB_OUTPUT"
FULL_BUILD_SUMMARY_FILE_NAME="full_build_summary_pr_$PR_NUMBER.log"
FULL_BUILD_SUMMARY_FILE_PATH="$GITHUB_WORKSPACE/develop/$FULL_BUILD_SUMMARY_FILE_NAME"
echo "FULL_BUILD_SUMMARY_FILE_NAME=$FULL_BUILD_SUMMARY_FILE_NAME" >> "$GITHUB_ENV"
echo "FULL_BUILD_SUMMARY_FILE_PATH=$FULL_BUILD_SUMMARY_FILE_PATH" >> "$GITHUB_ENV"
cp "$GITHUB_WORKSPACE/develop/full_build_summary.log" "$FULL_BUILD_SUMMARY_FILE_PATH"
- name: Add build stats summary comment
if: ${{ env.skip_comment == 'false' }}
env:
PR_NUMBER: ${{ matrix.prInfo.number }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ env.PR_NUMBER }}
body: ${{ steps.compute-comment-body.outputs.comment_body }}
- uses: actions/upload-artifact@v4
with:
name: ${{ env.FULL_BUILD_SUMMARY_FILE_NAME }}
path: ${{ env.FULL_BUILD_SUMMARY_FILE_PATH }}