Chromium Include Analysis Diff #20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Chromium Include Analysis Diff | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 18 * * *' | |
| permissions: {} | |
| jobs: | |
| chromium_include_analysis_diff: | |
| name: Chromium Include Analysis Diff | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| repository: dsanders11/chromium-include-cleanup | |
| - name: Download Include Analysis Output | |
| run: | | |
| curl https://commondatastorage.googleapis.com/chromium-browser-clang/include-analysis.js > include-analysis.js | |
| - run: npm install @actions/cache | |
| - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
| id: check-new-include-analysis | |
| with: | |
| script: | | |
| const fs = require('node:fs'); | |
| const cache = require('@actions/cache'); | |
| let rawIncludeAnalysis = fs.readFileSync('./include-analysis.js', 'utf8').trim(); | |
| rawIncludeAnalysis = /data = ({.*})/.exec(rawIncludeAnalysis)[1] | |
| const { revision } = JSON.parse(rawIncludeAnalysis); | |
| // Check if we've already analyzed this revision | |
| const cacheKey = `v1-chromium-include-analysis-diff-${revision}`; | |
| const cacheHit = | |
| (await cache.restoreCache(['/dev/null'], cacheKey, undefined, { | |
| lookupOnly: true, | |
| })) !== undefined; | |
| if (!cacheHit) { | |
| core.setOutput('revision', revision); | |
| // Create a cache entry (only the name matters) to keep track of seen revisions | |
| await cache.saveCache(['/dev/null'], cacheKey); | |
| } | |
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 | |
| if: ${{ steps.check-new-include-analysis.outputs.revision }} | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - name: Install Dependencies | |
| if: ${{ steps.check-new-include-analysis.outputs.revision }} | |
| run: pip install -r requirements.txt | |
| - name: Include Analysis Diff | |
| if: ${{ steps.check-new-include-analysis.outputs.revision }} | |
| run: | | |
| python include_analysis_diff.py include-analysis.js > include-analysis-diff.csv | |
| - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| if: ${{ steps.check-new-include-analysis.outputs.revision }} | |
| with: | |
| name: include-analysis-diff | |
| path: include-analysis-diff.csv | |
| - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
| if: ${{ steps.check-new-include-analysis.outputs.revision }} | |
| env: | |
| REVISION: ${{ steps.check-new-include-analysis.outputs.revision }} | |
| with: | |
| script: | | |
| const fs = require('node:fs'); | |
| const rows = fs.readFileSync('./include-analysis-diff.csv', 'utf8').trim().split('\n').map((line) => line.trim().split(',')); | |
| // If there's no include listed, the file itself increased in size | |
| const files = rows.filter((row) => row[4] === '').map((row) => [row[0], row[1], row[2], row[3], parseInt(row[5])]); | |
| const edges = rows.filter((row) => row[4] !== '').map((row) => [row[0], row[1], row[2], `${row[3]} --> ${row[4]}`, parseInt(row[5])]); | |
| if (files.length > 0 || edges.length > 0) { | |
| core.summary.addHeading('🔬 Chromium Include Analysis Diff'); | |
| core.summary.addRaw(`Analyzed revision ${process.env.REVISION} for differences in include analysis results compared to previous runs`); | |
| core.summary.addBreak(); | |
| if (files.length > 0) { | |
| core.summary.addHeading('Added Size Increases in Files', '2'); | |
| core.summary.addTable([ | |
| [ | |
| { data: 'Previous Analysis', header: true }, | |
| { data: 'Filename', header: true }, | |
| { data: 'Added Size Increase', header: true }, | |
| ], | |
| // Sort by added size, then convert it back to string or it won't render | |
| ...files | |
| .sort((a, b) => b[4] - a[4]) | |
| .map(([url, revision, date, filename, addedSize]) => [ | |
| `<a href="${url}" title="${revision}">${date}</a>`, | |
| // `<a href="${url}#view=files&filter=${encodeURIComponent("^" + filename + "$")}">${filename}</a>`, | |
| filename, | |
| addedSize.toLocaleString(), | |
| ]), | |
| ]); | |
| } | |
| if (edges.length > 0) { | |
| core.summary.addHeading('Added Size Increases in Edges', '2'); | |
| core.summary.addTable([ | |
| [ | |
| { data: 'Previous Analysis', header: true }, | |
| { data: 'Include Edge', header: true }, | |
| { data: 'Added Size Increase', header: true }, | |
| ], | |
| // Sort by added size, then convert it back to string or it won't render | |
| ...edges | |
| .sort((a, b) => b[4] - a[4]) | |
| .map(([url, revision, date, edge, addedSize]) => [ | |
| `<a href="${url}" title="${revision}">${date}</a>`, | |
| // `<a href="${url}#view=edges&includer=${encodeURIComponent("^" + edge.split(" ")[0] + "$")}&included=${encodeURIComponent("^" + edge.split(" ").at(-1) + "$")}"">${edge}</a>`, | |
| edge, | |
| addedSize.toLocaleString(), | |
| ]), | |
| ]); | |
| } | |
| } else { | |
| core.summary.addRaw(`No differences exceeding thresholds found between ${process.env.REVISION} and previous include analysis runs`); | |
| } | |
| await core.summary.write(); |