Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix part of #1861: [RunAllTests] Update Bazel CI workflow to run all Oppia tests #1904

Merged
merged 77 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
34e00da
Update Bazel CI workflow
BenHenning Sep 24, 2020
3f0cd72
Update main.yml
BenHenning Sep 24, 2020
a94e160
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Sep 24, 2020
ec990f6
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Nov 17, 2020
5c92f2c
Introduce remote caching in Bazel.
BenHenning Nov 18, 2020
9d026e9
Add debug line.
BenHenning Nov 18, 2020
4ac50c6
Disable workflows + fix debug line.
BenHenning Nov 18, 2020
93c3608
More debugging.
BenHenning Nov 18, 2020
4df788f
More debugging.
BenHenning Nov 18, 2020
b292826
Work around GitHub hiding secret since we're debugging.
BenHenning Nov 18, 2020
5bbc72a
Use base64 to properly encode newlines in GPG keys.
BenHenning Nov 18, 2020
c9b9d0b
Remove debug lines before changing back to correct GPG key.
BenHenning Nov 18, 2020
ca3fadc
Switch to production key.
BenHenning Nov 18, 2020
7854318
Fix env variable reference. Lock-down actions workflows via codeowners.
BenHenning Nov 18, 2020
74a775b
Install git-secret to default location.
BenHenning Nov 18, 2020
dfa9874
Add details. Debug $PATH.
BenHenning Nov 18, 2020
3064c24
Fix pathing for git-secret.
BenHenning Nov 18, 2020
2fd8663
Dummy commit to re-trigger actions.
BenHenning Nov 18, 2020
e099d9d
Undo commit to see if this one shows up.
BenHenning Nov 18, 2020
54e7996
Fix git-secret pathing try 2.
BenHenning Nov 18, 2020
17a4cf2
New commit to re-trigger action.
BenHenning Nov 18, 2020
5013d2e
Path debugging.
BenHenning Nov 18, 2020
ed344b0
Workaround to get GitHub to show changes.
BenHenning Nov 18, 2020
dce4133
Update runner to use Bash.
BenHenning Nov 18, 2020
8794e18
Restore binary-only build, other builds, and introduce new workflow for
BenHenning Nov 19, 2020
f7b10f2
Remove debug lines.
BenHenning Nov 19, 2020
9cbd94c
Rename & remove keep_going.
BenHenning Nov 19, 2020
2aa0944
Compute matrix containing all test targets.
BenHenning Nov 20, 2020
226c4a1
Simplify, fix some issues, and debug instead of run.
BenHenning Nov 20, 2020
7ae7e5f
Turn on actual testing.
BenHenning Nov 20, 2020
f26276e
Lower parallelization since GitHub started cancelling tasks.
BenHenning Nov 20, 2020
1850784
Try 15 parallel jobs instead.
BenHenning Nov 20, 2020
49b3584
Turn off fail-fast instead of limiting parallelization.
BenHenning Nov 20, 2020
c1546cb
Simplify workflow & allow it to be required.
BenHenning Nov 20, 2020
dcda583
Add test change to investigate computing affected targets.
BenHenning Nov 20, 2020
4aff1a8
Another test change to compute affected targets.
BenHenning Nov 20, 2020
d5904c1
Update workflow to use future script compute_affected_tests.sh.
BenHenning Nov 20, 2020
479d683
Add script to compute affected targets.
BenHenning Nov 20, 2020
c2c9fcd
Execute tests in parallel to build.
BenHenning Nov 20, 2020
372f2f4
Script clean-ups.
BenHenning Nov 20, 2020
5c888de
Try to ensure develop branch is available for change analysis.
BenHenning Nov 20, 2020
0bd5532
Add automatic workflow cancellation.
BenHenning Nov 20, 2020
fe0fec6
Attempt to make conditional matrix computation work.
BenHenning Nov 20, 2020
1155a9f
Remove join since it was used incorrectly.
BenHenning Nov 20, 2020
1b25e34
Add support for testing when Bazel, BUILD, and WORKSPACE files change.
BenHenning Nov 21, 2020
86c5c93
Fix broken tests by adding missing dep library.
BenHenning Nov 21, 2020
7ed040e
Finalize PR.
BenHenning Nov 21, 2020
ba45fd9
Lint fix.
BenHenning Nov 21, 2020
d7fd5bb
Fix timing issues and JDK 9-specific regression.
BenHenning Nov 23, 2020
80a6039
Restore workflow names + introduce test check.
BenHenning Nov 23, 2020
528bf6b
Update StateFragmentLocalTest.kt
BenHenning Nov 24, 2020
e691094
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Nov 24, 2020
d8d2fec
Merge branch 'build-all-targets-in-bazel-ci' of github.com:oppia/oppi…
BenHenning Nov 24, 2020
062b34d
Address reviewer comments.
BenHenning Dec 9, 2020
7a1ecbf
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Dec 9, 2020
cd4d4fd
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Dec 15, 2020
9530d12
Fix most tests broken in Bazel after syncing.
BenHenning Dec 16, 2020
a3fa326
Gitignore + fix broken test.
BenHenning Dec 16, 2020
3360b8c
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Dec 16, 2020
5908e77
Lint fixes.
BenHenning Dec 16, 2020
355d964
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Jan 7, 2021
654c27a
Post-merge clean-up.
BenHenning Jan 7, 2021
32a6009
Fix broken post-merge test.
BenHenning Jan 8, 2021
f2aacb0
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Jan 8, 2021
f3cb6f5
Remove unnecessary codeowners per earlier codeowners setup.
BenHenning Jan 8, 2021
8d4eb87
Fix
BenHenning Jan 8, 2021
5926861
Disable image region selection tests.
BenHenning Jan 8, 2021
b4cd6b4
Disable 2 previously missed tests.
BenHenning Jan 8, 2021
e33250a
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Jan 19, 2021
61eaeb3
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Jan 26, 2021
3fafc6c
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Feb 8, 2021
eae9660
Post-merge lint fix.
BenHenning Feb 8, 2021
a8bd5b3
Add missing dependency.
BenHenning Feb 9, 2021
33d4c37
Add missing codeowners for new files.
BenHenning Feb 9, 2021
3312174
Merge branch 'develop' into build-all-targets-in-bazel-ci
BenHenning Feb 11, 2021
b44ae3a
Post-merge fixes.
BenHenning Feb 11, 2021
1a3f4e9
Move Bazel tests to new workflow.
BenHenning Feb 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# (See oppia/#10250 for an example.) Please make sure to restore ownership after
# the above date passes.

# GitHub Actions & CI workflows.
.github/*.yaml @BenHenning
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
.github/*.yml @BenHenning

# Blanket codeowners
# This is for the case when new files are created in any directories that aren't
# covered as a whole, since in these cases, codeowners are not recognized for
Expand Down
167 changes: 153 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
jobs:
linters:
name: Lint Tests
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
Expand Down Expand Up @@ -47,10 +47,10 @@ jobs:

robolectric_tests:
name: Robolectric Tests (Non-App Modules)
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
os: [ubuntu-18.04]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down Expand Up @@ -104,11 +104,11 @@ jobs:

app_tests:
name: Robolectric Tests - App Module (Non-Flaky)
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
steps:
steps:
- uses: actions/checkout@v2

- uses: actions/cache@v2
Expand Down Expand Up @@ -140,33 +140,172 @@ jobs:
os: [ubuntu-18.04]
steps:
- uses: actions/checkout@v2
- name: Set up bazel
uses: jwlawson/actions-setup-bazel@v1
with:
bazel-version: '3.4.1'
- name: Clone Oppia Bazel
run: git clone https://github.com/oppia/bazel.git $HOME/oppia-bazel
- name: Set up JDK 9
uses: actions/setup-java@v1
with:
java-version: 9
- name: Extract Android Tools
- name: Extract Android tools
run: |
mkdir -p $GITHUB_WORKSPACE/tmp/android_tools
cd $HOME/oppia-bazel
unzip bazel-tools.zip
tar -xf $HOME/oppia-bazel/android_tools.tar.gz -C $GITHUB_WORKSPACE/tmp/android_tools
- name: Unzip Bazel Binary and Build Oppia
# See https://git-secret.io/installation for details on installing git-secret. Note that the
# apt-get method isn't used since it's much slower to update & upgrade apt before installation
# versus just directly cloning & installing the project. Further, the specific version
# shouldn't matter since git-secret relies on a future-proof storage mechanism for secrets.
# This also uses a different directory to install git-secret to avoid requiring root access
# when running the git secret command.
- name: Install git-secret (non-fork only)
if: github.repository == 'oppia/oppia-android'
shell: bash
run: |
cd $HOME
mkdir -p $HOME/gitsecret
git clone https://github.com/sobolevn/git-secret.git git-secret
cd git-secret && make build
PREFIX="$HOME/gitsecret" make install
echo "$HOME/gitsecret" >> $GITHUB_PATH
echo "$HOME/gitsecret/bin" >> $GITHUB_PATH
- name: Decrypt secrets (non-fork only)
if: github.repository == 'oppia/oppia-android'
env:
GIT_SECRET_GPG_PRIVATE_KEY: ${{ secrets.GIT_SECRET_GPG_PRIVATE_KEY }}
run: |
cd $HOME
# NOTE TO DEVELOPERS: Make sure to never print this key directly to stdout!
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
echo $GIT_SECRET_GPG_PRIVATE_KEY | base64 --decode > ./git_secret_private_key.gpg
gpg --import ./git_secret_private_key.gpg
cd $GITHUB_WORKSPACE
git secret reveal
- name: Unzip Bazel binary
run: |
cd $HOME/oppia-bazel
unzip bazel-build.zip
cd $GITHUB_WORKSPACE
chmod a+x $HOME/oppia-bazel/bazel
$HOME/oppia-bazel/bazel build //:oppia --android_databinding_use_v3_4_args --experimental_android_databinding_v2 --override_repository=android_tools=$GITHUB_WORKSPACE/tmp/android_tools --java_header_compilation=false --noincremental_dexing --define=android_standalone_dexing_tool=d8_compat_dx
cp $GITHUB_WORKSPACE/bazel-bin/oppia.apk /home/runner/work/oppia-android/oppia-android/
# Note that caching only works on non-forks.
- name: Build Oppia binary (with caching, non-fork only)
if: github.repository == 'oppia/oppia-android'
env:
BAZEL_REMOTE_CACHE_URL: ${{ secrets.BAZEL_REMOTE_CACHE_URL }}
run: |
$HOME/oppia-bazel/bazel build --override_repository=android_tools=$GITHUB_WORKSPACE/tmp/android_tools --remote_http_cache=$BAZEL_REMOTE_CACHE_URL --google_credentials=./config/oppia-dev-workflow-remote-cache-credentials.json -- //:oppia
- name: Build Oppia binary (without caching, fork only)
if: github.repository != 'oppia/oppia-android'
run: |
$HOME/oppia-bazel/bazel build --override_repository=android_tools=$GITHUB_WORKSPACE/tmp/android_tools -- //:oppia
- name: Copy Oppia APK for uploading
run: cp $GITHUB_WORKSPACE/bazel-bin/oppia.apk /home/runner/work/oppia-android/oppia-android/
- uses: actions/upload-artifact@v2
with:
name: oppia-bazel-apk
path: /home/runner/work/oppia-android/oppia-android/oppia.apk

bazel_compute_affected_targets:
name: Compute affected tests
runs-on: ubuntu-18.04
outputs:
matrix: ${{ steps.compute-test-matrix-from-affected.outputs.matrix || steps.compute-test-matrix-from-all.outputs.matrix }}
steps:
- uses: actions/checkout@v2

with:
fetch-depth: 0
- name: Clone Oppia Bazel
run: git clone https://github.com/oppia/bazel.git $HOME/oppia-bazel
- name: Unzip Bazel binary
run: |
cd $HOME/oppia-bazel
unzip bazel-build.zip
cd $GITHUB_WORKSPACE
chmod a+x $HOME/oppia-bazel/bazel
- name: Compute test matrix based on affected targets
id: compute-test-matrix-from-affected
if: "!contains(github.event.pull_request.title, '[RunAllTests]')"
# https://unix.stackexchange.com/a/338124 for reference on creating a JSON-friendly
# comma-separated list of test targets for the matrix.
run: |
TEST_TARGET_LIST=$(bash ./scripts/compute_affected_tests.sh $HOME/oppia-bazel/bazel | sed 's/^\|$/"/g' | paste -sd, -)
echo "Affected tests (note that this might be all tests if on the develop branch): $TEST_TARGET_LIST"
echo "::set-output name=matrix::{\"test-target\":[$TEST_TARGET_LIST]}"
- name: Compute test matrix based on all tests
id: compute-test-matrix-from-all
if: "contains(github.event.pull_request.title, '[RunAllTests]')"
run: |
TEST_TARGET_LIST=$($HOME/oppia-bazel/bazel query "kind(test, //...)" | sed 's/^\|$/"/g' | paste -sd, -)
echo "Affected tests (note that this might be all tests if on the develop branch): $TEST_TARGET_LIST"
echo "::set-output name=matrix::{\"test-target\":[$TEST_TARGET_LIST]}"

bazel_run_test:
name: Run Bazel Test
needs: bazel_compute_affected_targets
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix: ${{fromJson(needs.bazel_compute_affected_targets.outputs.matrix)}}
steps:
- uses: actions/checkout@v2
- name: Clone Oppia Bazel
run: git clone https://github.com/oppia/bazel.git $HOME/oppia-bazel
- name: Set up JDK 9
uses: actions/setup-java@v1
with:
java-version: 9
- name: Extract Android tools
run: |
mkdir -p $GITHUB_WORKSPACE/tmp/android_tools
cd $HOME/oppia-bazel
unzip bazel-tools.zip
tar -xf $HOME/oppia-bazel/android_tools.tar.gz -C $GITHUB_WORKSPACE/tmp/android_tools
# See explanation in bazel_build_app for how this is installed.
- name: Install git-secret (non-fork only)
vinitamurthi marked this conversation as resolved.
Show resolved Hide resolved
if: github.repository == 'oppia/oppia-android'
shell: bash
run: |
cd $HOME
mkdir -p $HOME/gitsecret
git clone https://github.com/sobolevn/git-secret.git git-secret
cd git-secret && make build
PREFIX="$HOME/gitsecret" make install
echo "$HOME/gitsecret" >> $GITHUB_PATH
echo "$HOME/gitsecret/bin" >> $GITHUB_PATH
- name: Decrypt secrets (non-fork only)
if: github.repository == 'oppia/oppia-android'
env:
GIT_SECRET_GPG_PRIVATE_KEY: ${{ secrets.GIT_SECRET_GPG_PRIVATE_KEY }}
run: |
cd $HOME
# NOTE TO DEVELOPERS: Make sure to never print this key directly to stdout!
echo $GIT_SECRET_GPG_PRIVATE_KEY | base64 --decode > ./git_secret_private_key.gpg
gpg --import ./git_secret_private_key.gpg
cd $GITHUB_WORKSPACE
git secret reveal
- name: Unzip Bazel binary
run: |
cd $HOME/oppia-bazel
unzip bazel-build.zip
cd $GITHUB_WORKSPACE
chmod a+x $HOME/oppia-bazel/bazel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a modular way, as the cloning oppia/bazel and setting the secret key is something we are performing more than once?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was added to GitHub recently: https://github.blog/changelog/2020-08-07-github-actions-composite-run-steps/. It requires creating custom actions that perform sub-steps in the same repo. I didn't pursue it since it would take more time to figure out how to do this correctly, but I can look into if you feel strongly (I'm also not a fan of reusing large, complicated portions of the actions script, but I also feel that this is something we can simplify in subsequent PRs).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. This could be a good learning issue around GitHub actions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea--will keep this open as a reminder for me to file an issue for this later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #2692.

- name: Run Oppia Test (with caching, non-fork only)
if: github.repository == 'oppia/oppia-android'
env:
BAZEL_REMOTE_CACHE_URL: ${{ secrets.BAZEL_REMOTE_CACHE_URL }}
run: $HOME/oppia-bazel/bazel test --override_repository=android_tools=$GITHUB_WORKSPACE/tmp/android_tools --remote_http_cache=$BAZEL_REMOTE_CACHE_URL --google_credentials=./config/oppia-dev-workflow-remote-cache-credentials.json -- ${{ matrix.test-target }}
- name: Run Oppia Test (without caching, fork only)
if: github.repository != 'oppia/oppia-android'
env:
BAZEL_REMOTE_CACHE_URL: ${{ secrets.BAZEL_REMOTE_CACHE_URL }}
run: $HOME/oppia-bazel/bazel test --override_repository=android_tools=$GITHUB_WORKSPACE/tmp/android_tools -- ${{ matrix.test-target }}

# Reference: https://github.community/t/127354/7.
check_test_results:
name: Check Bazel Test Results
needs: bazel_run_test
if: ${{ always() }}
runs-on: ubuntu-18.04
steps:
- name: Check tests passed
if: ${{ needs.bazel_run_test.result != 'success' }}
run: exit 1
28 changes: 28 additions & 0 deletions .github/workflows/workflow_canceller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Automatic Workflow Canceller

# This workflow should be triggered in one of three situations:
# 1. Manual workflow dispatch via https://github.com/oppia/oppia-android/actions.
# 2. Upon creation of a PR & updates to that PR.
# 3. Whenever the develop branch is changed (e.g. after a PR is merged).
#
# Note that the action being used here automatically accounts for the current branch & the commit
# hash of the tip of the branch to ensure it doesn't cancel previous workflows that aren't related
# to the branch being evaluated.
on:
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
workflow_dispatch:
pull_request:
push:
branches:
# Push events on develop branch
- develop

jobs:
cancel:
name: Cancel Previous Runs
runs-on: ubuntu-18.04
steps:
# See https://github.com/styfle/cancel-workflow-action for details on this workflow.
- uses: styfle/[email protected]
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
with:
workflow_id: main.yml
access_token: ${{ github.token }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ utility/build
gradle
gradlew
gradlew.bat
.gitsecret/keys/random_seed
!*.secret
config/oppia-dev-workflow-remote-cache-credentials.json
bazel-*
.bazelproject
Binary file added .gitsecret/keys/pubring.kbx
Binary file not shown.
Binary file added .gitsecret/keys/pubring.kbx~
Binary file not shown.
Binary file added .gitsecret/keys/trustdb.gpg
Binary file not shown.
1 change: 1 addition & 0 deletions .gitsecret/paths/mapping.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config/oppia-dev-workflow-remote-cache-credentials.json:c02f95d3829f9a7fb3757170ade432efa43d562d2e7c208372ec9d0f4a45da1a
1 change: 1 addition & 0 deletions app/src/main/res/layout-land/submitted_answer_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/submitted_answer_container"
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:explorationSplitViewMarginApplicable="@{viewModel.hasConversationView &amp;&amp; viewModel.isSplitView}"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/submitted_answer_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/submitted_answer_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:explorationSplitViewMarginApplicable="@{viewModel.hasConversationView &amp;&amp; viewModel.isSplitView}"
Expand Down
Loading