|
| 1 | +name: Chromium Include Analysis Diff |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: '0 18 * * *' |
| 7 | + |
| 8 | +permissions: {} |
| 9 | + |
| 10 | +jobs: |
| 11 | + chromium_include_analysis_diff: |
| 12 | + name: Chromium Include Analysis Diff |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 17 | + with: |
| 18 | + repository: dsanders11/chromium-include-cleanup |
| 19 | + - name: Download Include Analysis Output |
| 20 | + run: | |
| 21 | + curl https://commondatastorage.googleapis.com/chromium-browser-clang/include-analysis.js > include-analysis.js |
| 22 | + - run: npm install @actions/cache |
| 23 | + - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 24 | + id: check-new-include-analysis |
| 25 | + with: |
| 26 | + script: | |
| 27 | + const fs = require('node:fs'); |
| 28 | + const cache = require('@actions/cache'); |
| 29 | +
|
| 30 | + let rawIncludeAnalysis = fs.readFileSync('./include-analysis.js', 'utf8').trim(); |
| 31 | + rawIncludeAnalysis = /data = ({.*})/.exec(rawIncludeAnalysis)[1] |
| 32 | + const { revision } = JSON.parse(rawIncludeAnalysis); |
| 33 | +
|
| 34 | + // Check if we've already analyzed this revision |
| 35 | + const cacheKey = `v1-chromium-include-analysis-diff-${revision}`; |
| 36 | + const cacheHit = |
| 37 | + (await cache.restoreCache(['/dev/null'], cacheKey, undefined, { |
| 38 | + lookupOnly: true, |
| 39 | + })) !== undefined; |
| 40 | +
|
| 41 | + if (!cacheHit) { |
| 42 | + core.setOutput('revision', revision); |
| 43 | + // Create a cache entry (only the name matters) to keep track of seen revisions |
| 44 | + await cache.saveCache(['/dev/null'], cacheKey); |
| 45 | + } |
| 46 | + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 |
| 47 | + if: ${{ steps.check-new-include-analysis.outputs.revision }} |
| 48 | + with: |
| 49 | + python-version: '3.12' |
| 50 | + cache: 'pip' |
| 51 | + - name: Install Dependencies |
| 52 | + if: ${{ steps.check-new-include-analysis.outputs.revision }} |
| 53 | + run: pip install -r requirements.txt |
| 54 | + - name: Include Analysis Diff |
| 55 | + if: ${{ steps.check-new-include-analysis.outputs.revision }} |
| 56 | + run: | |
| 57 | + python include_analysis_diff.py include-analysis.js > include-analysis-diff.csv |
| 58 | + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 59 | + if: ${{ steps.check-new-include-analysis.outputs.revision }} |
| 60 | + with: |
| 61 | + name: include-analysis-diff |
| 62 | + path: include-analysis-diff.csv |
| 63 | + - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 64 | + if: ${{ steps.check-new-include-analysis.outputs.revision }} |
| 65 | + env: |
| 66 | + REVISION: ${{ steps.check-new-include-analysis.outputs.revision }} |
| 67 | + with: |
| 68 | + script: | |
| 69 | + const fs = require('node:fs'); |
| 70 | +
|
| 71 | + const rows = fs.readFileSync('./include-analysis-diff.csv', 'utf8').trim().split('\n').map((line) => line.trim().split(',')); |
| 72 | +
|
| 73 | + // If there's no include listed, the file itself increased in size |
| 74 | + const files = rows.filter((row) => row[4] === '').map((row) => [row[0], row[1], row[2], row[3], parseInt(row[5])]); |
| 75 | + const edges = rows.filter((row) => row[4] !== '').map((row) => [row[0], row[1], row[2], `${row[3]} --> ${row[4]}`, parseInt(row[5])]); |
| 76 | +
|
| 77 | + if (files.length > 0 || edges.length > 0) { |
| 78 | + core.summary.addHeading('🔬 Chromium Include Analysis Diff'); |
| 79 | + core.summary.addRaw(`Analyzed revision ${process.env.REVISION} for differences in include analysis results compared to previous runs`); |
| 80 | + core.summary.addBreak(); |
| 81 | + |
| 82 | + if (files.length > 0) { |
| 83 | + core.summary.addHeading('Added Size Increases in Files', '2'); |
| 84 | + core.summary.addTable([ |
| 85 | + [ |
| 86 | + { data: 'Previous Analysis', header: true }, |
| 87 | + { data: 'Filename', header: true }, |
| 88 | + { data: 'Added Size Increase', header: true }, |
| 89 | + ], |
| 90 | + // Sort by added size, then convert it back to string or it won't render |
| 91 | + ...files |
| 92 | + .sort((a, b) => b[4] - a[4]) |
| 93 | + .map(([url, revision, date, filename, addedSize]) => [ |
| 94 | + `<a href="${url}" title="${revision}">${date}</a>`, |
| 95 | + // `<a href="${url}#view=files&filter=${encodeURIComponent("^" + filename + "$")}">${filename}</a>`, |
| 96 | + filename, |
| 97 | + addedSize.toLocaleString(), |
| 98 | + ]), |
| 99 | + ]); |
| 100 | + } |
| 101 | +
|
| 102 | + if (edges.length > 0) { |
| 103 | + core.summary.addHeading('Added Size Increases in Edges', '2'); |
| 104 | + core.summary.addTable([ |
| 105 | + [ |
| 106 | + { data: 'Previous Analysis', header: true }, |
| 107 | + { data: 'Include Edge', header: true }, |
| 108 | + { data: 'Added Size Increase', header: true }, |
| 109 | + ], |
| 110 | + // Sort by added size, then convert it back to string or it won't render |
| 111 | + ...edges |
| 112 | + .sort((a, b) => b[4] - a[4]) |
| 113 | + .map(([url, revision, date, edge, addedSize]) => [ |
| 114 | + `<a href="${url}" title="${revision}">${date}</a>`, |
| 115 | + // `<a href="${url}#view=edges&includer=${encodeURIComponent("^" + edge.split(" ")[0] + "$")}&included=${encodeURIComponent("^" + edge.split(" ").at(-1) + "$")}"">${edge}</a>`, |
| 116 | + edge, |
| 117 | + addedSize.toLocaleString(), |
| 118 | + ]), |
| 119 | + ]); |
| 120 | + } |
| 121 | + } else { |
| 122 | + core.summary.addRaw(`No differences exceeding thresholds found between ${process.env.REVISION} and previous include analysis runs`); |
| 123 | + } |
| 124 | +
|
| 125 | + await core.summary.write(); |
0 commit comments