@allons-y/actions-file-diff 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,8 +22,8 @@
22
22
  <a href="https://www.npmjs.com/package/@allons-y/actions-file-diff">
23
23
  <img src="https://img.shields.io/npm/dw/@allons-y/actions-file-diff.svg" alt="NPM downloads" height="20" />
24
24
  </a>
25
- <a href="https://github.com/allonsy-studio/actions-file-diff/actions/workflows/testing.yml">
26
- <img src="https://github.com/allonsy-studio/actions-file-diff/actions/workflows/testing.yml/badge.svg?branch=main" alt="Tests" height="20" />
25
+ <a href="https://github.com/allonsy-studio/actions-file-diff/actions/workflows/ci.yml">
26
+ <img src="https://github.com/allonsy-studio/actions-file-diff/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI" height="20" />
27
27
  </a>
28
28
  <a href="https://github.com/allonsy-studio/actions-file-diff/blob/main/LICENSE">
29
29
  <img src="https://img.shields.io/github/license/allonsy-studio/actions-file-diff.svg" alt="License" height="20" />
@@ -78,7 +78,7 @@ jobs:
78
78
  working-directory: base
79
79
 
80
80
  # (c) Compare the two trees and report on the pull request.
81
- - uses: allonsy-studio/actions-file-diff@v1
81
+ - uses: allonsy-studio/actions-file-diff@v0
82
82
  with:
83
83
  head-path: ${{ github.workspace }}
84
84
  base-path: ${{ github.workspace }}/base
@@ -100,23 +100,26 @@ If `base-path` is omitted, or the directory does not exist, the action reports h
100
100
 
101
101
  ## Inputs
102
102
 
103
- | Name | Required | Default | Description |
104
- | ------------------- | -------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
105
- | `head-path` | no | `${{ github.workspace }}` | Directory containing the head (pull request) tree to measure. |
106
- | `base-path` | no | — | Directory containing the base tree to compare against. If omitted or missing, only head totals are reported. |
107
- | `token` | no | `${{ github.token }}` | Token used to post the pull request comment. |
108
- | `file-glob-pattern` | no | `**/dist/**` | Glob pattern(s) selecting the files to measure, resolved relative to `head-path` and `base-path` via [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob). Newline-separated for multiple. Lines starting with `!` exclude, e.g. `!**/*.map`. |
109
- | `build-dir` | no | `dist` | The path segment that separates a package from its built output. Files are grouped into a package named by the directory before this segment; the reported filename is the path after it. |
110
- | `main-file` | no | `index.js` | Filename, relative to the build dir, treated as the package's main file. Used for the summary table. |
111
- | `read-package-json` | no | `"true"` | When `"true"`, a package's `package.json` `main` field overrides `main-file` for that package. |
112
- | `extensions` | no | — | Newline- or comma-separated list of base extensions to report, e.g. `css, js`. Empty reports all files. The `.min`, `.gz` and `.map` layers are stripped before matching, so `index.min.css.gz` counts as `css`. |
113
- | `comment` | no | `"true"` | Whether to post or update the pull request comment. |
114
- | `comment-header` | no | `## File metrics` | First line of the comment. Also used to derive the hidden marker that keeps the comment sticky across runs, so use distinct headers if you run the action more than once per pull request. |
115
- | `visual-diff` | no | `summary` | Where the visual diff linked from the comment lives: `summary`, `branch` or `none`. See [Visual diff](#visual-diff). |
116
- | `report-branch` | no | `file-diff-reports` | Branch the HTML report is committed to when `visual-diff` is `branch`. Created as an orphan branch when missing. |
117
- | `pages-url` | no | — | Base URL that serves `report-branch`. Defaults to the repository's GitHub Pages URL. |
118
- | `max-diff-size` | no | `262144` | Largest file, in bytes, that gets a line diff. Larger files are listed without one. |
119
- | `max-diff-lines` | no | `20000` | Most diff lines kept for the whole report. A diff that would go over is left out of the report, with its line counts kept. `0` leaves out every diff. |
103
+ | Name | Required | Default | Description |
104
+ | ------------------- | -------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
105
+ | `head-path` | no | `${{ github.workspace }}` | Directory containing the head (pull request) tree to measure. |
106
+ | `base-path` | no | — | Directory containing the base tree to compare against. If omitted or missing, only head totals are reported. |
107
+ | `token` | no | `${{ github.token }}` | Token used to post the pull request comment. |
108
+ | `file-glob-pattern` | no | `**/dist/**` | Glob pattern(s) selecting the files to measure, resolved relative to `head-path` and `base-path` via [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob). Newline-separated for multiple. Lines starting with `!` exclude, e.g. `!**/*.map`. |
109
+ | `build-dir` | no | `dist` | The path segment that separates a package from its built output. Files are grouped into a package named by the directory before this segment; the reported filename is the path after it. |
110
+ | `main-file` | no | `index.js` | Filename, relative to the build dir, treated as the package's main file. Used for the summary table. |
111
+ | `read-package-json` | no | `"true"` | When `"true"`, a package's `package.json` `main` field overrides `main-file` for that package. |
112
+ | `extensions` | no | — | Newline- or comma-separated list of base extensions to report, e.g. `css, js`. Empty reports all files. The `.min`, `.gz` and `.map` layers are stripped before matching, so `index.min.css.gz` counts as `css`. |
113
+ | `normalize-names` | no | — | Regular expressions, one per line, for the changing parts of output filenames, such as content hashes. Each match is replaced before base and head paths are compared, so `index-BxK3a9.js` and `index-Q7pL2m.js` pair as one modified file. See [Hashed and renamed files](#hashed-and-renamed-files). |
114
+ | `ignore-patterns` | no | — | Regular expressions, one per line, for generated text that changes on every build, such as random IDs. Matches are replaced on both sides before text files are compared and diffed. See [Random IDs and inline source maps](#random-ids-and-inline-source-maps). |
115
+ | `rename-threshold` | no | `50` | Minimum similarity, as a percentage, for pairing a file only on base with a file only on head that has the same extension, the way git detects renames. `0` turns it off. |
116
+ | `comment` | no | `"true"` | Whether to post or update the pull request comment. |
117
+ | `comment-header` | no | `## File metrics` | First line of the comment. Also used to derive the hidden marker that keeps the comment sticky across runs, so use distinct headers if you run the action more than once per pull request. |
118
+ | `visual-diff` | no | `summary` | Where the visual diff linked from the comment lives: `summary`, `branch` or `none`. See [Visual diff](#visual-diff). |
119
+ | `report-branch` | no | `file-diff-reports` | Branch the HTML report is committed to when `visual-diff` is `branch`. Created as an orphan branch when missing. |
120
+ | `pages-url` | no | — | Base URL that serves `report-branch`. Defaults to the repository's GitHub Pages URL. |
121
+ | `max-diff-size` | no | `262144` | Largest file, in bytes, that gets a line diff. Larger files are listed without one. |
122
+ | `max-diff-lines` | no | `20000` | Most diff lines kept for the whole report. A diff that would go over is left out of the report, with its line counts kept. `0` leaves out every diff. |
120
123
 
121
124
  ## Outputs
122
125
 
@@ -176,7 +179,7 @@ jobs:
176
179
  steps:
177
180
  # ...build head and base as in Usage, skipped when the PR is closed:
178
181
  # if: github.event.action != 'closed'
179
- - uses: allonsy-studio/actions-file-diff@v1
182
+ - uses: allonsy-studio/actions-file-diff@v0
180
183
  with:
181
184
  base-path: ${{ github.workspace }}/base
182
185
  visual-diff: branch
@@ -184,6 +187,36 @@ jobs:
184
187
 
185
188
  On a `closed` event the action only removes the report, so the build steps can be skipped with `if: github.event.action != 'closed'`.
186
189
 
190
+ ### Hashed and renamed files
191
+
192
+ Bundlers often put a content hash in output filenames, so an edited file gets a new name. Before comparing, the action pairs each file that is only on base with one that is only on head, then reports the pair as one modified file, with its size change and a line diff against the old name:
193
+
194
+ 1. **By name**, when `normalize-names` is set. A pair needs exactly one base file and one head file with the same name after replacement.
195
+ 2. **By content**, for the rest. Files with the same extension pair when they are at least `rename-threshold` percent alike. This covers names that are entirely a hash, such as Eleventy's `bundle/9pWhpkqfvF.css`. Binary files pair only when identical.
196
+
197
+ Content matching compares at most 200 files per side and extension, skips files over 1 MiB, and stops after 30 seconds with a warning. Files it didn't pair show as added and removed. `normalize-names` is faster, so use it when names follow a pattern.
198
+
199
+ ```yaml
200
+ normalize-names: |
201
+ -[A-Za-z0-9_-]{8}(?=\.)
202
+ ```
203
+
204
+ ### Random IDs and inline source maps
205
+
206
+ Some builds write different text on every run, even with no source change: WebC's generated IDs (`norn-header-webc-x0DiQ`) and inline source maps that embed a random input name are two examples. Set `ignore-patterns` to the regular expressions that match that text:
207
+
208
+ ```yaml
209
+ ignore-patterns: |
210
+ (?<=-webc-)[A-Za-z0-9_-]{5}
211
+ sourceMappingURL=data:application/json;base64,[A-Za-z0-9+/=]+
212
+ ```
213
+
214
+ Each match is replaced with `[ignored]` on both sides before a text file is compared. A file that differs only in matches is left out of the changed files, and the line diff of a file with other changes shows `[ignored]` in place of each match.
215
+
216
+ - It applies to text files up to `max-diff-size`. Larger and binary files compare byte for byte.
217
+ - Sizes in the table still count the real bytes, so a match that changes length can still show a size change.
218
+ - It needs `visual-diff` set to `summary` or `branch`, which is what lists the changed files.
219
+
187
220
  ### How sizes are counted
188
221
 
189
222
  - Files ending in `.map`, `.gz`, or `.min.*` are not reported as rows themselves; they appear as columns on their parent file's row.
@@ -196,7 +229,7 @@ On a `closed` event the action only removes the report, so the build steps can b
196
229
  Single-package repository whose build output lives in `build/`:
197
230
 
198
231
  ```yaml
199
- - uses: allonsy-studio/actions-file-diff@v1
232
+ - uses: allonsy-studio/actions-file-diff@v0
200
233
  with:
201
234
  base-path: ${{ github.workspace }}/base
202
235
  file-glob-pattern: |
@@ -210,7 +243,7 @@ Single-package repository whose build output lives in `build/`:
210
243
  CSS-only report:
211
244
 
212
245
  ```yaml
213
- - uses: allonsy-studio/actions-file-diff@v1
246
+ - uses: allonsy-studio/actions-file-diff@v0
214
247
  with:
215
248
  base-path: ${{ github.workspace }}/base
216
249
  extensions: css
@@ -219,7 +252,7 @@ CSS-only report:
219
252
  Excluding sourcemaps with a `!` pattern:
220
253
 
221
254
  ```yaml
222
- - uses: allonsy-studio/actions-file-diff@v1
255
+ - uses: allonsy-studio/actions-file-diff@v0
223
256
  with:
224
257
  base-path: ${{ github.workspace }}/base
225
258
  file-glob-pattern: |
@@ -233,9 +266,10 @@ Excluding sourcemaps with a `!` pattern:
233
266
  Plain JavaScript, no TypeScript. The source under `src/` is bundled with esbuild into `dist/index.js`, which is what `action.yml` runs; the bundle is committed so consumers get the action's dependencies without an install step.
234
267
 
235
268
  ```sh
236
- yarn lint # eslint (flat config, @eslint/js recommended + prettier)
237
- yarn format # prettier --write, then eslint --fix
238
- yarn test # jest, JS-only (line diffs need git on the PATH)
269
+ yarn lint # opx lint: JS, JSON, Markdown, and license headers
270
+ yarn format # opx lint --fix
271
+ yarn test # vitest (line diffs need git on the PATH)
272
+ yarn coverage # vitest with per-file coverage thresholds
239
273
  yarn test:browser # drives the report page in Chrome (CHROME_PATH, or the installed Chrome)
240
274
  yarn build # esbuild -> dist/index.js (committed; CI fails if stale)
241
275
  yarn preview # render the visual diff page from a sample fixture into preview/