| 1 |
name: diff-shades |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: [main] |
| 6 |
paths: |
| 7 |
- src/** |
| 8 |
- pyproject.toml |
| 9 |
- scripts/diff_shades_gha_helper.py |
| 10 |
- .github/workflows/diff_shades.yml |
| 11 |
- .github/workflows/diff_shades_comment.yml |
| 12 |
|
| 13 |
pull_request: |
| 14 |
paths: |
| 15 |
- src/** |
| 16 |
- pyproject.toml |
| 17 |
- scripts/diff_shades_gha_helper.py |
| 18 |
- .github/workflows/diff_shades.yml |
| 19 |
- .github/workflows/diff_shades_comment.yml |
| 20 |
|
| 21 |
concurrency: |
| 22 |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} |
| 23 |
cancel-in-progress: true |
| 24 |
|
| 25 |
env: |
| 26 |
HATCH_BUILD_HOOKS_ENABLE: "1" |
| 27 |
# Clang is less picky with the C code it's given than gcc (and may generate faster |
| 28 |
# binaries too). |
| 29 |
CC: clang-18 |
| 30 |
|
| 31 |
permissions: {} |
| 32 |
|
| 33 |
jobs: |
| 34 |
configure: |
| 35 |
runs-on: ubuntu-latest |
| 36 |
outputs: |
| 37 |
matrix: ${{ steps.set-config.outputs.matrix }} |
| 38 |
|
| 39 |
steps: |
| 40 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 41 |
with: |
| 42 |
persist-credentials: false |
| 43 |
|
| 44 |
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 45 |
with: |
| 46 |
python-version: "3.13" |
| 47 |
pip-version: "25.3" |
| 48 |
pip-install: --group diff-shades --group diff-shades-comment |
| 49 |
|
| 50 |
- name: Calculate run configuration & metadata |
| 51 |
id: set-config |
| 52 |
env: |
| 53 |
GITHUB_TOKEN: ${{ github.token }} |
| 54 |
run: python scripts/diff_shades_gha_helper.py config |
| 55 |
|
| 56 |
analysis-base: |
| 57 |
name: analysis / base / ${{ matrix.mode }} |
| 58 |
needs: configure |
| 59 |
runs-on: ubuntu-latest |
| 60 |
strategy: |
| 61 |
fail-fast: false |
| 62 |
matrix: |
| 63 |
include: ${{ fromJson(needs.configure.outputs.matrix) }} |
| 64 |
|
| 65 |
steps: |
| 66 |
- name: Checkout this repository (full clone) |
| 67 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 68 |
with: |
| 69 |
# The baseline revision could be rather old so a full clone is ideal. |
| 70 |
fetch-depth: 0 |
| 71 |
persist-credentials: false |
| 72 |
|
| 73 |
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 74 |
with: |
| 75 |
python-version: "3.13" |
| 76 |
pip-version: "25.3" |
| 77 |
pip-install: --group diff-shades |
| 78 |
|
| 79 |
- name: Configure git |
| 80 |
run: | |
| 81 |
git config user.name "diff-shades-gha" |
| 82 |
git config user.email "[email protected]" |
| 83 |
|
| 84 |
- name: Attempt to use cached baseline analysis |
| 85 |
id: baseline-cache |
| 86 |
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 87 |
with: |
| 88 |
path: ${{ matrix.baseline-analysis }} |
| 89 |
key: ${{ matrix.baseline-cache-key }} |
| 90 |
|
| 91 |
- name: Build and install baseline revision |
| 92 |
if: steps.baseline-cache.outputs.cache-hit != 'true' |
| 93 |
env: |
| 94 |
GITHUB_TOKEN: ${{ github.token }} |
| 95 |
run: | |
| 96 |
${{ matrix.baseline-setup-cmd }} |
| 97 |
python -m pip install . |
| 98 |
|
| 99 |
- name: Analyze baseline revision |
| 100 |
if: steps.baseline-cache.outputs.cache-hit != 'true' |
| 101 |
run: |
| 102 |
diff-shades analyze ${{ matrix.baseline-analysis }} --work-dir projects-cache/ |
| 103 |
--force-${{ matrix.style }}-style -v |
| 104 |
|
| 105 |
- name: Upload baseline analysis |
| 106 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 107 |
with: |
| 108 |
name: ${{ matrix.baseline-analysis }} |
| 109 |
path: ${{ matrix.baseline-analysis }} |
| 110 |
|
| 111 |
analysis-target: |
| 112 |
name: analysis / target / ${{ matrix.mode }} |
| 113 |
needs: configure |
| 114 |
runs-on: ubuntu-latest |
| 115 |
strategy: |
| 116 |
fail-fast: false |
| 117 |
matrix: |
| 118 |
include: ${{ fromJson(needs.configure.outputs.matrix) }} |
| 119 |
|
| 120 |
steps: |
| 121 |
- name: Checkout this repository (full clone) |
| 122 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 123 |
with: |
| 124 |
# The baseline revision could be rather old so a full clone is ideal. |
| 125 |
fetch-depth: 0 |
| 126 |
persist-credentials: false |
| 127 |
|
| 128 |
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 129 |
with: |
| 130 |
python-version: "3.13" |
| 131 |
pip-version: "25.3" |
| 132 |
pip-install: --group diff-shades |
| 133 |
|
| 134 |
- name: Configure git |
| 135 |
run: | |
| 136 |
git config user.name "diff-shades-gha" |
| 137 |
git config user.email "[email protected]" |
| 138 |
|
| 139 |
- name: Build and install target revision |
| 140 |
env: |
| 141 |
GITHUB_TOKEN: ${{ github.token }} |
| 142 |
run: | |
| 143 |
${{ matrix.target-setup-cmd }} |
| 144 |
python -m pip install . |
| 145 |
|
| 146 |
# Pull it from previous runs - we're NOT trying to get it from this run |
| 147 |
# (but it wouldn't cause problems if we theoretically did) |
| 148 |
- name: Attempt to find baseline analysis |
| 149 |
id: baseline-cache |
| 150 |
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 151 |
with: |
| 152 |
path: ${{ matrix.baseline-analysis }} |
| 153 |
key: ${{ matrix.baseline-cache-key }} |
| 154 |
|
| 155 |
- name: Analyze target revision (with repeated projects) |
| 156 |
if: steps.baseline-cache.outputs.cache-hit == 'true' |
| 157 |
run: | |
| 158 |
diff-shades analyze ${{ matrix.target-analysis }} --work-dir projects-cache/ \ |
| 159 |
--force-${{ matrix.style }}-style -v \ |
| 160 |
--repeat-projects-from ${{ matrix.baseline-analysis }} |
| 161 |
|
| 162 |
- name: Analyze target revision (without repeated projects) |
| 163 |
if: steps.baseline-cache.outputs.cache-hit != 'true' |
| 164 |
run: |
| 165 |
diff-shades analyze ${{ matrix.target-analysis }} --work-dir projects-cache/ |
| 166 |
--force-${{ matrix.style }}-style -v |
| 167 |
|
| 168 |
- name: Upload target analysis |
| 169 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 170 |
with: |
| 171 |
name: ${{ matrix.target-analysis }} |
| 172 |
path: ${{ matrix.target-analysis }} |
| 173 |
|
| 174 |
- name: Check for failed files for target revision |
| 175 |
run: diff-shades show-failed --check --show-log ${{ matrix.target-analysis }} |
| 176 |
|
| 177 |
compare: |
| 178 |
name: compare / ${{ matrix.mode }} |
| 179 |
needs: ["configure", "analysis-base", "analysis-target"] |
| 180 |
if: ${{ !cancelled() }} |
| 181 |
runs-on: ubuntu-latest |
| 182 |
strategy: |
| 183 |
fail-fast: false |
| 184 |
matrix: |
| 185 |
include: ${{ fromJson(needs.configure.outputs.matrix) }} |
| 186 |
|
| 187 |
steps: |
| 188 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 189 |
with: |
| 190 |
persist-credentials: false |
| 191 |
|
| 192 |
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 193 |
with: |
| 194 |
merge-multiple: true |
| 195 |
|
| 196 |
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 197 |
with: |
| 198 |
python-version: "3.13" |
| 199 |
pip-version: "25.3" |
| 200 |
pip-install: --group diff-shades --group diff-shades-comment |
| 201 |
|
| 202 |
- name: Generate HTML diff report |
| 203 |
run: | |
| 204 |
diff-shades --dump-html diff.html \ |
| 205 |
compare --diff ${{ matrix.baseline-analysis }} ${{ matrix.target-analysis }} |
| 206 |
|
| 207 |
- name: Upload diff report |
| 208 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 209 |
with: |
| 210 |
name: ${{ matrix.style }}-diff.html |
| 211 |
path: diff.html |
| 212 |
|
| 213 |
- name: Generate summary file (PR only) |
| 214 |
if: github.event_name == 'pull_request' |
| 215 |
env: |
| 216 |
GITHUB_TOKEN: ${{ github.token }} |
| 217 |
run: | |
| 218 |
python scripts/diff_shades_gha_helper.py comment-body \ |
| 219 |
${{ matrix.baseline-analysis }} ${{ matrix.target-analysis }} \ |
| 220 |
${{ matrix.style }} ${{ matrix.mode }} |
| 221 |
|
| 222 |
- name: Upload summary file (PR only) |
| 223 |
if: github.event_name == 'pull_request' |
| 224 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 225 |
with: |
| 226 |
name: .${{ matrix.style }}.pr-comment.md |
| 227 |
path: .${{ matrix.style }}.pr-comment.md |
| 228 |
include-hidden-files: true |
| 229 |
|
| 230 |
- name: Verify zero changes (PR only) |
| 231 |
if: matrix.mode == 'assert-no-changes' |
| 232 |
run: | |
| 233 |
diff-shades compare --check \ |
| 234 |
${{ matrix.baseline-analysis }} ${{ matrix.target-analysis }} || \ |
| 235 |
(echo "Please verify you didn't change the stable code style unintentionally!" \ |
| 236 |
&& exit 1) |