From 4139e37c4640d46c1c20d3015240cbda2ee218dd Mon Sep 17 00:00:00 2001 From: RD Rama Devi <122200035+Rd4dev@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:02:02 +0530 Subject: [PATCH 1/5] Updated comment_coverage_report.yml based on previous comment Checks for the latest code coverage report and if they are identical then it skips posting a redundant comment else will proceed to post the currently generated code coverage report as comment. --- .github/workflows/comment_coverage_report.yml | 67 +++++++++++++------ 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/.github/workflows/comment_coverage_report.yml b/.github/workflows/comment_coverage_report.yml index 0cc70da29a2..0b3075de32e 100644 --- a/.github/workflows/comment_coverage_report.yml +++ b/.github/workflows/comment_coverage_report.yml @@ -2,12 +2,12 @@ name: Comment Coverage Report -# Controls when the action will run. Triggers the workflow on pull request events -# (opened, synchronize, reopened) +# Controls when the action will run. Triggers the workflow on pull request events +# (assigned, opened, synchronize, reopened) on: pull_request_target: - types: [opened, synchronize, reopened] + types: [assigned, opened, synchronize, reopened] concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} @@ -17,8 +17,6 @@ jobs: check_code_coverage_completed: name: Check code coverage completed runs-on: ubuntu-latest - outputs: - conclusion: ${{ steps.wait-for-coverage.outputs.run-conclusion }} steps: - name: Wait for code coverage to complete id: wait-for-coverage @@ -29,13 +27,6 @@ jobs: allowed-conclusions: | success failure - action_required - - - name: Conclusion Analysis - if: steps.wait-for-coverage.outputs.run-conclusion == 'action_required' - run: | - echo "::error::First-time contributor workflows require manual approval. After approval, please re-run the comment coverage workflows to post the coverage report." - exit 1 comment_coverage_report: name: Comment Code Coverage Report @@ -45,9 +36,27 @@ jobs: # The expression if: ${{ !cancelled() }} runs a job or step regardless of its success or failure while responding to cancellations, # serving as a cancellation-compliant alternative to if: ${{ always() }} in concurrent workflows. - if: ${{ !cancelled() }} - runs-on: ubuntu-latest + 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 @@ -59,22 +68,22 @@ jobs: const runsResponse = await github.rest.actions.listWorkflowRuns({ owner, repo, - workflow_id: 'code_coverage.yml', + workflow_id: 'code_coverage.yml', event: 'pull_request', head_sha: '${{ github.event.pull_request.head.sha }}', }); - + 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[0]; if(!run) { - core.setFailed('Could not find a successful workflow run for the PR'); + core.setFailed('Could not find a succesful workflow run for the PR'); return; } core.setOutput('run-id', run.id); - + - name: Download Generated Markdown Report uses: actions/download-artifact@v4 if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status @@ -82,9 +91,29 @@ 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 }} - body-path: 'CoverageReport.md' + body-path: 'CoverageReport.md' From 3828869fc2ac01910bbe38df7b0328543449de3a Mon Sep 17 00:00:00 2001 From: RD Rama Devi <122200035+Rd4dev@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:05:39 +0530 Subject: [PATCH 2/5] Updated stats.yml to post analysis only with follow up comments This basically works in the way of pull_request triggers but with cron jobs to run every single day and check if there are any follow up commits to the latest apk aab analysis report and skips commenting if there aren't as it essentially means there is no changes in the report (other than other merged base branch code) and posts a comment if there are follow up commits. --- .github/workflows/stats.yml | 498 ++++++++++++++++++------------------ 1 file changed, 254 insertions(+), 244 deletions(-) diff --git a/.github/workflows/stats.yml b/.github/workflows/stats.yml index 74cbbeabbed..7e69fed49ca 100644 --- a/.github/workflows/stats.yml +++ b/.github/workflows/stats.yml @@ -3,272 +3,282 @@ name: Stats Checks & Reports on: - workflow_dispatch: - schedule: - - cron: "30 02 * * *" + workflow_dispatch: + schedule: + - cron: "30 02 * * *" permissions: - pull-requests: write + 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 + 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" + - 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 + 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: 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 }}, + }); - - 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 + 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; - # 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 + require('fs').writeFileSync('latest_aab_comment_body.log', commentBody, 'utf8'); + core.setOutput("latest_aab_comment_created_at", commentDate); + + return + } + } - - name: Set up build environment - uses: ./develop/.github/actions/set-up-android-bazel-build-environment + - 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 }} + 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: Check Bazel environment - run: | - cd develop - bazel info + - name: Set up JDK 11 + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + uses: actions/setup-java@v1 + with: + java-version: 11 - - 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: Set up Bazel + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + uses: abhinavsingh/setup-bazel@v3 + with: + version: 6.5.0 - - 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 + # 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 + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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- - # 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 + # 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 + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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: 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: Configure Bazel to use a local cache + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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: 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 + # 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 + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + uses: actions/checkout@v4 + with: + path: develop - - 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', - }); + - name: Set up build environment + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + uses: ./develop/.github/actions/set-up-android-bazel-build-environment - const runs = runsResponse.data.workflow_runs; - runs.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); + - name: Check Bazel environment + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + run: | + cd develop + bazel info - const run = runs[1]; - if(!run) { - core.setFailed('Could not find a succesful workflow run'); - return; - } - console.log(run.id); + - 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 + with: + fetch-depth: 0 + ref: ${{ env.PR_BASE_REF_NAME }} + path: base - core.setOutput('run-id', run.id); + - 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 + with: + fetch-depth: 0 + repository: ${{ env.PR_HEAD }} + ref: ${{ env.PR_HEAD_REF_NAME }} + path: head - - 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) + # 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) + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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: 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: Build Oppia dev, alpha, beta, and GA (base branch) + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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: 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 + - name: Run stats analysis tool (develop branch) + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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 - # 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<> "$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" + # 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 + run: | + { + echo 'comment_body<> "$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 }} + - name: Add build stats summary comment + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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 }} + - 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 }} From e61f7c2f7656f9d36c29bb910fa247f4371045f4 Mon Sep 17 00:00:00 2001 From: RD Rama Devi <122200035+Rd4dev@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:47:04 +0530 Subject: [PATCH 3/5] Updated comment_coverage_report.yml with upstream changes and fix indentations --- .github/workflows/comment_coverage_report.yml | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/comment_coverage_report.yml b/.github/workflows/comment_coverage_report.yml index 0b3075de32e..765fe298515 100644 --- a/.github/workflows/comment_coverage_report.yml +++ b/.github/workflows/comment_coverage_report.yml @@ -2,12 +2,12 @@ name: Comment Coverage Report -# Controls when the action will run. Triggers the workflow on pull request events -# (assigned, opened, synchronize, reopened) +# Controls when the action will run. Triggers the workflow on pull request events +# (opened, synchronize, reopened) on: pull_request_target: - types: [assigned, opened, synchronize, reopened] + types: [opened, synchronize, reopened] concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} @@ -17,6 +17,8 @@ jobs: check_code_coverage_completed: name: Check code coverage completed runs-on: ubuntu-latest + outputs: + conclusion: ${{ steps.wait-for-coverage.outputs.run-conclusion }} steps: - name: Wait for code coverage to complete id: wait-for-coverage @@ -27,6 +29,13 @@ jobs: allowed-conclusions: | success failure + action_required + + - name: Conclusion Analysis + if: steps.wait-for-coverage.outputs.run-conclusion == 'action_required' + run: | + echo "::error::First-time contributor workflows require manual approval. After approval, please re-run the comment coverage workflows to post the coverage report." + exit 1 comment_coverage_report: name: Comment Code Coverage Report @@ -36,8 +45,8 @@ jobs: # The expression if: ${{ !cancelled() }} runs a job or step regardless of its success or failure while responding to cancellations, # serving as a cancellation-compliant alternative to if: ${{ always() }} in concurrent workflows. - if: ${{ !cancelled() }} - runs-on: ubuntu-latest + if: ${{ !cancelled() }} + runs-on: ubuntu-latest steps: - name: Find the latest Code Coverage Report Comment uses: actions/github-script@v6 @@ -68,7 +77,7 @@ jobs: const runsResponse = await github.rest.actions.listWorkflowRuns({ owner, repo, - workflow_id: 'code_coverage.yml', + workflow_id: 'code_coverage.yml', event: 'pull_request', head_sha: '${{ github.event.pull_request.head.sha }}', }); @@ -78,7 +87,7 @@ jobs: const run = runs[0]; if(!run) { - core.setFailed('Could not find a succesful workflow run for the PR'); + core.setFailed('Could not find a successful workflow run for the PR'); return; } @@ -116,4 +125,4 @@ jobs: uses: peter-evans/create-or-update-comment@v4 with: issue-number: ${{ github.event.pull_request.number }} - body-path: 'CoverageReport.md' + body-path: 'CoverageReport.md' From 8630ac41399a9061e5404ae1000d98bee49c6763 Mon Sep 17 00:00:00 2001 From: RD Rama Devi <122200035+Rd4dev@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:48:25 +0530 Subject: [PATCH 4/5] Update indentations on blank lines with comment_coverage_report.yml --- .github/workflows/comment_coverage_report.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/comment_coverage_report.yml b/.github/workflows/comment_coverage_report.yml index 765fe298515..4a04401e88f 100644 --- a/.github/workflows/comment_coverage_report.yml +++ b/.github/workflows/comment_coverage_report.yml @@ -30,7 +30,7 @@ jobs: success failure action_required - + - name: Conclusion Analysis if: steps.wait-for-coverage.outputs.run-conclusion == 'action_required' run: | @@ -81,7 +81,7 @@ jobs: event: 'pull_request', head_sha: '${{ github.event.pull_request.head.sha }}', }); - + const runs = runsResponse.data.workflow_runs; runs.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); @@ -92,7 +92,7 @@ jobs: } core.setOutput('run-id', run.id); - + - name: Download Generated Markdown Report uses: actions/download-artifact@v4 if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status From 049135cb7bdcfadd06dc9255728ee2fd585a5f81 Mon Sep 17 00:00:00 2001 From: RD Rama Devi <122200035+Rd4dev@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:55:04 +0530 Subject: [PATCH 5/5] Updating indents with stats.yml --- .github/workflows/stats.yml | 498 ++++++++++++++++++------------------ 1 file changed, 249 insertions(+), 249 deletions(-) diff --git a/.github/workflows/stats.yml b/.github/workflows/stats.yml index 7e69fed49ca..bdcb532c03e 100644 --- a/.github/workflows/stats.yml +++ b/.github/workflows/stats.yml @@ -3,282 +3,282 @@ name: Stats Checks & Reports on: - workflow_dispatch: - schedule: - - cron: "30 02 * * *" + workflow_dispatch: + schedule: + - cron: "30 02 * * *" permissions: - pull-requests: write + 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 + 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" + - 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: 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 }}, - }); + 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: 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; + 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); + require('fs').writeFileSync('latest_aab_comment_body.log', commentBody, 'utf8'); + core.setOutput("latest_aab_comment_created_at", commentDate); - return - } - } + 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 }}, - }); + - 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 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"); - } + 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: 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 }} - 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: 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 }} + 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 - if: ${{ steps.track_commits.outputs.new_commits == 'true' }} - uses: actions/setup-java@v1 - with: - java-version: 11 + - 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 + - name: Set up Bazel + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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 - if: ${{ steps.track_commits.outputs.new_commits == 'true' }} - 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- + # 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 + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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 - if: ${{ steps.track_commits.outputs.new_commits == 'true' }} - 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 + # 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 + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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 - if: ${{ steps.track_commits.outputs.new_commits == 'true' }} - 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: Configure Bazel to use a local cache + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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 - if: ${{ steps.track_commits.outputs.new_commits == 'true' }} - uses: actions/checkout@v4 - with: - path: develop + # 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 + 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: 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 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 - with: - fetch-depth: 0 - ref: ${{ env.PR_BASE_REF_NAME }} - path: base + - 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 + with: + fetch-depth: 0 + ref: ${{ env.PR_BASE_REF_NAME }} + 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 - with: - fetch-depth: 0 - repository: ${{ env.PR_HEAD }} - ref: ${{ env.PR_HEAD_REF_NAME }} - path: head + - 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 + 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) - if: ${{ steps.track_commits.outputs.new_commits == 'true' }} - 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 + # 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) + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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) - if: ${{ steps.track_commits.outputs.new_commits == 'true' }} - 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: Build Oppia dev, alpha, beta, and GA (base branch) + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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) - if: ${{ steps.track_commits.outputs.new_commits == 'true' }} - 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: Run stats analysis tool (develop branch) + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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 - # 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 - run: | - { - echo 'comment_body<> "$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" + # 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 + run: | + { + echo 'comment_body<> "$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: ${{ steps.track_commits.outputs.new_commits == 'true' }} - 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 }} + - name: Add build stats summary comment + if: ${{ steps.track_commits.outputs.new_commits == 'true' }} + 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 - if: ${{ steps.track_commits.outputs.new_commits == 'true' }} - with: - name: ${{ env.FULL_BUILD_SUMMARY_FILE_NAME }} - path: ${{ env.FULL_BUILD_SUMMARY_FILE_PATH }} + - 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 }}