Only require acknowledgments rebuild in gh lint action

This commit is contained in:
ayumi-signal 2024-03-01 11:33:00 -08:00 committed by GitHub
parent e5e4c1aa3e
commit b379ec115d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 6 deletions

View File

@ -50,6 +50,12 @@ jobs:
- run: yarn lint
- run: yarn lint-deps
- run: yarn lint-license-comments
- name: Check acknowledgments file is up to date
run: yarn build:acknowledgments
env:
REQUIRE_SIGNAL_LIB_FILES: 1
- run: git diff --exit-code
- name: Update cached .eslintcache and tsconfig.tsbuildinfo

View File

@ -7,6 +7,11 @@ const { join } = require('path');
const pMap = require('p-map');
const prettier = require('prettier');
// During development, you might use local versions of dependencies which are missing
// acknowledgment files. In this case we'll skip rebuilding the acknowledgment files.
// Enable this flag to throw an error.
const REQUIRE_SIGNAL_LIB_FILES = Boolean(process.env.REQUIRE_SIGNAL_LIB_FILES);
const {
dependencies = {},
optionalDependencies = {},
@ -76,12 +81,28 @@ async function getMarkdownForSignalLib(dependencyName) {
'dist',
'acknowledgments.md'
);
const licenseBody = (await fs.promises.readFile(licenseFilePath, 'utf8'))
.replace(/^# Acknowledgments/, '')
.trim();
return [`# Acknowledgements for ${dependencyName}`, '', licenseBody].join(
'\n'
);
let licenseBody;
try {
licenseBody = await fs.promises.readFile(licenseFilePath, 'utf8');
} catch (err) {
if (err) {
if (err.code === 'ENOENT' && !REQUIRE_SIGNAL_LIB_FILES) {
console.warn(
`Missing acknowledgments file for ${dependencyName}. Skipping generation of acknowledgments.`
);
process.exit(0);
}
throw err;
}
}
return [
`# Acknowledgements for ${dependencyName}`,
'',
licenseBody.replace(/^# Acknowledgments/, '').trim(),
].join('\n');
}
async function main() {