Skip to content

Commit

Permalink
Try caching coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlademann-wf committed Apr 3, 2024
1 parent 778da81 commit 03787c6
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 112 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Unit test coverage

on:
workflow_call:
inputs:
sdk:
required: true
type: string
head_commit_sha:
required: true
type: string
previous_commit_sha:
required: true
type: string
use_cached_coverage:
required: true
type: boolean

jobs:
get-cached-coverage:
runs-on: ubuntu-latest
outputs:
cache-hit: ${{ steps.download-cache.outputs.cache-hit == 'true' }}
steps:
- name: Get Cached Coverage Data
id: download-cache
uses: actions/cache/restore@v4
with:
path: |
reports/coverage
key: coverage@${{ inputs.previous_commit_sha }}

- name: Upload Cached Coverage Data
id: store-cache
if: ${{ steps.download-cache.outputs.cache-hit == 'true' }}
uses: actions/upload-artifact@v4
with:
name: coverage
path: reports/coverage

test-coverage:
runs-on: ubuntu-latest
needs: [ get-cached-coverage ]
steps:
- uses: actions/checkout@v4
if: ${{ !needs.get-cached-coverage.outputs.cache-hit || !inputs.use_cached_coverage }}

- uses: dart-lang/setup-dart@v1
if: ${{ !needs.get-cached-coverage.outputs.cache-hit || !inputs.use_cached_coverage }}
with:
sdk: ${{ inputs.sdk }}

- name: Run Tests (DDC + coverage)
if: ${{ !needs.get-cached-coverage.outputs.cache-hit || !inputs.use_cached_coverage }}
run: dart run dart_dev test --test-args="--coverage=reports/coverage" -P dartdevc

- name: Upload New Coverage Data
if: ${{ !needs.get-cached-coverage.outputs.cache-hit || !inputs.use_cached_coverage }}
uses: actions/upload-artifact@v4
with:
name: coverage
path: reports/coverage

generate-coverage:
runs-on: ubuntu-latest
needs: [ test-coverage ]
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ inputs.sdk }}
- name: Download Package Config
uses: actions/download-artifact@v4
with:
name: package_config@${{ inputs.sdk }}
path: .dart_tool

- name: Download Coverage Data
uses: actions/download-artifact@v4
with:
name: coverage
path: reports/coverage

- name: Activate Coverage Package
run: dart pub global activate coverage

- name: Format Coverage
run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o reports/coverage/lcov.info -i reports/coverage

- name: Cache Coverage Data
uses: actions/cache/save@v4
with:
path: |
reports/coverage
key: coverage@${{ inputs.head_commit_sha }}

- name: Report Coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: reports/coverage/lcov.info
10 changes: 2 additions & 8 deletions .github/workflows/dart_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ on:
branches:
- '**'

permissions:
contents: read
checks: write
deployments: write
id-token: write
pull-requests: write
statuses: read

jobs:
source-check:
uses: ./.github/workflows/source-check.yml
Expand All @@ -34,6 +26,8 @@ jobs:
gen_coverage: ${{ matrix.sdk == '2.19.6' }}
run_dart_checks: ${{ needs.source-check.outputs.run_dart_checks == 'true' }}
is_tag_build: ${{ needs.source-check.outputs.is_tag_build == 'true' }}
head_commit_sha: ${{ needs.source-check.outputs.head_commit_sha }}
previous_commit_sha: ${{ needs.source-check.outputs.previous_commit_sha }}

analyzer-plugin:
needs: [ source-check ]
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ on:
sdk:
required: true
type: string
gen_coverage:
required: true
store_package_config:
required: false
default: false
type: boolean
store_lockfile:
required: true
Expand Down Expand Up @@ -41,7 +42,7 @@ jobs:
path: pubspec.lock

- name: Upload Package Config
if: ${{ inputs.gen_coverage }}
if: ${{ inputs.store_package_config }}
uses: actions/upload-artifact@v4
with:
name: package_config@${{ inputs.sdk }}
Expand Down
111 changes: 20 additions & 91 deletions .github/workflows/lib_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,27 @@ on:
is_tag_build:
required: true
type: boolean

permissions:
contents: read
checks: write
deployments: write
id-token: write
pull-requests: write
statuses: read
head_commit_sha:
required: true
type: string
previous_commit_sha:
required: true
type: string

jobs:
install:
uses: ./.github/workflows/install.yml
with:
sdk: ${{ inputs.sdk }}
gen_coverage: ${{ inputs.gen_coverage }}
store_package_config: ${{ inputs.gen_coverage }}
store_lockfile: true

validate:
uses: ./.github/workflows/validate.yml
needs: [ install ]
with:
sdk: ${{ inputs.sdk }}

build-ddc:
needs: [ install ]
if: ${{ !inputs.is_tag_build && inputs.run_dart_checks }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ inputs.sdk }}

- id: build
timeout-minutes: 6
name: Build generated files / precompile DDC assets
run: |
dart run build_runner build --delete-conflicting-outputs
- name: Verify that generated files are up-to-date
run: |
if [ ${{ inputs.sdk }} = '2.18.7' ]; then
git diff --exit-code
else
# Don't check these generated files for other SDKs, since they may generate differently
# due to different resolved dependencies.
git diff --exit-code -- ":(exclude)test/mockito.mocks.dart" ":(exclude)test/over_react/component_declaration/redux_component_test/test_reducer.g.dart"
fi
if: steps.build.outcome == 'success'

# Analyze again after generated files are created to verify that those generated classes don't cause analysis errors
- name: Analyze project source (post-build)
run: dart analyze
if: steps.build.outcome == 'success'
run_ddc_build: ${{ !inputs.is_tag_build && inputs.run_dart_checks }}

test-dart2js:
needs: [ install ]
Expand Down Expand Up @@ -99,66 +66,28 @@ jobs:
run: dart test -P vm

test-ddc:
runs-on: ubuntu-latest
needs: [ install ]
# Run on a tag build no matter what so that coverage is generated for that commit
if: ${{ (inputs.is_tag_build && inputs.gen_coverage) || inputs.run_dart_checks }}
if: ${{ !inputs.gen_coverage && !inputs.is_tag_build && inputs.run_dart_checks }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ inputs.sdk }}

- name: Run tests (DDC)
if: ${{ !inputs.gen_coverage }}
- name: Run
run: dart run dart_dev test -P dartdevc

- name: Run tests (DDC + coverage)
if: ${{ inputs.gen_coverage }}
run: dart run dart_dev test --test-args="--coverage=reports/coverage" -P dartdevc

- name: Upload Coverage Data
if: ${{ inputs.gen_coverage }}
uses: actions/upload-artifact@v4
with:
name: coverage
path: reports/coverage

generate-coverage:
runs-on: ubuntu-latest
needs: [ install, test-ddc ]
test-coverage:
needs: [ install ]
if: ${{ inputs.gen_coverage }}
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ inputs.sdk }}
- name: Download Package Config
uses: actions/download-artifact@v4
with:
name: package_config@${{ inputs.sdk }}
path: .dart_tool
- name: Download Coverage Data
uses: actions/download-artifact@v4
with:
name: coverage
path: reports/coverage
- name: Activate Coverage Package
run: dart pub global activate coverage
- name: Format Coverage
run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o reports/coverage/lcov.info -i reports/coverage
- name: Upload Formatted Coverage as Artifact
uses: actions/upload-artifact@v4
with:
name: lcov.info
path: reports/coverage/lcov.info
- name: Upload Coverage to codecov.io
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: reports/coverage/lcov.info
uses: ./.github/workflows/coverage.yml
with:
sdk: ${{ inputs.sdk }}
head_commit_sha: ${{ inputs.head_commit_sha }}
previous_commit_sha: ${{ inputs.previous_commit_sha }}
use_cached_coverage: ${{ inputs.is_tag_build && inputs.gen_coverage }}

validate_analyzer:
validate-analyzer-5:
needs: [ install ]
if: ${{ !inputs.is_tag_build && inputs.run_dart_checks }}
runs-on: ubuntu-latest
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/plugin_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ on:
required: true
type: string

permissions:
contents: read
checks: write
deployments: write
id-token: write
pull-requests: write
statuses: read

jobs:
test:
runs-on: ubuntu-latest
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/source-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ name: Source check
on:
workflow_call:
outputs:
head_commit_sha:
description: "git rev-parse HEAD"
value: ${{ jobs.get-prev-sha.outputs.head_commit_sha }}
previous_commit_sha:
description: "git rev-parse HEAD~ (so we can retrieve a cached copy of code coverage on tag commits)"
value: ${{ jobs.get-prev-sha.outputs.previous_commit_sha }}
is_tag_build:
description: "Whether the build is the result of a tagged release commit"
value: ${{ jobs.git-diff.outputs.is_tag_build }}
Expand All @@ -11,6 +17,23 @@ on:
value: ${{ jobs.git-diff.outputs.run_dart_checks }}

jobs:
get-prev-sha:
runs-on: ubuntu-latest
outputs:
head_commit_sha: ${{ steps.rev-parse.outputs.head_commit_sha }}
previous_commit_sha: ${{ steps.rev-parse.outputs.previous_commit_sha }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ github.event.pull_request.head.sha }}
- name: Get Previous Commit Sha
id: rev-parse
shell: bash
run: |
echo "head_commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "previous_commit_sha=$(git rev-parse HEAD~)" >> "$GITHUB_OUTPUT"
git-diff:
runs-on: ubuntu-latest
outputs:
Expand Down
Loading

0 comments on commit 03787c6

Please sign in to comment.