Skip to content

Commit

Permalink
sort files before diff
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Dec 13, 2024
1 parent c8f968f commit 2679852
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions .github/workflows/utilities/diffFiles.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,45 @@ module.exports = async ({folder, globString, outputFile}, originPath) => {
// create output file
shell.touch(outputFile)
// create diffs
const diffs = files.map(file => {
// get filename
const regexRunnerPath = new RegExp('^[a-z\/]+\/dist', 'g')
const filename = file.replaceAll(regexRunnerPath,'')
// if file is new
if (!fs.existsSync(file.replace(folder, `${originPath}/` + folder))) {
console.info('⚠️ File is new: ' + file + '\n')
return {
title: file.replaceAll('dist/', ''),
body: ''
const diffs = files
.map(file => {
// get filename
const regexRunnerPath = new RegExp('^[a-z/]+/dist', 'g')
const filename = file.replaceAll(regexRunnerPath, '')
// if file is new
if (!fs.existsSync(file.replace(folder, `${originPath}/${folder}`))) {
console.info(`⚠️ File is new: ${file}\n`)
return {
title: file.replaceAll('dist/', ''),
body: '',
}
}
}
// run diff & store in file
const diff = shell.exec(`diff -u ${file.replace(folder, `${originPath}/` + folder)} ${file}`)
// run diff & store in file
const diff = shell.exec(`diff -u <(sort ${file.replace(folder, `${originPath}/${folder}`)}) <(sort ${file})`)

console.log(`Checking diff for ${filename}...`)

console.log('Checking diff for ' + filename + '...')
if (diff.stderr) {
console.error(diff.stderr)
core.setFailed(diff.stderr)
}

if (diff.stderr) {
console.error(diff.stderr)
core.setFailed(diff.stderr)
}

if (diff.stdout === '') {
console.log('No diff for ' + filename + '\n')
} else {
console.log(diff.stdout + '\n')
}

return {
title: filename,
body: diff.stdout || ''
}
})
// filter files with no diffs
.filter(item => {
return item.body !== ''
})
if (diff.stdout === '') {
console.log(`No diff for ${filename}\n`)
} else {
console.log(`${diff.stdout}\n`)
}

return {
title: filename,
body: diff.stdout || '',
}
})
// filter files with no diffs
.filter(item => {
return item.body !== ''
})

// store diffs in file
fs.writeFileSync(outputFile, JSON.stringify(diffs, null, ' '))
}
}

0 comments on commit 2679852

Please sign in to comment.