Skip to content

Commit

Permalink
Always post GitHub issue comments in order
Browse files Browse the repository at this point in the history
We always want JavaScript and Stylesheets first
  • Loading branch information
colinrotherham committed Dec 1, 2023
1 parent 2e803eb commit ed74d5c
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions .github/workflows/scripts/comments.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile } from 'node:fs/promises'
import { join } from 'path'
import { basename, join } from 'path'

import { getFileSizes } from '@govuk-frontend/lib/files'
import { getStats, modulePaths } from '@govuk-frontend/stats'
Expand All @@ -12,16 +12,28 @@ import { getStats, modulePaths } from '@govuk-frontend/stats'
* @param {DiffComment[]} diffs
*/
export async function commentDiffs(githubActionContext, issueNumber, diffs) {
// Run the comments in parallel to avoid that an early one failing prevents the others
// and use `allSettled` to avoid the promise rejecting on the first failure but wait
// for everything to complete
const results = await Promise.allSettled(
diffs.map((diff) => commentDiff(githubActionContext, issueNumber, diff))
)
const errors = []

// Run comments in order, but prevent errors stopping other comments
for (const diff of diffs) {
try {
await commentDiff(githubActionContext, issueNumber, diff)
} catch (error) {
const filename = basename(diff.path)

// Defer errors until all comments are attempted
errors.push(
new Error(`Failed to post GitHub comment for ${filename}`, {
cause: error
})
)
}
}

if (results.some((result) => result.status === 'rejected')) {
throw new Error('Posting diff comment failed', {
cause: results
// Throw on any deferred errors above
if (errors.length) {
throw new Error('Failed to post GitHub comments', {
cause: errors
})
}
}
Expand Down

0 comments on commit ed74d5c

Please sign in to comment.