Skip to content

Commit

Permalink
Fix part of #5508: Limit APK/AAB Difference analysis reports in the P…
Browse files Browse the repository at this point in the history
…R Comment Thread (#5532)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->
Fixes part of #5508 

### This PR includes

Steps to locate the previous `stats.yml` workflow run, download its
build artifact, and compare it with the current build log. If changes
are detected, a comment will be uploaded to help minimize comment thread
overload.

**The implementation:**
- Download the previous build log artifact (if available).
- Run the script.
- Compare the current generated build log with the previous build log
artifact:
  - if no differences are found -> skip commenting.
  - if differences are found -> comment the current generated build log
- if no previous artifact is found -> comment the current generated
build log
    - This occurs in 2 instances:
      - 1. It's the first run of the PR.
- 2. An error occurred during the previous stat check (since the
previous build is from the second-to-last run ID).
- Upload the current build log as an artifact (for the next stat run).
- Comment/skip the stat report based on the comparison result.

#

### Tested with a cloned PR
_(with stats.yml implementation on develop)_

Tested PR:
Rd4dev/Oppia-Android-Fork-from-Fork#40

Reference for proof of implementation:

- [x] should comment on initial run |
[comment](Rd4dev/Oppia-Android-Fork-from-Fork#40 (comment))
| [stack
trace](https://github.com/Rd4dev/Oppia-Android-Fork-from-Fork/actions/runs/10762876260/job/29843752198#step:19:26)
- [x] shouldn't comment when no change |
[reference1](Rd4dev/Oppia-Android-Fork-from-Fork#40 (comment))
|
[reference2](Rd4dev/Oppia-Android-Fork-from-Fork#40 (comment))
- [x] should comment on change |
[comment](Rd4dev/Oppia-Android-Fork-from-Fork#40 (comment))
|
[reference](Rd4dev/Oppia-Android-Fork-from-Fork#40 (comment))
- [x] comment on previous build fail (replicated!) |
[comment](Rd4dev/Oppia-Android-Fork-from-Fork#40 (comment))
|
[reference](Rd4dev/Oppia-Android-Fork-from-Fork#40 (comment))

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

---------

Co-authored-by: Ben Henning <[email protected]>
  • Loading branch information
Rd4dev and BenHenning authored Sep 12, 2024
1 parent 4f4831a commit c82b71b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
run: |
cp $GITHUB_WORKSPACE/bazel-bin/oppia.apk /home/runner/work/oppia-android/oppia-android/
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: oppia-bazel.apk
path: /home/runner/work/oppia-android/oppia-android/oppia.apk
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
# We require 'sudo' to avoid an error of the existing android sdk. See https://github.com/actions/starter-workflows/issues/58
run: sudo ./gradlew --full-stacktrace :utility:testDebugUnitTest -Dorg.gradle.java.home=$JAVA_HOME
- name: Upload Utility Test Reports
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status
with:
name: utility reports
Expand All @@ -77,7 +77,7 @@ jobs:
# We require 'sudo' to avoid an error of the existing android sdk. See https://github.com/actions/starter-workflows/issues/58
run: sudo ./gradlew --full-stacktrace :data:testDebugUnitTest -Dorg.gradle.java.home=$JAVA_HOME
- name: Upload Data Test Reports
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status
with:
name: data reports
Expand All @@ -90,7 +90,7 @@ jobs:
# We require 'sudo' to avoid an error of the existing android sdk. See https://github.com/actions/starter-workflows/issues/58
run: sudo ./gradlew --full-stacktrace :domain:testDebugUnitTest -Dorg.gradle.java.home=$JAVA_HOME
- name: Upload Domain Test Reports
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status
with:
name: domain reports
Expand All @@ -103,7 +103,7 @@ jobs:
# We require 'sudo' to avoid an error of the existing android sdk. See https://github.com/actions/starter-workflows/issues/58
run: sudo ./gradlew --full-stacktrace :testing:testDebugUnitTest -Dorg.gradle.java.home=$JAVA_HOME
- name: Upload Testing Test Reports
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status
with:
name: testing reports
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
run: |
sudo ./gradlew --full-stacktrace :app:testDebugUnitTest --${{ matrix.shard }} -Dorg.gradle.java.home=$JAVA_HOME
- name: Upload App Test Reports
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status
with:
name: app reports ${{ matrix.shard }}
Expand Down
60 changes: 59 additions & 1 deletion .github/workflows/stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,63 @@ jobs:
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
Expand All @@ -203,14 +260,15 @@ jobs:
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@v2
- uses: actions/upload-artifact@v4
with:
name: ${{ env.FULL_BUILD_SUMMARY_FILE_NAME }}
path: ${{ env.FULL_BUILD_SUMMARY_FILE_PATH }}

0 comments on commit c82b71b

Please sign in to comment.