Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
Expand Down
140 changes: 140 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: Test Coverage

on:
push:
pull_request:
workflow_dispatch:

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

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install
- name: Run tests with coverage
id: coverage
run: npm run coverage
continue-on-error: true
- name: Comment coverage report on pull requests
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('node:fs');
const path = require('node:path');

const marker = '<!-- pricefeed-coverage-report -->';
const thresholds = {
lines: 72,
statements: 72,
functions: 89,
branches: 90,
};
const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
const summaryPath = path.join(workspace, 'coverage', 'coverage-summary.json');

if (!fs.existsSync(summaryPath)) {
core.warning(`Coverage summary not found at ${summaryPath}; skipping PR coverage comment.`);
return;
}

const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8'));
const total = summary.total;

function status(pct, threshold) {
return pct >= threshold ? '\u{1F7E2}' : '\u{1F534}';
}

function percent(value) {
return `${Number(value || 0).toFixed(2)}%`;
}

function metricRow(label, key) {
const metric = total[key] || { pct: 0, covered: 0, total: 0 };
return `| ${status(metric.pct, thresholds[key])} | ${label} | ${percent(metric.pct)} | ${thresholds[key]}% | ${metric.covered} / ${metric.total} |`;
}

function fileName(file) {
const relative = path.isAbsolute(file) ? path.relative(workspace, file) : file;
return relative.replaceAll(path.sep, '/');
}

const categories = [
['Lines', 'lines'],
['Statements', 'statements'],
['Functions', 'functions'],
['Branches', 'branches'],
];

const fileRows = Object.entries(summary)
.filter(([file]) => file !== 'total')
.sort(([left], [right]) => fileName(left).localeCompare(fileName(right)))
.map(([file, metrics]) => (
`| \`${fileName(file)}\` | ${percent(metrics.lines?.pct)} | ${percent(metrics.statements?.pct)} | ${percent(metrics.functions?.pct)} | ${percent(metrics.branches?.pct)} |`
));

const serverUrl = process.env.GITHUB_SERVER_URL || 'https://github.com';
const { owner, repo } = context.repo;
const runUrl = `${serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`;
const commitSha = context.payload.pull_request.head.sha;
const headRepoUrl = context.payload.pull_request.head.repo.html_url || `${serverUrl}/${owner}/${repo}`;
const commitUrl = `${headRepoUrl}/commit/${commitSha}`;

const body = [
marker,
'## Coverage Report',
'',
'| Status | Category | Percentage | Threshold | Covered / Total |',
'| --- | --- | ---: | ---: | ---: |',
...categories.map(([label, key]) => metricRow(label, key)),
'',
'<details>',
'<summary>File Coverage</summary>',
'',
'| File | Lines | Statements | Functions | Branches |',
'| --- | ---: | ---: | ---: | ---: |',
...fileRows,
'',
'</details>',
'',
`Generated in workflow [#${context.runNumber}](${runUrl}) for commit [${commitSha.slice(0, 7)}](${commitUrl}) by GitHub Actions.`,
].join('\n');

const issue_number = context.issue.number;
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
});

const existingComment = comments.find((comment) => (
comment.user.type === 'Bot' && comment.body?.includes(marker)
));

if (existingComment) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}
- name: Enforce coverage threshold
if: steps.coverage.outcome == 'failure'
run: exit 1
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Steem Witness Price Feed Publishing Tool

[![CI](https://github.com/DoctorLai/pricefeed/actions/workflows/ci.yml/badge.svg)](https://github.com/DoctorLai/pricefeed/actions/workflows/ci.yml)
[![Test Coverage](https://github.com/DoctorLai/pricefeed/actions/workflows/coverage.yml/badge.svg)](https://github.com/DoctorLai/pricefeed/actions/workflows/coverage.yml)
[![Node.js](https://img.shields.io/badge/node-%3E%3D18-43853d?logo=node.js&logoColor=white)](https://nodejs.org/)
[![Docker Hub](https://img.shields.io/docker/pulls/justyy/pricefeed?logo=docker&logoColor=white)](https://hub.docker.com/r/justyy/pricefeed)
[![Docker Pulls](https://img.shields.io/docker/pulls/justyy/pricefeed?logo=docker&logoColor=white)](https://hub.docker.com/r/justyy/pricefeed)
[![Docker Image Size](https://img.shields.io/docker/image-size/justyy/pricefeed/latest?logo=docker&logoColor=white)](https://hub.docker.com/r/justyy/pricefeed/tags)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

![image](https://user-images.githubusercontent.com/1764434/173547905-6366f5eb-22dc-4327-bbda-6a4cc4cd3b96.png)

Here is the AI-generated [Wiki](https://deepwiki.com/DoctorLai/pricefeed) for this project.

Publishes a STEEM price feed for your witness account. Prices are pulled from
multiple exchanges, validated, averaged, and broadcast to the Steem blockchain
on a configurable interval, with automatic RPC-node failover.
Expand Down Expand Up @@ -64,14 +68,15 @@ test/ node:test unit tests and fixtures

## Available scripts

| Script | Description |
| -------------------- | --------------------------------------------------- |
| `npm start` | Run the price feed. |
| `npm test` | Run the unit test suite (`node --test`). |
| `npm run lint` | Syntax-check every source and test file. |
| `npm run format` | Check formatting with Prettier. |
| `npm run format:fix` | Apply Prettier formatting. |
| `npm run ci` | Run lint, tests, and the format check (used by CI). |
| Script | Description |
| -------------------- | ----------------------------------------------- |
| `npm start` | Run the price feed. |
| `npm test` | Run the unit test suite (`node --test`). |
| `npm run coverage` | Run tests with coverage reports and thresholds. |
| `npm run lint` | Syntax-check every source and test file. |
| `npm run format` | Check formatting with Prettier. |
| `npm run format:fix` | Apply Prettier formatting. |
| `npm run ci` | Run lint, coverage, and the format check. |

## Running in production

Expand Down
Loading
Loading