forked from lite-xl/lite-xl-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CI and script to reorganize README
- Loading branch information
1 parent
0570164
commit 7bc11a2
Showing
5 changed files
with
2,046 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Reorganize README | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
|
||
jobs: | ||
reorganize: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14 | ||
- name: run the script | ||
run: | | ||
cd scripts | ||
npm install | ||
npm run main -- "https://github.com/${{ github.repository }}/blob/${GITHUB_REF##*/}/" ../README.md ../README.md | ||
- name: create PR | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
commit-message: Reorganize README.md | ||
branch: reorganize-ci | ||
add-paths: README.md | ||
delete-branch: false | ||
title: '[CI] Reorganize README.md' | ||
body: | | ||
This is a CI that makes sure entries are in alphabetical order and no links are invalid. | ||
Please check the [CI run][1] for logs. | ||
[1]: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { readFile, writeFile } from 'fs/promises' | ||
|
||
import centra from 'centra' | ||
import pLimit from 'p-limit' | ||
import { remark } from 'remark' | ||
import remarkGfm from 'remark-gfm' | ||
import { select, selectAll } from 'unist-util-select' | ||
|
||
const baseurl = process.argv[2] | ||
const inputFile = process.argv[3] | ||
const outputFile = process.argv[4] | ||
|
||
const selector = 'tableCell:first-child inlineCode' | ||
const sortEntries = async tree => { | ||
const rows = select('table', tree) | ||
const header = rows.children.shift() | ||
|
||
rows.children.sort((first, second) => | ||
select(selector, first).value | ||
.localeCompare(select(selector, second).value)) | ||
|
||
rows.children.unshift(header) | ||
return tree | ||
} | ||
|
||
const makeUrl = link => link.url.startsWith('http') ? link.url : baseurl + link.url | ||
|
||
const get404s = async tree => { | ||
const rows = select('table', tree) | ||
const links = selectAll('tableCell:first-child link', rows) | ||
.map(makeUrl) | ||
|
||
|
||
const limit = pLimit(5) | ||
const reqs = links | ||
.map(url => | ||
limit(() => centra(url, 'HEAD') | ||
.send() | ||
.then(res => [url, res.statusCode]) | ||
.catch(() => [url, undefined]))) | ||
|
||
const status = await Promise.all(reqs) | ||
const good = new Set(status.filter(([_, s]) => typeof s === 'number' && s < 400).map(([url]) => url)) | ||
|
||
if (good.size !== status.length) { | ||
console.log(`Found ${status.length - good.size} broken URLs`) | ||
status | ||
.filter(([url]) => !good.has(url)) | ||
.forEach(([url, status]) => console.log(`${url} : ${typeof status === 'number' ? status : 'failed'}`)) | ||
} | ||
|
||
// filter the table | ||
rows.children = rows.children | ||
.filter(row => { | ||
const link = select('tableCell:first-child link', row) | ||
return link ? good.has(makeUrl(link)) : true | ||
}) | ||
|
||
|
||
return tree | ||
} | ||
|
||
const main = async () => { | ||
const file = await readFile(inputFile, { encoding: 'utf-8' }) | ||
const output = await remark() | ||
.use(remarkGfm) | ||
.use(() => get404s) | ||
.use(() => sortEntries) | ||
.process(file) | ||
|
||
await writeFile(outputFile, String(output)) | ||
} | ||
|
||
main() |
Oops, something went wrong.