Skip to content

Commit 66ff315

Browse files
committed
verify-action-build: support .cjs and .mjs compiled bundle extensions
The Dockerfile that rebuilds an action's bundle and diff_js only looked for *.js. Actions bundled with esbuild or rollup often emit dist/index.cjs (when the source package declares "type": "module" and needs a CommonJS bundle for the node runner — JustinBeckwith/linkinator-action v2.4.2 is the current trigger) or dist/index.mjs. For those actions the current pipeline both skips deleting the published bundle before rebuild (so a broken build is masked by the leftover file) and reports "No compiled JavaScript found" because the comparison walks only *.js. Extend the pre-rebuild delete step and the has_output probe in build_action.Dockerfile to cover *.js, *.cjs and *.mjs, and factor the file-collection in diff_js.py into a _collect_compiled_js helper that scans all three extensions. Add unit tests covering the helper including nested output directories (e.g. dist/sub/main/index.cjs). Generated-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4a6aae0 commit 66ff315

3 files changed

Lines changed: 57 additions & 11 deletions

File tree

utils/tests/verify_action_build/test_diff_js.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818
#
19-
from verify_action_build.diff_js import beautify_js
19+
from verify_action_build.diff_js import _collect_compiled_js, beautify_js
2020

2121

2222
class TestBeautifyJs:
@@ -47,3 +47,32 @@ def test_consistent_output(self):
4747
result1 = beautify_js(code)
4848
result2 = beautify_js(code)
4949
assert result1 == result2
50+
51+
52+
class TestCollectCompiledJs:
53+
def test_picks_up_js_cjs_mjs(self, tmp_path):
54+
(tmp_path / "dist").mkdir()
55+
(tmp_path / "dist" / "index.js").write_text("// js\n")
56+
(tmp_path / "dist" / "index.cjs").write_text("// cjs\n")
57+
(tmp_path / "dist" / "index.mjs").write_text("// mjs\n")
58+
(tmp_path / "dist" / "index.cjs.map").write_text("{}\n")
59+
(tmp_path / "dist" / "readme.md").write_text("ignored\n")
60+
61+
found = _collect_compiled_js(tmp_path)
62+
63+
from pathlib import Path
64+
assert found == {
65+
Path("dist/index.js"),
66+
Path("dist/index.cjs"),
67+
Path("dist/index.mjs"),
68+
}
69+
70+
def test_empty_dir_returns_empty(self, tmp_path):
71+
assert _collect_compiled_js(tmp_path) == set()
72+
73+
def test_nested_dirs(self, tmp_path):
74+
(tmp_path / "dist" / "sub" / "main").mkdir(parents=True)
75+
(tmp_path / "dist" / "sub" / "main" / "index.cjs").write_text("// cjs\n")
76+
77+
from pathlib import Path
78+
assert _collect_compiled_js(tmp_path) == {Path("dist/sub/main/index.cjs")}

utils/verify_action_build/diff_js.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@
2525
from .console import console, link
2626
from .diff_display import show_colored_diff
2727

28+
# Extensions emitted by action build toolchains. `.js` is the common case
29+
# (webpack/ncc/tsc); `.cjs` is what esbuild/rollup write when the source
30+
# package is ESM (type: module) and the action needs a CommonJS bundle for
31+
# the node runner (e.g. JustinBeckwith/linkinator-action);
32+
# `.mjs` is the inverse — an ESM bundle for node20+ runners.
33+
COMPILED_JS_EXTENSIONS = ("*.js", "*.cjs", "*.mjs")
34+
35+
36+
def _collect_compiled_js(base: Path) -> set[Path]:
37+
"""Return relative paths of compiled JS files under base."""
38+
found: set[Path] = set()
39+
for pattern in COMPILED_JS_EXTENSIONS:
40+
for f in base.rglob(pattern):
41+
found.add(f.relative_to(base))
42+
return found
43+
2844

2945
def beautify_js(content: str) -> str:
3046
"""Reformat JavaScript for readable diffing."""
@@ -46,13 +62,8 @@ def diff_js_files(
4662
# Files vendored by @vercel/ncc that are not built from the action's source.
4763
ignored_files = {"sourcemap-register.js"}
4864

49-
original_files = set()
50-
rebuilt_files = set()
51-
52-
for f in original_dir.rglob("*.js"):
53-
original_files.add(f.relative_to(original_dir))
54-
for f in rebuilt_dir.rglob("*.js"):
55-
rebuilt_files.add(f.relative_to(rebuilt_dir))
65+
original_files = _collect_compiled_js(original_dir)
66+
rebuilt_files = _collect_compiled_js(rebuilt_dir)
5667

5768
all_files = sorted(original_files | rebuilt_files)
5869

utils/verify_action_build/dockerfiles/build_action.Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,15 @@ RUN if [ -d "node_modules" ]; then \
8383
mkdir /original-node-modules; \
8484
fi
8585

86-
# Delete compiled JS from output dir before rebuild to ensure a clean build
86+
# Delete compiled JS from output dir before rebuild to ensure a clean build.
87+
# Covers .js, .cjs and .mjs — actions bundled with esbuild/rollup may emit
88+
# dist/index.cjs (e.g. JustinBeckwith/linkinator-action) or dist/index.mjs.
8789
RUN OUT_DIR=$(cat /out-dir.txt); \
88-
if [ -d "$OUT_DIR" ]; then find "$OUT_DIR" -name '*.js' -print -delete > /deleted-js.log 2>&1; else echo "no $OUT_DIR/ directory" > /deleted-js.log; fi
90+
if [ -d "$OUT_DIR" ]; then \
91+
find "$OUT_DIR" \( -name '*.js' -o -name '*.cjs' -o -name '*.mjs' \) -print -delete > /deleted-js.log 2>&1; \
92+
else \
93+
echo "no $OUT_DIR/ directory" > /deleted-js.log; \
94+
fi
8995

9096
# If an approved (previous) commit hash is provided, restore the dev-dependency
9197
# lock files from that commit so the rebuild uses the same toolchain (e.g. same
@@ -179,7 +185,7 @@ RUN BUILD_DIR=$(cat /build-dir.txt); \
179185
RUN OUT_DIR=$(cat /out-dir.txt); \
180186
BUILD_DIR=$(cat /build-dir.txt); \
181187
RUN_CMD=$(cat /run-cmd); \
182-
has_output() { [ -d "$OUT_DIR" ] && find "$OUT_DIR" -name '*.js' -print -quit | grep -q .; }; \
188+
has_output() { [ -d "$OUT_DIR" ] && find "$OUT_DIR" \( -name '*.js' -o -name '*.cjs' -o -name '*.mjs' \) -print -quit | grep -q .; }; \
183189
BUILD_DONE=false; \
184190
if [ -x build ] && ./build dist 2>/dev/null; then \
185191
echo "build-step: ./build dist" >> /build-info.log; \

0 commit comments

Comments
 (0)