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

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,29 +100,32 @@ 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
 
123
126
  | Name | Description |
124
127
  | ------------- | ------------------------------------------------------------------------------------------------- |
125
- | `has-changed` | `"true"` when the head total differs from the base total. Always `"false"` when there is no base. |
128
+ | `has-changed` | `"true"` when any reported file was added, removed, or changed in content, after `ignore-patterns`. Always `"false"` when there is no base. |
126
129
  | `total-size` | Head total in bytes. |
127
130
  | `report-url` | Link to the visual diff (published page or workflow run). Empty when `visual-diff` is `none`. |
128
131
 
@@ -142,7 +145,7 @@ The pull request comment is shortened to fit GitHub's 65,536-character limit; wh
142
145
 
143
146
  ### `visual-diff: summary` (default)
144
147
 
145
- - Writes the three parts as collapsible sections in the [job summary](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#adding-a-job-summary). The comment links to the workflow run.
148
+ - Writes the three parts as collapsible sections in the [job summary](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#adding-a-job-summary). The comment links to the workflow run, unless no files changed.
146
149
  - No extra permissions or setup.
147
150
  - Limits: the summary has no tabs and can't show images (only a list of changed images), and GitHub caps it at 1 MiB, so long diffs are cut off with a note. It is kept for as long as the run's logs.
148
151
 
@@ -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,37 @@ 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
+ - Minified copies and source maps (`.min.*`, `.map`) are compared the same way, though they get no line diff of their own.
218
+ - Compressed copies (`.gz`, `.br`, `.zst`) count as changed only when the file they compress did, so recompression alone is not a change. One without an uncompressed copy compares byte for byte.
219
+ - Sizes in the table still count the real bytes, so a match that changes length can still show a size change.
220
+
187
221
  ### How sizes are counted
188
222
 
189
223
  - 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 +230,7 @@ On a `closed` event the action only removes the report, so the build steps can b
196
230
  Single-package repository whose build output lives in `build/`:
197
231
 
198
232
  ```yaml
199
- - uses: allonsy-studio/actions-file-diff@v1
233
+ - uses: allonsy-studio/actions-file-diff@v0
200
234
  with:
201
235
  base-path: ${{ github.workspace }}/base
202
236
  file-glob-pattern: |
@@ -210,7 +244,7 @@ Single-package repository whose build output lives in `build/`:
210
244
  CSS-only report:
211
245
 
212
246
  ```yaml
213
- - uses: allonsy-studio/actions-file-diff@v1
247
+ - uses: allonsy-studio/actions-file-diff@v0
214
248
  with:
215
249
  base-path: ${{ github.workspace }}/base
216
250
  extensions: css
@@ -219,7 +253,7 @@ CSS-only report:
219
253
  Excluding sourcemaps with a `!` pattern:
220
254
 
221
255
  ```yaml
222
- - uses: allonsy-studio/actions-file-diff@v1
256
+ - uses: allonsy-studio/actions-file-diff@v0
223
257
  with:
224
258
  base-path: ${{ github.workspace }}/base
225
259
  file-glob-pattern: |
@@ -233,9 +267,10 @@ Excluding sourcemaps with a `!` pattern:
233
267
  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
268
 
235
269
  ```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)
270
+ yarn lint # opx lint: JS, JSON, Markdown, and license headers
271
+ yarn format # opx lint --fix
272
+ yarn test # vitest (line diffs need git on the PATH)
273
+ yarn coverage # vitest with per-file coverage thresholds
239
274
  yarn test:browser # drives the report page in Chrome (CHROME_PATH, or the installed Chrome)
240
275
  yarn build # esbuild -> dist/index.js (committed; CI fails if stale)
241
276
  yarn preview # render the visual diff page from a sample fixture into preview/