Skip to content

Commit

Permalink
Only require acknowledgments rebuild in gh lint action
Browse files Browse the repository at this point in the history
Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and ayumi-signal committed Mar 1, 2024
1 parent 840c988 commit 3f8206e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -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
Expand Down
33 changes: 27 additions & 6 deletions scripts/generate-acknowledgments.js
Expand Up @@ -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 = {},
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 3f8206e

Please sign in to comment.