Skip to content

Commit

Permalink
build: be more robust if a changelog is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Feb 15, 2024
1 parent 7554a34 commit d5a740b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
7 changes: 7 additions & 0 deletions packages/lexicon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# lexicon

## 1.0.0

### Major Changes

First release of the lexicon
58 changes: 33 additions & 25 deletions scripts/slack-publish-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const getImplementationMessage = (cliVersion, changes) => {

changes.publishedPackages.forEach((pkg) => {
const changelog = extractChangelog(pkg.name, pkg.version);
if (changelog.length) {
if (changelog?.length) {
attachments[0].blocks.push({
type: 'section',
text: {
Expand All @@ -115,34 +115,42 @@ const getImplementationMessage = (cliVersion, changes) => {
// If the returned changelog is empty, don't bother listing the changes
const extractChangelog = (package, version) => {
const [_, name] = package.split('@openfn/');
const log = readFileSync(`packages/${name}/CHANGELOG.md`, 'utf8').split('\n');
let shouldParse = false;
let skipDeps = false;
const changes = [];
for (const line of log) {
if (skipDeps) {
if (line.startsWith(' -')) {
continue;
} else {
skipDeps = false;
try {
const log = readFileSync(`packages/${name}/CHANGELOG.md`, 'utf8').split(
'\n'
);
let shouldParse = false;
let skipDeps = false;
const changes = [];
for (const line of log) {
if (skipDeps) {
if (line.startsWith(' -')) {
continue;
} else {
skipDeps = false;
}
}
}

if (line.startsWith('- Updated dependencies')) {
// Ignore all the dependency stuff
skipDeps = true;
continue;
}
if (line === `## ${version}`) {
shouldParse = true;
} else if (shouldParse && line.startsWith('## ')) {
// This is the start of the next version, stop parsing
break;
} else if (shouldParse && line.length > 2 && !line.startsWith('#')) {
changes.push(line);
if (line.startsWith('- Updated dependencies')) {
// Ignore all the dependency stuff
skipDeps = true;
continue;
}
if (line === `## ${version}`) {
shouldParse = true;
} else if (shouldParse && line.startsWith('## ')) {
// This is the start of the next version, stop parsing
break;
} else if (shouldParse && line.length > 2 && !line.startsWith('#')) {
changes.push(line);
}
}
return changes.join('\n');
} catch (e) {
console.error(`Error reading changelog for ${package}:`);
console.error(e);
return [];
}
return changes.join('\n');
};

const file = readFileSync('pnpm-publish-summary.json');
Expand Down

0 comments on commit d5a740b

Please sign in to comment.