Bind Reports to Pull-Request #103
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
name: Bind Reports to Pull-Request | |
on: | |
workflow_run: | |
workflows: [Generate Reports] | |
types: [completed] | |
permissions: | |
pull-requests: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: subosito/flutter-action@v2 | |
with: | |
channel: 'stable' | |
cache: true | |
- name: Get Artifacts Link | |
env: | |
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }} | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
ARTIFACT_ID=$(gh api "/repos/${{ github.repository }}/actions/artifacts" \ | |
--jq ".artifacts.[] | | |
select(.workflow_run.id==${PREVIOUS_JOB_ID}) | | |
.id") | |
echo "ARTIFACT_URL=https://github.com/${{ github.repository }}/suites/${SUITE_ID}/artifacts/${ARTIFACT_ID}" >> $GITHUB_ENV | |
PR_NUMBER=$(jq -r '.pull_requests[0].number' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV | |
- name: Get Total Coverage | |
run: | | |
flutter pub get | |
dart run grinder test --coverage | |
COVERAGE=$(dart run test_cov_console --file="./coverage/lcov.info" --total | tr -d '[:space:]') | |
curl -vLJO -H 'Accept: application/octet-stream' "https://lyskouski.github.io/app-finance/coverage/test_total.log" | |
MAIN_COVERAGE=$(cat test_total.log | tr -d '[:space:]') | |
echo "Main branch coverage: $MAIN_COVERAGE %" | |
echo "Current branch coverage: $COVERAGE %" | |
DELTA=$(echo "$COVERAGE - $MAIN_COVERAGE" | bc) | |
echo "DELTA_COVERAGE=${DELTA}" >> $GITHUB_ENV | |
- uses: actions/github-script@v6 | |
env: | |
PR_NUMBER: ${{ env.PR_NUMBER }} | |
PR_NOTES: | | |
Build artifacts: | |
| Name | Link | | |
|------|------| | |
| Dependencies Graph | [dependencies.svg](${{ env.ARTIFACT_URL }}) | | |
Coverage delta: ${{ env.DELTA_COVERAGE }}% | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: process.env.PR_NUMBER, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: process.env.PR_NOTES | |
}) | |