Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
fix: Added graceful handling of malformed GameMaker URLs and missing …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
adam-coster committed Mar 6, 2023
1 parent 4cf4ea6 commit c6f5645
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions packages/releases/src/feeds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Pathy } from '@bscotch/pathy';
import { assert } from '@bscotch/utility/browser';
import { z } from 'zod';
import { defaultNotesCachePath } from './constants.js';
import { downloadRssFeed, findPairedRuntime } from './feeds.lib.js';
Expand All @@ -23,14 +22,15 @@ export async function computeReleasesSummaryWithNotes(
releases ||= await computeReleasesSummary();
const notes = await listReleaseNotes(releases, cache);
const withNotes: GameMakerReleaseWithNotes[] = [];
const emptyChanges = {
changes: {
since: null,
groups: [],
},
};
for (const release of releases) {
const ideNotes = notes[release.ide.notesUrl];
assert(ideNotes, `No notes found for IDE release ${release.ide.version}`);
const runtimeNotes = notes[release.runtime.notesUrl];
assert(
runtimeNotes,
`No notes found for IDE release ${release.runtime.version}`,
);
const ideNotes = notes[release.ide.notesUrl] || emptyChanges;
const runtimeNotes = notes[release.runtime.notesUrl] || emptyChanges;
const ide = { ...release.ide, notes: ideNotes.changes };
const runtime = { ...release.runtime, notes: runtimeNotes.changes };
withNotes.push({
Expand Down
6 changes: 4 additions & 2 deletions packages/releases/src/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export async function listReleaseNotes(
const cacheData = await cachePath.read({ fallback: {} });
for (const release of releases) {
for (const type of ['ide', 'runtime'] as const) {
const url = release[type].notesUrl;
let url = release[type].notesUrl;
// URL can be malformed
url = url.replace(/^(.+\.cloudfront\.net)(release.*)$/, '$1/$2');
if (cacheData[url]) {
if (!cacheData[url].type) {
cacheData[url].type = type;
Expand Down Expand Up @@ -92,7 +94,7 @@ function cleanNotes(cachedNotes: RawReleaseNotesCache) {
const notesByUrl = cleanedNotes.reduce((acc, note) => {
acc[note.url] = note;
return acc;
}, {} as Record<string, typeof cleanedNotes[0]>);
}, {} as Record<string, (typeof cleanedNotes)[0]>);
return notesByUrl;
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/update-releases-summary.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { pathy } from '@bscotch/pathy';
import { listReleasesWithNotes } from '../packages/releases/dist/index.js';
import { computeReleasesSummaryWithNotes } from '../packages/releases/dist/index.js';
import fs from 'fs';

const notesCache = pathy('packages/releases/release-notes-cache.json');
const summaryPath = pathy('packages/releases/releases-summary.json');
const releases = await listReleasesWithNotes(undefined, notesCache);
const releases = await computeReleasesSummaryWithNotes(undefined, notesCache);
await summaryPath.write(releases);
// Write to the file that GitHub Workflow uses to store env vars
fs.appendFileSync(
Expand Down

0 comments on commit c6f5645

Please sign in to comment.