Skip to content

Commit

Permalink
Merge pull request #11 from oppia/add-build-stats-ci-workflow
Browse files Browse the repository at this point in the history
Add build stats ci workflow
  • Loading branch information
BenHenning authored May 23, 2024
2 parents a59ff53 + 32733a0 commit 6fd8628
Show file tree
Hide file tree
Showing 589 changed files with 18,400 additions and 20,610 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ build --android_databinding_use_v3_4_args \
--define=android_standalone_dexing_tool=d8_compat_dx \
--android_databinding_use_androidx

# Ensure all built Java files treat warnings as errors (similar to the Kotlin configuration) to help
# reduce code smell & potential bugs during development.
build --javacopt="-Werror"

# Show all test output by default (for better debugging).
test --test_output=all
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ WORKSPACE @oppia/android-app-infrastructure-reviewers
.bazelrc @oppia/android-app-infrastructure-reviewers
.bazelversion @oppia/android-app-infrastructure-reviewers
/tools/android/ @oppia/android-app-infrastructure-reviewers
/tools/kotlin/ @oppia/android-app-infrastructure-reviewers

# Configurations for Bazel-built Android App Bundles.
/bundle_config.pb.json @oppia/android-dev-workflow-reviewers
Expand Down
139 changes: 139 additions & 0 deletions .github/workflows/stats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Contains jobs corresponding to stats, including build stats due to changes in a PR.

name: Stats Checks & Reports

on:
pull_request:

jobs:
build_stats:
name: Build Stats
runs-on: ubuntu-20.04
env:
ENABLE_CACHING: false
CACHE_DIRECTORY: ~/.bazel_cache
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up JDK 9
uses: actions/setup-java@v1
with:
java-version: 9

- name: Set up Bazel
uses: abhinavsingh/setup-bazel@v3
with:
version: 4.0.0

- name: Set up build environment
uses: ./.github/actions/set-up-android-bazel-build-environment

# 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

- name: Check Bazel environment
run: bazel info
- name: Change to base
env:
base_commit_hash: ${{ github.event.pull_request.base.sha }}
run: |
git checkout $base_commit_hash
git log -n 1
- name: Build Oppia dev, alpha, beta, and GA (base)
run: |
bazel build -- //:oppia_dev //:oppia_alpha //:oppia_beta //:oppia_ga
cp bazel-bin/oppia_dev.aab ./oppia_dev_without_changes.aab
cp bazel-bin/oppia_alpha.aab ./oppia_alpha_without_changes.aab
cp bazel-bin/oppia_beta.aab ./oppia_beta_without_changes.aab
cp bazel-bin/oppia_ga.aab ./oppia_ga_without_changes.aab
- name: Change to feature branch
run: |
git checkout $GITHUB_SHA
git log -n 1
- name: Build Oppia dev, alpha, beta, and GA (branch)
run: |
bazel build -- //:oppia_dev //:oppia_alpha //:oppia_beta //:oppia_ga
cp bazel-bin/oppia_dev.aab ./oppia_dev_with_changes.aab
cp bazel-bin/oppia_alpha.aab ./oppia_alpha_with_changes.aab
cp bazel-bin/oppia_beta.aab ./oppia_beta_with_changes.aab
cp bazel-bin/oppia_ga.aab ./oppia_ga_with_changes.aab
- name: Run stats analysis tool
run: |
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
# Reference: https://github.com/peter-evans/create-or-update-comment#setting-the-comment-body-from-a-file.
- name: Extract reports for uploading & commenting
id: compute-comment-body
run: |
comment_body="$(cat /home/runner/work/oppia-android/oppia-android/brief_build_summary.log)"
comment_body="${comment_body//'%'/'%25'}"
comment_body="${comment_body//$'\n'/'%0A'}"
comment_body="${comment_body//$'\r'/'%0D'}"
echo "::set-output name=comment_body::$comment_body"
- name: Add build stats summary comment
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.compute-comment-body.outputs.comment_body }}

- uses: actions/upload-artifact@v2
with:
name: fill-build-summary.log
path: |
/home/runner/work/oppia-android/oppia-android/full_build_summary.log
3 changes: 3 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TODO(#1532): Rename file to 'BUILD' post-Gradle.

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("//:build_flavors.bzl", "AVAILABLE_FLAVORS", "define_oppia_aab_binary_flavor", "transform_android_manifest")
load("//:version.bzl", "MAJOR_VERSION", "MINOR_VERSION", "OPPIA_DEV_KITKAT_VERSION_CODE", "OPPIA_DEV_VERSION_CODE")

Expand Down Expand Up @@ -137,3 +138,5 @@ package_group(
define_oppia_aab_binary_flavor(flavor = flavor)
for flavor in AVAILABLE_FLAVORS
]

dagger_rules()
95 changes: 72 additions & 23 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ This file lists and imports all external dependencies needed to build Oppia Andr

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_jar")
load("//third_party:versions.bzl", "HTTP_DEPENDENCY_VERSIONS", "get_maven_dependencies")
load("//:build_vars.bzl", "BUILD_SDK_VERSION", "BUILD_TOOLS_VERSION")
load("//third_party:versions.bzl", "HTTP_DEPENDENCY_VERSIONS", "MAVEN_REPOSITORIES", "get_maven_dependencies")

# Android SDK configuration. For more details, see:
# https://docs.bazel.build/versions/master/be/android.html#android_sdk_repository
# TODO(#1542): Sync Android SDK version with the manifest.
android_sdk_repository(
name = "androidsdk",
api_level = 33,
build_tools_version = "29.0.2",
api_level = BUILD_SDK_VERSION,
build_tools_version = BUILD_TOOLS_VERSION,
)

# Add support for JVM rules: https://github.com/bazelbuild/rules_jvm_external
Expand All @@ -26,20 +27,22 @@ http_archive(
# Add support for Kotlin: https://github.com/bazelbuild/rules_kotlin.
http_archive(
name = "io_bazel_rules_kotlin",
patches = ["//tools/kotlin:add_kotlinc_optin_support.patch"],
sha256 = HTTP_DEPENDENCY_VERSIONS["rules_kotlin"]["sha"],
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % HTTP_DEPENDENCY_VERSIONS["rules_kotlin"]["version"]],
)

# TODO(#1535): Remove once rules_kotlin is released because these lines become unnecessary
load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version")

kt_download_local_dev_dependencies()

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")

kotlin_repositories()
# Use the 1.6 compiler since rules_kotlin 1.5 defaults to the 1.5 compiler.
kotlin_repositories(
compiler_release = kotlinc_version(
release = "1.6.21",
sha256 = "632166fed89f3f430482f5aa07f2e20b923b72ef688c8f5a7df3aa1502c6d8ba",
),
)

kt_register_toolchains()
register_toolchains("//tools/kotlin:kotlin_16_jdk9_toolchain")

# The proto_compiler and proto_java_toolchain bindings load the protos rules needed for the model
# module while helping us avoid the unnecessary compilation of protoc. Referecences:
Expand Down Expand Up @@ -96,8 +99,9 @@ load("@dagger//:workspace_defs.bzl", "DAGGER_ARTIFACTS", "DAGGER_REPOSITORIES")
# Add support for Robolectric: https://github.com/robolectric/robolectric-bazel
http_archive(
name = "robolectric",
strip_prefix = "robolectric-bazel-4.5",
urls = ["https://github.com/robolectric/robolectric-bazel/archive/4.5.tar.gz"],
sha256 = HTTP_DEPENDENCY_VERSIONS["robolectric"]["sha"],
strip_prefix = "robolectric-bazel-%s" % HTTP_DEPENDENCY_VERSIONS["robolectric"]["version"],
urls = ["https://github.com/robolectric/robolectric-bazel/archive/%s.tar.gz" % HTTP_DEPENDENCY_VERSIONS["robolectric"]["version"]],
)

load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")
Expand All @@ -109,6 +113,7 @@ git_repository(
name = "tools_android",
commit = "00e6f4b7bdd75911e33c618a9bc57bab7a6e8930",
remote = "https://github.com/bazelbuild/tools_android",
shallow_since = "1594238320 -0400",
)

load("@tools_android//tools/googleservices:defs.bzl", "google_services_workspace_dependencies")
Expand All @@ -126,18 +131,25 @@ git_repository(

git_repository(
name = "android-spotlight",
commit = "ebde38335bfb56349eae57e705b611ead9addb15",
commit = "cc23499d37dc8533a2876e45b5063e981a4583f4",
remote = "https://github.com/oppia/android-spotlight",
shallow_since = "1668824029 -0800",
shallow_since = "1680147372 -0700",
)

# A custom fork of KotliTeX that removes resources artifacts that break the build, and updates the
# min target SDK version to be compatible with Oppia.
git_repository(
name = "kotlitex",
commit = "43139c140833c7120f351d63d74b42c253d2b213",
commit = "ccdf4170817fa3b48b8e1e452772dd58ecb71cf2",
remote = "https://github.com/oppia/kotlitex",
shallow_since = "1647554845 -0700",
shallow_since = "1679426649 -0700",
)

git_repository(
name = "archive_patcher",
commit = "d1c18b0035d5f669ddaefadade49cae0748f9df2",
remote = "https://github.com/oppia/archive-patcher",
shallow_since = "1642022460 -0800",
)

bind(
Expand All @@ -147,6 +159,7 @@ bind(

http_archive(
name = "protobuf_tools",
sha256 = HTTP_DEPENDENCY_VERSIONS["protobuf_tools"]["sha"],
strip_prefix = "protobuf-%s" % HTTP_DEPENDENCY_VERSIONS["protobuf_tools"]["version"],
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v{0}/protobuf-all-{0}.zip".format(HTTP_DEPENDENCY_VERSIONS["protobuf_tools"]["version"])],
)
Expand Down Expand Up @@ -178,16 +191,52 @@ http_jar(
# Note to developers: new dependencies should be added to //third_party:versions.bzl, not here.
maven_install(
artifacts = DAGGER_ARTIFACTS + get_maven_dependencies(),
duplicate_version_warning = "error",
fail_if_repin_required = True,
fetch_sources = True,
maven_install_json = "//third_party:maven_install.json",
repositories = DAGGER_REPOSITORIES + [
"https://maven.fabric.io/public",
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
override_targets = {
"com.google.guava:guava": "@//third_party:com_google_guava_guava",
"org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm": "@//third_party:kotlinx-coroutines-core-jvm",
},
repositories = DAGGER_REPOSITORIES + MAVEN_REPOSITORIES,
strict_visibility = True,
)

load("@maven//:defs.bzl", "pinned_maven_install")

pinned_maven_install()

[
http_jar(
name = "guava_%s" % guava_type,
sha256 = HTTP_DEPENDENCY_VERSIONS["guava_%s" % guava_type]["sha"],
urls = [
"{0}/com/google/guava/guava/{1}-{2}/guava-{1}-{2}.jar".format(
url_base,
HTTP_DEPENDENCY_VERSIONS["guava_%s" % guava_type]["version"],
guava_type,
)
for url_base in DAGGER_REPOSITORIES + MAVEN_REPOSITORIES
],
)
for guava_type in [
"android",
"jre",
]
]

http_jar(
name = "kotlinx-coroutines-core-jvm",
sha256 = HTTP_DEPENDENCY_VERSIONS["kotlinx-coroutines-core-jvm"]["sha"],
urls = [
"{0}/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/{1}/kotlinx-coroutines-core-jvm-{1}.jar".format(
url_base,
HTTP_DEPENDENCY_VERSIONS["kotlinx-coroutines-core-jvm"]["version"],
)
for url_base in DAGGER_REPOSITORIES + MAVEN_REPOSITORIES
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()
Loading

0 comments on commit 6fd8628

Please sign in to comment.