Skip to content

Commit

Permalink
build: add lint workflow (#17)
Browse files Browse the repository at this point in the history
* build: add lint workflow

* chore: run prettier

* chore: don't lint third-party code
  • Loading branch information
dsanders11 authored Jun 12, 2023
1 parent 4cee1cc commit 97b2c39
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 33 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # tag: v3.5.3
- name: Setup Node.js
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # tag: v3.6.0
with:
node-version: 18.x
- name: Lint
run: |
yarn
yarn lint
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/static/css/prismjs/**
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"scripts": {
"watch": "nodemon --watch src --ext js,css,handlebars --exec \"npm run start\"",
"start": "node src/index.js",
"lint": "prettier --check \"src/**/*.js\" \"src/**/*.css\"",
"prettier:write": "prettier --write \"src/**/*.js\" \"src/**/*.css\"",
"postinstall": "cp node_modules/prismjs/themes/*.css src/static/css/prismjs"
}
Expand Down
5 changes: 2 additions & 3 deletions src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const ExpiryMap = require('expiry-map');
const pMemoize = require('p-memoize');
const semver = require('semver');


let octokit = null;
const getOctokit = async () => {
if (octokit) return octokit;
Expand Down Expand Up @@ -146,8 +145,8 @@ const getTSDefs = pMemoize(
{
cache: new ExpiryMap(60 * 60 * 24 * 1000),
cacheKey: (version) => `ts/${version}`,
}
)
},
);

module.exports = {
getGitHubRelease,
Expand Down
59 changes: 31 additions & 28 deletions src/routes/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ Handlebars.registerHelper('markdownMergeHeaders', function (contentArr) {
const groupName = headers[i];
const groupContent = headers[i + 1];
groups[groupName] = groups[groupName] || '';
groups[groupName] += `<div class="notes-version-group ${hasPrerelease ? 'maybe-prerelease' : ''
}"><div>${version}</div>\n\n${groupContent.trim()}\n\n</div>\n`;
groups[groupName] += `<div class="notes-version-group ${
hasPrerelease ? 'maybe-prerelease' : ''
}"><div>${version}</div>\n\n${groupContent.trim()}\n\n</div>\n`;
}
}
let generatedNotes = '# Combined Release Notes\n\n';
Expand All @@ -63,9 +64,7 @@ async function getValidVersionRange(startVersion, endVersion, res) {
const parsedStart = semver.parse(startVersion);
const parsedEnd = semver.parse(endVersion);
if (!parsedStart || !parsedEnd || parsedStart.major !== parsedEnd.major) {
res.end(
'Sorry you can only compare Electron versions in the same major line at the moment',
);
res.end('Sorry you can only compare Electron versions in the same major line at the moment');
return [allReleases, null];
}

Expand All @@ -92,11 +91,14 @@ async function getValidVersionRange(startVersion, endVersion, res) {
return [allReleases, null];
}

return [allReleases, allReleases.filter(
(r) =>
semver.parse(r.version).compare(startVersion) > 0 &&
semver.parse(r.version).compare(endVersion) <= 0,
)];
return [
allReleases,
allReleases.filter(
(r) =>
semver.parse(r.version).compare(startVersion) > 0 &&
semver.parse(r.version).compare(endVersion) <= 0,
),
];
}

async function handleComparisonRequest(startVersion, endVersion, res) {
Expand All @@ -112,7 +114,8 @@ async function handleComparisonRequest(startVersion, endVersion, res) {
if (parsed.prerelease.length) {
notes = notes.split(`@${r.tag_name.substr(1)}\`.`)[1];
}
notes = '# Release Notes\n' + notes.replace(/# Release Notes for [^\r\n]+(?:(?:\n)|(?:\r\n))/i, '');
notes =
'# Release Notes\n' + notes.replace(/# Release Notes for [^\r\n]+(?:(?:\n)|(?:\r\n))/i, '');
return [notes, r.tag_name];
});

Expand All @@ -136,15 +139,9 @@ async function handleTypescriptComparisonRequest(startVersion, endVersion, res)

const [startTypes, endTypes] = await Promise.all([
getTSDefs(startVersion),
getTSDefs(endVersion)
getTSDefs(endVersion),
]);
const tsDiff = Diff.createPatch(
'electron.d.ts',
startTypes,
endTypes,
startVersion,
endVersion,
);
const tsDiff = Diff.createPatch('electron.d.ts', startTypes, endTypes, startVersion, endVersion);
const diff = Prism.highlight(tsDiff, Prism.languages.javascript, 'typescript');

res.render('ts-diff', {
Expand Down Expand Up @@ -172,13 +169,10 @@ router.get(
}),
);

router.get(
'/compare/:comparisonRange',
(req, res) => {
const [startVersion, endVersion] = req.params.comparisonRange.split('...');
res.redirect(`/release/compare/${startVersion}/${endVersion}`);
},
);
router.get('/compare/:comparisonRange', (req, res) => {
const [startVersion, endVersion] = req.params.comparisonRange.split('...');
res.redirect(`/release/compare/${startVersion}/${endVersion}`);
});

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
Expand All @@ -201,7 +195,9 @@ router.get(
if (parsed.prerelease.length) {
releaseNotes = releaseNotes.split(new RegExp(`@${escapeRegExp(version.substr(1))}\`?.`))[1];
}
releaseNotes = '# Release Notes\n' + releaseNotes.replace(/# Release Notes for [^\r\n]+(?:(?:\n)|(?:\r\n))/i, '');
releaseNotes =
'# Release Notes\n' +
releaseNotes.replace(/# Release Notes for [^\r\n]+(?:(?:\n)|(?:\r\n))/i, '');

const lastPreRelease = allReleases.find(
(r) =>
Expand Down Expand Up @@ -234,7 +230,14 @@ router.get(
prerelease: parsed.prerelease[0] || '',
css: 'release',
compareTarget: version,
compareList: allReleases.filter(r => r.version !== version.substr(1) && semver.parse(r.version).prerelease[0] !== 'nightly' && parsed.major === semver.parse(r.version).major).map(r => r.version),
compareList: allReleases
.filter(
(r) =>
r.version !== version.substr(1) &&
semver.parse(r.version).prerelease[0] !== 'nightly' &&
parsed.major === semver.parse(r.version).major,
)
.map((r) => r.version),
});
}),
);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ router.get(
prev: paginate.href(req)(true),
next: paginate.href(req)(false),
pages: paginate.getArrayPages(req)(5, pageCount, req.query.page),
first: paginate.href(req)(false, {page: 1}),
last: paginate.href(req)(false, {page: pageCount}),
first: paginate.href(req)(false, { page: 1 }),
last: paginate.href(req)(false, { page: pageCount }),
});
}),
);
Expand Down

0 comments on commit 97b2c39

Please sign in to comment.