-
Notifications
You must be signed in to change notification settings - Fork 0
Add ratchet coverage action #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Changelog | ||
|
|
||
| ## v1.0.0 | ||
|
|
||
| - Initial version with caching and baseline ratcheting. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Ratchet coverage | ||
|
|
||
| Generate code coverage using `cargo tarpaulin` and fail the workflow if the | ||
| coverage percentage falls below a stored baseline. | ||
|
|
||
| ## Inputs | ||
|
|
||
| | Name | Description | Required | Default | | ||
| | --- | --- | --- | --- | | ||
| | baseline-file | File used to persist the baseline coverage percentage between runs | no | `.coverage-baseline` | | ||
| | args | Additional arguments passed to `cargo tarpaulin` | no | *(none)* | | ||
|
|
||
|
Comment on lines
+8
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Documentation out of sync with action.yml inputs The inputs table includes Ensure 🤖 Prompt for AI Agents |
||
| ## Outputs | ||
|
|
||
| | Name | Description | | ||
| | --- | --- | | ||
| | percent | Coverage percentage reported by `cargo tarpaulin` | | ||
|
|
||
| ## Example | ||
|
|
||
| ```yaml | ||
| - uses: ./.github/actions/setup-rust@v1 | ||
| - uses: ./.github/actions/ratchet-coverage@v1 | ||
| with: | ||
| baseline-file: .cache/coverage-baseline | ||
| args: --workspace | ||
| ``` | ||
|
|
||
| `cargo tarpaulin` only runs on Linux hosts, so use this action on | ||
| `ubuntu-latest` runners. | ||
|
|
||
| ### How it works | ||
|
|
||
| The action restores the previous coverage baseline using `actions/cache` and | ||
| installs `cargo-tarpaulin` if necessary. After running the coverage command, it | ||
| compares the new percentage with the stored baseline. The job fails if coverage | ||
| has dropped. On success, the baseline file is updated and saved back to the | ||
| cache using a branch-specific key for future runs. | ||
|
|
||
| Release history is available in [CHANGELOG](CHANGELOG.md). | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||||||||||||||||||||||||||||
| name: Ratchet coverage | ||||||||||||||||||||||||||||||
| description: Run cargo tarpaulin and fail if coverage decreases | ||||||||||||||||||||||||||||||
| inputs: | ||||||||||||||||||||||||||||||
| baseline-file: | ||||||||||||||||||||||||||||||
| description: Path to store the coverage baseline | ||||||||||||||||||||||||||||||
| required: false | ||||||||||||||||||||||||||||||
| default: .coverage-baseline | ||||||||||||||||||||||||||||||
| args: | ||||||||||||||||||||||||||||||
| description: Additional arguments passed to cargo tarpaulin | ||||||||||||||||||||||||||||||
| required: false | ||||||||||||||||||||||||||||||
| default: '' | ||||||||||||||||||||||||||||||
| outputs: | ||||||||||||||||||||||||||||||
| percent: | ||||||||||||||||||||||||||||||
| description: Coverage percentage reported by cargo tarpaulin | ||||||||||||||||||||||||||||||
| value: ${{ steps.cov.outputs.percent }} | ||||||||||||||||||||||||||||||
| runs: | ||||||||||||||||||||||||||||||
| using: composite | ||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||
| - name: Restore baseline | ||||||||||||||||||||||||||||||
| uses: actions/cache@v4 | ||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||
| path: ${{ inputs.baseline-file }} | ||||||||||||||||||||||||||||||
| key: ratchet-baseline-${{ runner.os }}-${{ github.ref_name }} | ||||||||||||||||||||||||||||||
| - name: Cache cargo artifacts | ||||||||||||||||||||||||||||||
| uses: actions/cache@v4 | ||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||
| path: | | ||||||||||||||||||||||||||||||
| ~/.cargo/bin/cargo-tarpaulin | ||||||||||||||||||||||||||||||
| ~/.cargo/registry | ||||||||||||||||||||||||||||||
| ~/.cargo/git | ||||||||||||||||||||||||||||||
| target | ||||||||||||||||||||||||||||||
| key: ${{ runner.os }}-tarpaulin-${{ hashFiles('**/Cargo.lock') }} | ||||||||||||||||||||||||||||||
| restore-keys: | | ||||||||||||||||||||||||||||||
| ${{ runner.os }}-tarpaulin- | ||||||||||||||||||||||||||||||
| - name: Install cargo-tarpaulin | ||||||||||||||||||||||||||||||
| run: cargo install cargo-tarpaulin | ||||||||||||||||||||||||||||||
| shell: bash | ||||||||||||||||||||||||||||||
| - name: Run coverage | ||||||||||||||||||||||||||||||
| id: cov | ||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||
| output=$(cargo tarpaulin ${{ inputs.args }} --out lcov 2>&1) | ||||||||||||||||||||||||||||||
| echo "$output" | ||||||||||||||||||||||||||||||
| percent=$(echo "$output" | grep -oP '[0-9]+(?:\.[0-9]+)?(?=%)' | head -n1) | ||||||||||||||||||||||||||||||
| if [ -z "$percent" ]; then | ||||||||||||||||||||||||||||||
| echo "Unable to extract coverage percentage" >&2 | ||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
| echo "percent=$percent" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||||
| shell: bash | ||||||||||||||||||||||||||||||
| - name: Ratchet coverage | ||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||
| file="${{ inputs.baseline-file }}" | ||||||||||||||||||||||||||||||
| current="${{ steps.cov.outputs.percent }}" | ||||||||||||||||||||||||||||||
| baseline=0 | ||||||||||||||||||||||||||||||
| if [ -f "$file" ]; then | ||||||||||||||||||||||||||||||
| baseline=$(cat "$file") | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
| echo "Current coverage: $current%" | ||||||||||||||||||||||||||||||
| echo "Baseline coverage: $baseline%" | ||||||||||||||||||||||||||||||
| if ! [[ "$current" =~ ^[0-9]+(\.[0-9]+)?$ ]] || \ | ||||||||||||||||||||||||||||||
| ! [[ "$baseline" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then | ||||||||||||||||||||||||||||||
| echo "Invalid coverage values" >&2 | ||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
| # Ensure we're on Linux where `bc` is guaranteed to be installed | ||||||||||||||||||||||||||||||
| if [[ "$RUNNER_OS" != "Linux" ]]; then | ||||||||||||||||||||||||||||||
| echo "This action only supports Linux runners for float comparisons." >&2 | ||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if [ "$(echo "$current < $baseline" | bc -l)" = "1" ]; then | ||||||||||||||||||||||||||||||
|
leynos marked this conversation as resolved.
|
||||||||||||||||||||||||||||||
| echo "Coverage decreased" >&2 | ||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Ensure For example, prepend in the Ratchet coverage step: + if [[ "$RUNNER_OS" != "Linux" ]]; then
+ echo "This action only supports Linux runners for float comparisons." >&2
+ exit 1
+ fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| printf '%.2f' "$current" > "$file" | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Overwriting the baseline file may cause issues in concurrent runs. Parallel workflow runs could overwrite the same baseline file, causing race conditions. Use a branch- or run-specific cache key to avoid conflicts. |
||||||||||||||||||||||||||||||
| shell: bash | ||||||||||||||||||||||||||||||
| - name: Save baseline | ||||||||||||||||||||||||||||||
| if: success() | ||||||||||||||||||||||||||||||
| uses: actions/cache@v4 | ||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||
| path: ${{ inputs.baseline-file }} | ||||||||||||||||||||||||||||||
| key: ratchet-baseline-${{ runner.os }}-${{ github.ref_name }} | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .github/actions/export-postgres-url/ @leynos | ||
| .github/actions/generate-coverage/ @leynos | ||
| .github/actions/setup-rust/ @leynos | ||
| .github/actions/upload-codescene-coverage/ @leynos | ||
| .github/actions/ratchet-coverage/ @leynos |
Uh oh!
There was an error while loading. Please reload this page.