Skip to content

Commit

Permalink
Merge branch 'caption-tag' of https://github.com/manas-yu/oppia-android
Browse files Browse the repository at this point in the history
… into caption-tag
  • Loading branch information
manas-yu committed Dec 13, 2024
2 parents 890343a + fa83941 commit 72fa61f
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 94 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/comment_coverage_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ jobs:
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- name: Find the latest Code Coverage Report Comment
uses: actions/github-script@v6
with:
script: |
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.pull_request.number }},
});
for (let i = comments.length - 1; i >= 0; i--) {
if (comments[i].body.includes("## Coverage Report")) {
const latestCodeCoverageComment = comments[i].body;
require('fs').writeFileSync('latest_code_coverage_comment.md', latestCodeCoverageComment, 'utf8');
return
}
}
- name: Find CI workflow run for PR
id: find-workflow-run
uses: actions/github-script@v7
Expand Down Expand Up @@ -82,8 +100,28 @@ jobs:
name: final-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.find-workflow-run.outputs.run-id }}

- name: Compare Current Coverage Report with the Latest Coverage Report
run: |
if [ -f latest_code_coverage_comment.md ]; then
sed -i -e '$a\' CoverageReport.md
sed -i -e '$a\' latest_code_coverage_comment.md
if diff -B CoverageReport.md latest_code_coverage_comment.md > /dev/null; then
echo "No changes detected; skipping coverage comment."
echo "skip_coverage_comment=true" >> $GITHUB_ENV
else
echo "Changes detected; proceeding with the coverage comment."
diff CoverageReport.md latest_code_coverage_comment.md || true
echo "skip_coverage_comment=false" >> $GITHUB_ENV
fi
else
echo "No previous coverage comment found to compare; posting evaluated coverage comment."
echo "skip_coverage_comment=false" >> $GITHUB_ENV
fi
- name: Upload Coverage Report as PR Comment
if: ${{ env.skip_coverage_comment == 'false' }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
Expand Down
126 changes: 68 additions & 58 deletions .github/workflows/stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,65 @@ jobs:
ENABLE_CACHING: false
CACHE_DIRECTORY: ~/.bazel_cache
steps:
- name: Find the latest APK & AAB Analysis Comment
uses: actions/github-script@v6
id: find_latest_apk_aab_comment
with:
script: |
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ matrix.prInfo.number }},
});
for (let i = comments.length - 1; i >= 0; i--) {
if (comments[i].body.includes("# APK & AAB differences analysis")) {
const latestComment = comments[i];
const commentBody = latestComment.body;
const commentDate = latestComment.created_at;
require('fs').writeFileSync('latest_aab_comment_body.log', commentBody, 'utf8');
core.setOutput("latest_aab_comment_created_at", commentDate);
return
}
}
- name: Track Commits following the latest APK & AAB Analysis Comment
uses: actions/github-script@v6
id: track_commits
with:
script: |
const commits = await github.paginate(github.rest.pulls.listCommits, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ matrix.prInfo.number }},
});
const latestCommentDate = "${{ steps.find_latest_apk_aab_comment.outputs.latest_aab_comment_created_at }}";
const recentCommits = commits.filter(commit => {
const commitDate = new Date(commit.commit.committer.date);
return commitDate > new Date("${{ steps.find_latest_apk_aab_comment.outputs.latest_aab_comment_created_at }}");
});
const recentCommitsCount = recentCommits.length;
if(recentCommitsCount > 0 || !latestCommentDate) {
core.setOutput("new_commits", "true");
} else {
console.log("No new commits since the last APK & AAB report; Skipping redundant analysis.");
core.setOutput("new_commits", "false");
}
- name: Compute PR head owner/repo reference
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
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
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
env:
PR_BASE_REF_NAME: ${{ matrix.prInfo.baseRefName }}
PR_HEAD_REF_NAME: ${{ matrix.prInfo.headRefName }}
Expand All @@ -57,11 +109,13 @@ jobs:
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
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
uses: actions/setup-java@v1
with:
java-version: 11

- name: Set up Bazel
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
uses: abhinavsingh/setup-bazel@v3
with:
version: 6.5.0
Expand All @@ -73,6 +127,7 @@ jobs:
# 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
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
id: cache
with:
path: ${{ env.CACHE_DIRECTORY }}
Expand All @@ -87,6 +142,7 @@ jobs:
# few slower CI actions around the time cache is detected to be too large, but it should
# incrementally improve thereafter.
- name: Ensure cache size
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
env:
BAZEL_CACHE_DIR: ${{ env.CACHE_DIRECTORY }}
run: |
Expand All @@ -105,6 +161,7 @@ jobs:
fi
- name: Configure Bazel to use a local cache
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
env:
BAZEL_CACHE_DIR: ${{ env.CACHE_DIRECTORY }}
run: |
Expand All @@ -117,19 +174,23 @@ jobs:
# run from the latest develop rather than the base branch (which might be different for
# chained PRs).
- name: Check out develop repository
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
uses: actions/checkout@v4
with:
path: develop

- name: Set up build environment
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
uses: ./develop/.github/actions/set-up-android-bazel-build-environment

- name: Check Bazel environment
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
run: |
cd develop
bazel info
- name: Check out base repository and branch
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
env:
PR_BASE_REF_NAME: ${{ matrix.prInfo.baseRefName }}
uses: actions/checkout@v4
Expand All @@ -139,6 +200,7 @@ jobs:
path: base

- name: Check out head repository and branch
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
env:
PR_HEAD_REF_NAME: ${{ matrix.prInfo.headRefName }}
uses: actions/checkout@v4
Expand All @@ -152,6 +214,7 @@ jobs:
# 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)
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
run: |
cd head
git log -n 1
Expand All @@ -163,6 +226,7 @@ jobs:
bazel shutdown
- name: Build Oppia dev, alpha, beta, and GA (base branch)
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
run: |
cd base
git log -n 1
Expand All @@ -174,6 +238,7 @@ jobs:
bazel shutdown
- name: Run stats analysis tool (develop branch)
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
run: |
cd develop
git log -n 1
Expand All @@ -184,66 +249,10 @@ 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
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
env:
PR_NUMBER: ${{ matrix.prInfo.number }}
id: compute-comment-body
Expand All @@ -260,7 +269,7 @@ 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' }}
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
env:
PR_NUMBER: ${{ matrix.prInfo.number }}
uses: peter-evans/create-or-update-comment@v1
Expand All @@ -269,6 +278,7 @@ jobs:
body: ${{ steps.compute-comment-body.outputs.comment_body }}

- uses: actions/upload-artifact@v4
if: ${{ steps.track_commits.outputs.new_commits == 'true' }}
with:
name: ${{ env.FULL_BUILD_SUMMARY_FILE_NAME }}
path: ${{ env.FULL_BUILD_SUMMARY_FILE_PATH }}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AudioViewModel @Inject constructor(
}

fun loadMainContentAudio(allowAutoPlay: Boolean, reloadingContent: Boolean) {
setStateAndExplorationId(state, explorationId)
hasFeedback = false
loadAudio(contentId = null, allowAutoPlay, reloadingContent)
}
Expand All @@ -88,7 +89,12 @@ class AudioViewModel @Inject constructor(
* @param allowAutoPlay If false, audio is guaranteed not to be autoPlayed.
*/
private fun loadAudio(contentId: String?, allowAutoPlay: Boolean, reloadingMainContent: Boolean) {
val targetContentId = contentId ?: state.content.contentId
val targetContentId = when {
!contentId.isNullOrEmpty() -> contentId
this::state.isInitialized -> state.content.contentId
else -> ""
}

val voiceoverMapping =
state.recordedVoiceoversMap[targetContentId] ?: VoiceoverMapping.getDefaultInstance()

Expand All @@ -106,10 +112,9 @@ class AudioViewModel @Inject constructor(
selectedLanguageName.set(locale.getDisplayLanguage(locale))

when {
selectedLanguageCode.isEmpty() && languages.any {
it == defaultLanguage
} -> setAudioLanguageCode(defaultLanguage)
languages.any { it == selectedLanguageCode } -> setAudioLanguageCode(selectedLanguageCode)
selectedLanguageCode.isEmpty() && languages.contains(defaultLanguage) ->
setAudioLanguageCode(defaultLanguage)
languages.contains(selectedLanguageCode) -> setAudioLanguageCode(selectedLanguageCode)
languages.isNotEmpty() -> {
autoPlay = false
this.reloadingMainContent = false
Expand Down
Loading

0 comments on commit 72fa61f

Please sign in to comment.