Skip to content

Commit e8ec186

Browse files
gamemaker1yakov116fregante
authored
Meta: Verify features meta on CI (refined-github#4699)
Co-authored-by: yakov116 <16872793+yakov116@users.noreply.github.com> Co-authored-by: Federico Brigante <me@fregante.com>
1 parent 66e8ae1 commit e8ec186

4 files changed

Lines changed: 63 additions & 32 deletions

File tree

.github/workflows/features.yml

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,22 @@
1-
name: Feature
1+
name: Features
22

33
on:
44
pull_request:
5-
types:
6-
- opened
7-
- edited
8-
- synchronize # push
9-
path:
10-
- source/refined-github.ts
5+
branches:
6+
- '*'
7+
push:
8+
branches:
9+
- main
10+
- 'test/*'
1111

1212
jobs:
13-
New:
14-
outputs:
15-
name: ${{ steps.name.outputs.first_match }}
13+
Verify:
1614
runs-on: ubuntu-latest
17-
if: startsWith(github.event.pull_request.title, 'Add') && endsWith(github.event.pull_request.title, 'feature')
1815
steps:
1916
- uses: actions/checkout@v2
20-
- name: Find feature name
21-
id: name
22-
uses: AsasInnab/regex-action@v1
17+
- uses: actions/setup-node@v2
2318
with:
24-
regex_pattern: '(?<=Add `)[a-z-]+(?=` feature)'
25-
regex_flags: g
26-
search_string: ${{ github.event.pull_request.title }}
27-
28-
- name: Has `${{ steps.name.outputs.first_match }}.tsx` been created?
29-
uses: mudlabs/simple-diff@v1.2.0
30-
with:
31-
path: source/features/${{ steps.name.outputs.first_match }}.tsx
32-
33-
- name: Has `${{ steps.name.outputs.first_match }}` been imported?
34-
run: grep "import './features/${{ steps.name.outputs.first_match }}';" source/refined-github.ts -q
35-
36-
- name: Has `${{ steps.name.outputs.first_match }}` been documented?
37-
run: grep '"${{ steps.name.outputs.first_match }}"' readme.md -q
19+
node-version: 16
20+
cache: npm
21+
- run: npm ci
22+
- run: npm run test:features

build/readme-parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference types="../source/globals" />
2-
import path from 'node:path';
2+
33
import regexJoin from 'regex-join';
44
import {readFileSync} from 'node:fs';
55
import {parse as parseMarkdown} from 'markdown-wasm/dist/markdown.node.js';
@@ -38,7 +38,7 @@ function searchInHighlights(readmeContent: string, id: FeatureID): FeatureMeta |
3838
}
3939

4040
export function getFeaturesMeta(): FeatureMeta[] {
41-
const readmeContent = readFileSync(path.join(__dirname, '../readme.md'), 'utf-8');
41+
const readmeContent = readFileSync('readme.md', 'utf-8');
4242
const features = [];
4343
for (const id of getFeatures()) {
4444
if (!id.startsWith('rgh-')) {
@@ -53,7 +53,7 @@ export function getFeaturesMeta(): FeatureMeta[] {
5353
}
5454

5555
export function getFeatures(): FeatureID[] {
56-
const contents = readFileSync(path.join(__dirname, '../source/refined-github.ts'), 'utf-8');
56+
const contents = readFileSync('source/refined-github.ts', 'utf-8');
5757
return [...contents.matchAll(/^import '\.\/features\/([^.]+)';/gm)]
5858
.map(match => match[1] as FeatureID)
5959
.sort();

build/verify-features.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env -S TS_NODE_COMPILER_OPTIONS='{"module":"es2020"}' node --loader ts-node/esm
2+
3+
import {readdirSync} from 'node:fs';
4+
5+
import {getFeatures, getFeaturesMeta} from './readme-parser.js'; // Must import as `.js`
6+
7+
const featuresDirContents = readdirSync('source/features/');
8+
const importedFeatures = getFeatures();
9+
const featuresInReadme = getFeaturesMeta();
10+
11+
const errors: string[] = [];
12+
13+
for (const fileName of featuresDirContents) {
14+
if (fileName === 'index.tsx' || fileName.endsWith('.css')) {
15+
continue;
16+
}
17+
18+
if (!fileName.endsWith('.tsx')) {
19+
errors.push(`ERR: The \`/source/features\` folder should only contain .css and .tsx files. File \`${fileName}\` violates that rule`);
20+
continue;
21+
}
22+
23+
const featureId = fileName.replace('.tsx', '');
24+
if (!importedFeatures.includes(featureId as FeatureID)) {
25+
errors.push(`ERR: ${featureId} should be imported by \`/sources/refined-github.ts\``);
26+
}
27+
28+
if (fileName.startsWith('rgh-')) {
29+
continue;
30+
}
31+
32+
const featureMeta = featuresInReadme.find(feature => feature.id === featureId);
33+
if (!featureMeta) {
34+
errors.push(`ERR: The feature ${featureId} should be described in the readme`);
35+
continue;
36+
}
37+
38+
if (featureMeta.description.length < 20) {
39+
errors.push(`ERR: ${featureId} should be described better in the readme (at least 20 characters)`);
40+
}
41+
}
42+
43+
console.error(errors.join('\n'));
44+
45+
process.exitCode = errors.length;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"lint:js": "xo",
1313
"pack:safari": "xcodebuild -project 'safari/Refined GitHub.xcodeproj'",
1414
"start:safari": "open 'safari/build/Release/Refined GitHub.app'",
15-
"test": "run-p ava lint:* build:*",
15+
"test": "run-p ava lint:* build:* test:features",
16+
"test:features": "./build/verify-features.ts",
1617
"watch": "run-p watch:* --continue-on-error",
1718
"watch:typescript": "tsc --noEmit --watch --preserveWatchOutput",
1819
"watch:webpack": "webpack --mode=development --watch"

0 commit comments

Comments
 (0)