Skip to content

Commit

Permalink
Run license cheks with test action
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Sep 23, 2024
1 parent 3c4f4be commit 2d06dd1
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 35 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
node-version: ${{ matrix.node }}
- run: npm install
- name: Run tests
run: npm test
run: |
npm run licenses
npm test
env:
EENGINE_REDIS: redis://127.0.0.1:6379/1
17 changes: 15 additions & 2 deletions lib/routes-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const psl = require('psl');
const { oauth2Apps, LEGACY_KEYS, OAUTH_PROVIDERS, oauth2ProviderData } = require('./oauth2-apps');
const { autodetectImapSettings } = require('./autodetect-imap-settings');
const getSecret = require('./get-secret');
const humanize = require('humanize');
const os = require('os');
const {
ADDRESS_STRATEGIES,
Expand Down Expand Up @@ -889,6 +888,20 @@ function applyRoutes(server, call) {
let hasAccounts = !!stats.accounts;
stats.connectedAccounts = (stats.connections.connected || 0) + (stats.connections.syncing || 0);

let defaultLocale = (await settings.get('locale')) || 'en';

let nrFormatter;

let nrFormatterOpts = {
style: 'decimal'
};

try {
nrFormatter = new Intl.NumberFormat(defaultLocale, nrFormatterOpts);
} catch (err) {
nrFormatter = new Intl.NumberFormat('en-US', nrFormatterOpts);
}

return h.view(
'dashboard',
{
Expand All @@ -907,7 +920,7 @@ function applyRoutes(server, call) {
color: typeof stats.redisPing !== 'number' ? 'warning' : stats.redisPing < ALLOWED_REDIS_LATENCY ? 'success' : 'danger',
icon: 'clock',
comment: 'How many milliseconds does it take to run a Redis command',
value: typeof stats.redisPing !== 'number' ? '\u2013' : humanize.numberFormat(stats.redisPing / 1000000, 3, '.', ' ')
value: typeof stats.redisPing !== 'number' ? '\u2013' : nrFormatter.format(stats.redisPing / 1000000)
}
},
{
Expand Down
19 changes: 19 additions & 0 deletions list-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const he = require('he');
const packageData = require('./package.json');
const satisfies = require('spdx-satisfies');

const ALLOWED_LICENSES = ['ISC', 'MIT', 'Apache-1.0+', 'CC-BY-3.0', 'BSD-2-Clause', 'BSD-3-Clause', '0BSD', 'CC0-1.0', 'MIT-0', 'MPL-2.0', 'Python-2.0'];

let chunks = [];
process.stdin.on('readable', () => {
Expand Down Expand Up @@ -40,6 +43,22 @@ process.stdin.on('end', () => {

console.log(`<td><a href="https://npmjs.com/package/${he.encode(packageName)}">${he.encode(packageName)}</a></td>`);

for (let license of [].concat(data.licenses || [])) {
license = license.replace(/MIT\*/, 'MIT');

let _satisfies;
try {
_satisfies = satisfies(license, `(${ALLOWED_LICENSES.join(' OR ')})`);
} catch (err) {
console.error(err);
}

if (!_satisfies) {
console.error(`Failed to verify license for ${packageName}. Found: "${license}"`);
process.exit(1);
}
}

[packageVersion, [].concat(data.licenses || []).join(', '), data.publisher, data.email]
.map(entry => entry || '')
.forEach(entry => {
Expand Down
35 changes: 19 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build-source": "rm -rf node_modules && npm install && rm -rf node_modules && npm install --omit=dev && ./update-info.sh",
"build-dist": "pkg --compress Brotli package.json && npm install && node winconf.js",
"build-dist-fast": "pkg --debug package.json && npm install && node winconf.js",
"licenses": "license-checker --excludePackages emailengine-app --json | node list-generate.js > static/licenses.html",
"licenses": "license-checker --excludePackages 'emailengine-app' --json | node list-generate.js > static/licenses.html",
"gettext": "find ./views -name \"*.hbs\" -print0 | xargs -0 xgettext-template -L Handlebars -o translations/messages.pot --force-po && jsxgettext lib/routes-ui.js workers/api.js lib/tools.js -j -o translations/messages.pot",
"prepare-docker": "echo \"EE_DOCKER_LEGACY=$EE_DOCKER_LEGACY\" >> system.env && cat system.env",
"update": "rm -rf node_modules package-lock.json && ncu -u && npm install && ./copy-static-files.sh && npm run licenses && npm run gettext",
Expand Down Expand Up @@ -53,13 +53,14 @@
"@postalsys/certs": "1.0.11",
"@postalsys/email-ai-tools": "1.8.11",
"@postalsys/email-text-tools": "2.1.11",
"@postalsys/gettext": "4.0.0",
"@postalsys/hecks": "3.0.0-fork.3",
"@postalsys/joi-messages": "1.0.2",
"@postalsys/templates": "2.0.0",
"ace-builds": "1.36.2",
"base32.js": "0.1.0",
"bull-arena": "4.4.2",
"bullmq": "5.13.1",
"bullmq": "5.13.2",
"compare-versions": "6.1.1",
"dotenv": "16.4.5",
"encoding-japanese": "2.2.0",
Expand All @@ -72,7 +73,6 @@
"hapi-swagger": "17.3.0",
"he": "1.2.0",
"html-to-text": "9.0.5",
"humanize": "0.0.9",
"ical.js": "1.5.0",
"iconv-lite": "0.6.3",
"imapflow": "1.0.164",
Expand All @@ -92,7 +92,6 @@
"msgpack5": "6.0.2",
"murmurhash": "2.0.1",
"nanoid": "3.3.4",
"@postalsys/gettext": "4.0.0",
"nodemailer": "6.9.15",
"pino": "9.4.0",
"prom-client": "15.1.3",
Expand Down Expand Up @@ -123,6 +122,7 @@
"jsxgettext": "0.11.0",
"pino-pretty": "11.2.2",
"resedit": "2.0.2",
"spdx-satisfies": "5.0.1",
"xgettext-template": "5.0.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion sbom.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions static/licenses.html
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ <h1>EmailEngine v2.46.3</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/bullmq">bullmq</a></td>
<td>5.13.1</td>
<td>5.13.2</td>
<td>MIT</td>
<td>Taskforce.sh Inc.</td>
<td></td>
Expand Down Expand Up @@ -3364,16 +3364,6 @@ <h1>EmailEngine v2.46.3</h1><p>EmailEngine includes code from the following soft
</td
</tr>
<tr>
<td><a href="https://npmjs.com/package/humanize">humanize</a></td>
<td>0.0.9</td>
<td>MIT*</td>
<td>Tai-Jin Lee</td>
<td>[email protected]</td>
<td>
<a href="https://github.com/taijinlee/humanize">github.com/taijinlee/humanize</a>
</td
</tr>
<tr>
<td><a href="https://npmjs.com/package/ical.js">ical.js</a></td>
<td>1.5.0</td>
<td>MPL-2.0</td>
Expand Down Expand Up @@ -5854,6 +5844,16 @@ <h1>EmailEngine v2.46.3</h1><p>EmailEngine includes code from the following soft
</td
</tr>
<tr>
<td><a href="https://npmjs.com/package/spdx-satisfies">spdx-satisfies</a></td>
<td>5.0.1</td>
<td>MIT</td>
<td>Kyle E. Mitchell</td>
<td>[email protected]</td>
<td>
<a href="https://github.com/kemitchell/spdx-satisfies.js">github.com/kemitchell/spdx-satisfies.js</a>
</td
</tr>
<tr>
<td><a href="https://npmjs.com/package/speakeasy">speakeasy</a></td>
<td>2.0.0</td>
<td>MIT</td>
Expand Down

0 comments on commit 2d06dd1

Please sign in to comment.