diff --git a/.github/workflows/diff-design-tokens.yml b/.github/workflows/diff-design-tokens.yml index 2d5fd1528..6768dc7e6 100644 --- a/.github/workflows/diff-design-tokens.yml +++ b/.github/workflows/diff-design-tokens.yml @@ -88,40 +88,32 @@ jobs: // get config const diffConfig = ${{ needs.setup.outputs.diffs }} - const output = [] - - // create sections + // create diff for each config for (const config of diffConfig) { - await diffFiles(config.folder, config.globString, config.outputFile) - // read diff file - const diff = JSON.parse(fs.readFileSync(config.outputFile, 'utf8')) - // create sections - const sections = [] - for (const {title, body} of diff) { - sections.push({ - title, - body - }) - } - output.push({ - file: config.outputFile, - title: config.title, - sections - }) + await diffFiles(config, 'base') } - // set output - core.setOutput('diffFilePath', output); - - name: Write summary uses: actions/github-script@v7 with: script: | + const fs = require('fs') const addSummary = require('./.github/workflows/utilities/addSummary.cjs') - const diffFileArray = ${{ steps.diff-files.outputs.diffFilePath }} + const diffConfig = ${{ needs.setup.outputs.diffs }} + + const output = [] + // read diff files + for (const config of diffConfig) { + const diff = JSON.parse(fs.readFileSync(config.outputFile, 'utf8')) + // add to output + output.push({ + title: config.title, + sections: diff + }) + } // add summary - addSummary(diffFileArray, true) + addSummary(output, true) - name: Comment on pr if: github.event_name == 'pull_request' @@ -131,12 +123,18 @@ jobs: GITHUB_RUN_ID: ${{ github.run_id }} with: script: | + const fs = require('fs') const addComment = require('./.github/workflows/utilities/addComment.cjs') - const diffFilePath = ${{ steps.diff-files.outputs.diffFilePath }} + const diffConfig = ${{ needs.setup.outputs.diffs }} const WORKFLOW_SUMMARY_URL = `https://github.com/${{env.GITHUB_REPOSITORY}}/actions/runs/${{env.GITHUB_RUN_ID}}` - for (const diff of diffFilePath) { - await addComment(diff, WORKFLOW_SUMMARY_URL, context, github) + // read diff files + for (const config of diffConfig) { + const diff = JSON.parse(fs.readFileSync(config.outputFile, 'utf8')) + await addComment({ + title: config.title, + sections: diff + }, WORKFLOW_SUMMARY_URL, context, github) } remove_comment: diff --git a/.github/workflows/utilities/addComment.cjs b/.github/workflows/utilities/addComment.cjs index 6a26201b4..55ae6cf83 100644 --- a/.github/workflows/utilities/addComment.cjs +++ b/.github/workflows/utilities/addComment.cjs @@ -2,6 +2,8 @@ const findCommentByContent = (searchContent, comments) => { return comments.filter(comment => comment.body.includes(searchContent)); } +const COMMENT_CHAR_LIMIT = 65536 + module.exports = async ({title, body, sections}, summaryLink, context, github) => { console.log(`Preparing comment content for ${title}`) // prepare body @@ -25,7 +27,7 @@ module.exports = async ({title, body, sections}, summaryLink, context, github) = } // overwrite body if to long - if(summaryLink && commentBody.length > 65536) { + if(summaryLink && commentBody.length > COMMENT_CHAR_LIMIT) { commentBody = `## ${title}\n\nThe message is too long to be displayed here. For more details, please check the job summary.` } @@ -42,7 +44,7 @@ module.exports = async ({title, body, sections}, summaryLink, context, github) = console.log(`Found ${existingComment.length} comments, with the title "## ${title}"`) // delete comment if no body or sections if(!body && (!sections || sections.length === 0)) { - if(existingComment.length > 0 &&) { + if(existingComment.length > 0) { console.log(`Deleting comment with the title "## ${title}" and the id ${existingComment[0].id}`) // if comment exists, delete it await github.rest.issues.deleteComment({ diff --git a/.github/workflows/utilities/addSummary.cjs b/.github/workflows/utilities/addSummary.cjs index b52108ad5..702e62c63 100644 --- a/.github/workflows/utilities/addSummary.cjs +++ b/.github/workflows/utilities/addSummary.cjs @@ -1,10 +1,11 @@ const core = require('@actions/core') +const SUMMARY_CHAR_LIMIT = 1024000 + module.exports = (content, overwrite = false) => { if(!Array.isArray(content)) { content = [content] } - // core.summary.clear() for (const {title, body, sections} of content) { // if no body or sections, skip @@ -27,7 +28,14 @@ module.exports = (content, overwrite = false) => { `${body}\n`+ '```\n\n'+ '' - core.summary.addRaw(section, true) + + if(core.summary.stringify().length + section.length <= SUMMARY_CHAR_LIMIT) { + core.summary.addRaw(section, true) + } + else { + core.warning('Summary character limit reached, content will be truncated.') + core.info('---------------',`${title}:`, body, '---------------') + } }) } } diff --git a/.github/workflows/utilities/diffFiles.cjs b/.github/workflows/utilities/diffFiles.cjs index 7bf2b2861..76d1bbedf 100644 --- a/.github/workflows/utilities/diffFiles.cjs +++ b/.github/workflows/utilities/diffFiles.cjs @@ -2,7 +2,7 @@ const shell = require('shelljs') const fs = require('fs') const glob = require('@actions/glob') -module.exports = async (folder, globString, outputFile) => { +module.exports = async ({folder, globString, outputFile}, originPath) => { const globber = await glob.create(folder + globString) const files = await globber.glob() // create output file @@ -13,7 +13,7 @@ module.exports = async (folder, globString, outputFile) => { const regexRunnerPath = new RegExp('^[a-z\/]+\/dist', 'g') const filename = file.replaceAll(regexRunnerPath,'') // if file is new - if (!fs.existsSync(file.replace(folder, 'base/' + folder))) { + if (!fs.existsSync(file.replace(folder, `${originPath}/` + folder))) { console.info('⚠️ File is new: ' + file + '\n') return { title: file.replaceAll('dist/', ''), @@ -21,7 +21,7 @@ module.exports = async (folder, globString, outputFile) => { } } // run diff & store in file - const diff = shell.exec(`diff -u ${file.replace(folder, 'base/' + folder)} ${file}`) + const diff = shell.exec(`diff -u ${file.replace(folder, `${originPath}/` + folder)} ${file}`) console.log('Checking diff for ' + filename + '...')