Skip to content

Commit

Permalink
Detected outdated README on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Apr 8, 2022
1 parent b55196b commit 18a9f71
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 135 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
pull_request:
branches:
- main
schedule:
- cron: 0 0 * * *

jobs:
build:
Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,12 @@
| `8.4.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 |
| `8.4.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 |
| `8.2.2` `8.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 |
| `8.2.1` |||||||
| `8.0.2` `8.0` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 |
| `8.0.1` |||||||
| `7.10.3` `7.10` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 |
| `7.10.2` |||||||
| `7.10.1` |||||||
| `7.8.4` `7.8` | 🟢 ||||||
| `7.8.3` |||||||
| `7.8.2` |||||||
| `7.8.1` |||||||
| `7.6.3` `7.6` | 🟢 ||||||
| `7.6.2` |||||||
| `7.6.1` |||||||
| `7.4.2` `7.4` | 🟢 | 🟢 |||||
| `7.4.1` | 🟢 ||||||
| `7.2.2` `7.2` | 🟢 | 🟢 |||||
| `7.2.1` |||||||
| `7.0.4` `7.0` | 🟢 | 🟢 |||||
| `7.0.3` |||||||
| `7.0.2` |||||||
| `7.0.1` | 🟢 | 🟢 |||||
45 changes: 26 additions & 19 deletions generate/readme.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
import * as fs from 'fs';
import * as resolve from '../src/resolve';
import { resolveVersion } from '../src/resolve';
import { allSet, all, versions } from './versions';

type Environment = keyof typeof versions;
const environments: Environment[] = Object.keys(versions) as Environment[];
import { versionMap } from './selftest';

const code = (input: string) => '`' + input + '`';
const majorVersion = (version: string) => version.split('.').splice(0, 2).join('.');
const unique = (xs: string[]) => [...new Set(xs)];

const supports = (version: string) => (name: Environment) => {
return versions[name].includes(version) ? 'oo' : 'xx';
};
async function main() {
const versions = await versionMap();

const majorVersion = (version: string) => version.split('.').splice(0, 2).join('.');
type Environment = keyof typeof versions;
const environments: Environment[] = Object.keys(versions) as Environment[];

const unique = (xs: string[]) => [...new Set(xs)];
const supports = (version: string) => (name: Environment) => {
return versions[name].has(version) ? 'oo' : 'xx';
};

const latestMajorVersions = Object.fromEntries(
unique(all.map(majorVersion)).map(major => [resolveVersion(major, allSet), major])
);
const allSet = new Set(Object.values(versions).map(x => Array.from(x)).flat());
const all = [...allSet].sort(resolve.compare);

function codeVersion(version: string): string {
const major = latestMajorVersions[version];
return major ? `${code(version)} ${code(major)}` : code(version);
}
const latestMajorVersions = Object.fromEntries(
unique(all.map(majorVersion)).map(major => [resolveVersion(major, allSet), major])
);

function codeVersion(version: string): string {
const major = latestMajorVersions[version];
return major ? `${code(version)} ${code(major)}` : code(version);
}

async function main() {
const { markdownTable } = await import('markdown-table');
const header = [''].concat(environments.map(code));
const align = ['l'].concat(environments.map(_ => 'c'));
const row = (version: string) => [codeVersion(version)].concat(environments.map(supports(version)));
const rows = all.reverse().map(row);
const table = [header].concat(rows);
console.log(markdownTable(table, { align }).replace(/oo/g, '🟢').replace(/xx/g, '❌'));
fs.writeFileSync('README.md', markdownTable(table, { align }).replace(/oo/g, '🟢').replace(/xx/g, '❌') + '\n');
}

main();
if (require.main === module) {
main();
}
34 changes: 28 additions & 6 deletions generate/selftest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import * as fs from 'fs';
import * as YAML from 'yaml';
import { versions } from './versions';
import * as resolve from '../src/resolve';

for (const [name, supported] of Object.entries(versions)) {
const file = `.github/workflows/selftest.${name}.yml`;
const yaml = YAML.parse(fs.readFileSync(file, 'utf8'));
yaml.jobs.build.strategy.matrix.ghc = supported;
fs.writeFileSync(file, YAML.stringify(yaml));
import { ppa } from '../src/apt';
import { list } from '../src/ghcup';

export async function versionMap() {
const ghcup = await list();
return {
'ubuntu-18.04': new Set([...ppa.ubuntu18, ...ghcup]),
'ubuntu-20.04': new Set([...ppa.ubuntu20, ...ghcup]),
'macos-10.15': ghcup,
'macos-11': ghcup,
'windows-2019': ghcup,
'windows-2022': ghcup,
};
}

async function main() {
const versions = await versionMap();
for (const [name, supported] of Object.entries(versions)) {
const file = `.github/workflows/selftest.${name}.yml`;
const yaml = YAML.parse(fs.readFileSync(file, 'utf8'));
yaml.jobs.build.strategy.matrix.ghc = [...supported].sort(resolve.compare);
fs.writeFileSync(file, YAML.stringify(yaml));
}
}

if (require.main === module) {
main();
}
18 changes: 0 additions & 18 deletions generate/versions.ts

This file was deleted.

48 changes: 0 additions & 48 deletions generate/versions/all.json

This file was deleted.

29 changes: 0 additions & 29 deletions generate/versions/ghcup.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"main": "build/main.js",
"scripts": {
"build": "tsc && ncc build",
"build": "tsc && ncc build && ts-node generate/readme.ts && ts-node generate/selftest.ts",
"test": "jest",
"watch": "jest --config jest.config.fast.ts --watch"
},
Expand Down
23 changes: 21 additions & 2 deletions src/resolve.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import { allSet } from '../generate/versions';

import { compare, resolveVersion, resolve } from '../src/resolve';

const context = describe;

const allSet = new Set([
'7.6.1',
'7.6.2',
'7.6.3',
'7.8.1',
'7.8.2',
'7.8.3',
'7.8.4',
'7.10.1',
'7.10.2',
'7.10.3',
'8.0.1',
'8.0.2',
'8.2.1',
'8.2.2',
'8.4.1',
'8.4.2',
'8.4.3',
'8.4.4',
]);

describe('compare', () => {
it('compares versions', () => {
expect(compare('1.0', '1.2')).toBe(-1);
Expand Down

0 comments on commit 18a9f71

Please sign in to comment.