diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 03ff60d..c476267 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,8 @@ on: pull_request: branches: - main + schedule: + - cron: 0 0 * * * jobs: build: diff --git a/README.md b/README.md index 193fbb2..e02f868 100644 --- a/README.md +++ b/README.md @@ -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` | 🟢 | 🟢 | ❌ | ❌ | ❌ | ❌ | diff --git a/generate/readme.ts b/generate/readme.ts index 454704f..667edcf 100644 --- a/generate/readme.ts +++ b/generate/readme.ts @@ -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(); +} diff --git a/generate/selftest.ts b/generate/selftest.ts index 229445b..d97462e 100644 --- a/generate/selftest.ts +++ b/generate/selftest.ts @@ -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(); } diff --git a/generate/versions.ts b/generate/versions.ts deleted file mode 100644 index 7a2a9e0..0000000 --- a/generate/versions.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as fs from 'fs'; - -import { ppa } from '../src/apt'; - -export const all: string[] = JSON.parse(fs.readFileSync('generate/versions/all.json', 'utf8')); -export const allSet = new Set(all); - -const ghcup: string[] = JSON.parse(fs.readFileSync('generate/versions/ghcup.json', 'utf8')); -const ghcupSet: Set = new Set(ghcup); - -export const versions = { - 'ubuntu-18.04': all.filter(version => ghcupSet.has(version) || ppa.ubuntu18.has(version)), - 'ubuntu-20.04': all.filter(version => ghcupSet.has(version) || ppa.ubuntu20.has(version)), - 'macos-10.15': ghcup, - 'macos-11': ghcup, - 'windows-2019': ghcup, - 'windows-2022': ghcup, -}; diff --git a/generate/versions/all.json b/generate/versions/all.json deleted file mode 100644 index faacc9f..0000000 --- a/generate/versions/all.json +++ /dev/null @@ -1,48 +0,0 @@ -[ - "7.0.1", - "7.0.2", - "7.0.3", - "7.0.4", - "7.2.1", - "7.2.2", - "7.4.1", - "7.4.2", - "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", - "8.6.1", - "8.6.2", - "8.6.3", - "8.6.4", - "8.6.5", - "8.8.1", - "8.8.2", - "8.8.3", - "8.8.4", - "8.10.1", - "8.10.2", - "8.10.3", - "8.10.4", - "8.10.5", - "8.10.6", - "8.10.7", - "9.0.1", - "9.0.2", - "9.2.1", - "9.2.2" -] diff --git a/generate/versions/ghcup.json b/generate/versions/ghcup.json deleted file mode 100644 index 15d367d..0000000 --- a/generate/versions/ghcup.json +++ /dev/null @@ -1,29 +0,0 @@ -[ - "7.10.3", - "8.0.2", - "8.2.2", - "8.4.1", - "8.4.2", - "8.4.3", - "8.4.4", - "8.6.1", - "8.6.2", - "8.6.3", - "8.6.4", - "8.6.5", - "8.8.1", - "8.8.2", - "8.8.3", - "8.8.4", - "8.10.1", - "8.10.2", - "8.10.3", - "8.10.4", - "8.10.5", - "8.10.6", - "8.10.7", - "9.0.1", - "9.0.2", - "9.2.1", - "9.2.2" -] diff --git a/package.json b/package.json index 261c362..59fc1b9 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/resolve.spec.ts b/src/resolve.spec.ts index 6887b0c..e79cbce 100644 --- a/src/resolve.spec.ts +++ b/src/resolve.spec.ts @@ -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);