Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Rust

permissions: read-all
permissions:
contents: read
pull-requests: write

on:
push:
Expand Down Expand Up @@ -81,6 +83,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Download coverage reports
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
Expand All @@ -91,6 +95,15 @@ jobs:
run: |
sed -i 's#SF:/Users/#SF:/home/#g' lcov/*apple-darwin*.info
npx lcov-result-merger 'lcov/lcov-*.info' lcov.info
- name: Upload coverage
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7
continue-on-error: true
- name: Upload Coverage
run: |
PR_ARGS=""
if [ "${{ github.event_name }}" = "pull_request" ]; then
git fetch origin ${{ github.event.pull_request.base.sha }}
PR_ARGS="--pr ${{ github.event.pull_request.number }} --pr-base ${{ github.event.pull_request.base.sha }}"
fi
node tools/codecov/upload.mjs ./lcov.info $PR_ARGS
env:
CODECOV_URL: ${{ vars.CODECOV_URL }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion alioth/src/firmware/acpi/reg_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ fn test_pm_timer() {
let timer = AcpiPmTimer::default();
let v1 = timer.read(0, 4).unwrap();
let v2 = timer.read(0, 4).unwrap();
assert!(v2 > v1);
assert!(v2 >= v1);
}
13 changes: 13 additions & 0 deletions tools/codecov/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Dependencies
node_modules/

# Build Output
dist/
.wrangler/

# Environment Variables
.dev.vars

# Operating System Files
.DS_Store
Thumbs.db
130 changes: 130 additions & 0 deletions tools/codecov/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Alioth Code Coverage Dashboard

This project is a lightweight, Coveralls-style code coverage dashboard. It is built using the [Hono](https://hono.dev) framework and runs on **Cloudflare Workers**. It can be configured to serve any GitHub repository via `wrangler.toml`.

To remain within edge execution limits and keep storage costs low, this app uses:
- **Cloudflare D1 (SQLite)**: To store lightweight metadata (commit SHA, branch, overall coverage %).
- **Cloudflare R2 (Blob Storage)**: To store parsed coverage mappings as JSON.
- **GitHub Raw API**: To dynamically fetch source code on demand, rather than storing massive source files in a database.

## Prerequisites

- Node.js (v18+)
- A Cloudflare account
- `wrangler` CLI installed globally or via `npx`

## Setup & Configuration

1. **Install dependencies:**
```bash
npm install
```

2. **Create the D1 Database:**
```bash
npx wrangler d1 create alioth-codecov-db
```
*Take note of the `database_id` returned by this command.*

3. **Update `wrangler.toml`:**
Open `wrangler.toml` and replace `REPLACE_WITH_YOUR_D1_DATABASE_ID` with the actual ID you just generated.

4. **Create the R2 Bucket:**
```bash
npx wrangler r2 bucket create alioth-codecov-reports
```

5. **Initialize the Database Schema:**
Run the schema against your production D1 database:
```bash
npx wrangler d1 execute alioth-codecov-db --remote --file=./schema.sql
```

## Local Development

To run the worker locally, you first need to initialize the local SQLite database simulation:

```bash
# Initialize local DB
npx wrangler d1 execute alioth-codecov-db --local --file=./schema.sql

# Start the development server
npm run dev
```

The app will be available at `http://localhost:8787`.

## Securing the API (Authentication)

To prevent unauthorized uploads to your dashboard, you should set a secret token. Both the worker and the upload script will use this to verify the payload.

1. **Generate a random token** (e.g., `openssl rand -hex 32`).
2. **Set the token in Cloudflare Secrets:**
```bash
npx wrangler secret put CODECOV_TOKEN
```
*(Paste your token when prompted)*
3. **Set the token for local development:** Create a `.dev.vars` file in the `codecov` directory:
```env
CODECOV_TOKEN=your_local_secret_token
```

## Deployment

Deploy the worker to your Cloudflare account:

```bash
npm run deploy
```

Once deployed, you will receive a `*.workers.dev` URL (or your custom domain) where the dashboard is hosted.

## Uploading Coverage Reports

A Node.js script (`upload.mjs`) is provided to parse `lcov.info` files and upload them to the worker.

This script extracts git metadata (commit SHA, branch) directly from the local git repository and converts the LCOV file into an optimized JSON payload before sending it to the API.

### Usage

```bash
# Export the URL of your deployed worker (or use localhost for local testing)
export CODECOV_URL="https://your-worker-url.workers.dev/api/upload"

# Export the authentication token you created
export CODECOV_TOKEN="your_secret_token"

# Run the upload script from the root of your repository
node tools/codecov/upload.mjs ./lcov.info
```

### CI/CD Integration (GitHub Actions)
In your GitHub Actions workflow, after running tests and generating an `lcov` report, you can use a unified step to automatically push coverage data to your dashboard for both regular commits and pull requests:

```yaml
- name: Upload Coverage
run: |
PR_ARGS=""
if [ "${{ github.event_name }}" = "pull_request" ]; then
PR_ARGS="--pr ${{ github.event.pull_request.number }} --pr-base ${{ github.event.pull_request.base.sha }}"
fi
node tools/codecov/upload.mjs ./lcov.info $PR_ARGS
env:
CODECOV_URL: ${{ vars.CODECOV_URL }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

## Shields.io Badge

You can embed a dynamic code coverage badge in your repository's `README.md` using Shields.io. The badge will automatically turn green (>=80%), yellow (>=60%), or red depending on the coverage of your `main` branch.

```md
![Coverage](https://img.shields.io/endpoint?url=https://your-worker-url.workers.dev/api/badge)
```

To fetch the badge for a specific branch, append `?branch=branch-name` to the endpoint URL:

```md
![Coverage](https://img.shields.io/endpoint?url=https://your-worker-url.workers.dev/api/badge?branch=feature/test)
```
Loading
Loading