Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/scripts/release-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,19 @@ if [[ "$release_type" == node ]]; then
# pnpm pack writes publishConfig.exports into exports. A missing target fails only on import.
packed_files=$(tar -tf "$artifact")
targets=$(jq -r '.exports, .bin | .. | strings' <<< "$metadata")
if [[ -z "$targets" ]]; then
echo "Packed $packed_name has no target in its exports or bin" >&2
exit 1
fi
while IFS= read -r target; do
[[ -n "$target" ]] || continue
if [[ "$target" == *"*"* ]]; then
echo "Packed $packed_name has the pattern target $target, which this check cannot match" >&2
exit 1
fi
if ! grep -Fxq "package/${target#./}" <<< "$packed_files"; then
echo "Packed $packed_name has no $target, a target of its exports or bin" >&2
exit 1
fi
done <<< "$targets"
echo "$packed_name: targets in exports and bin: $(wc -l <<< "$targets" | tr -d ' '), all in the tarball"
fi
22 changes: 20 additions & 2 deletions .github/scripts/release_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ expect_failure "Retry commit changes package.json outside packageManager" \
run_source workflow_dispatch refs/heads/main "$package_change_sha"

mkdir -p "$tmp/archive/package"
printf '{"name":"@telemetry-dev/mcp","version":"0.1.1"}\n' > "$tmp/archive/package/package.json"
printf '{"name":"@telemetry-dev/mcp","version":"0.1.1","exports":{"./package.json":"./package.json"}}\n' \
> "$tmp/archive/package/package.json"
tar -czf "$tmp/mcp.tgz" -C "$tmp/archive" package
printf '{"packages/mcp":"0.1.1"}\n' > "$repo/.release-please-manifest.json"
(
Expand All @@ -291,7 +292,7 @@ expect_failure "Packed name @telemetry-dev/other does not match release name @te
bash -c "cd '$repo' && '$artifact_script' packages/mcp '$tmp/wrong-name.tgz'"
printf '{"packages/mcp":"0.1.1"}\n' > "$repo/.release-please-manifest.json"
jq -n '{
name: "@telemetry-dev/mcp", version: "0.1.1", bin: "dist/cli.mjs",
name: "@telemetry-dev/mcp", version: "0.1.1", bin: {mcp: "dist/cli.mjs"},
exports: {".": {types: "./dist/index.d.mts", import: "./dist/index.mjs"}, "./package.json": "./package.json"}
}' > "$tmp/archive/package/package.json"
for missing in none dist/index.d.mts dist/cli.mjs; do
Expand All @@ -310,6 +311,23 @@ for missing in none dist/index.d.mts dist/cli.mjs; do
bash -c "cd '$repo' && '$artifact_script' packages/mcp '$tmp/exports.tgz'"
fi
done
# A string bin is the other form of bin.
jq '.bin = "dist/cli.mjs"' "$tmp/archive/package/package.json" > "$tmp/bin.json"
mv "$tmp/bin.json" "$tmp/archive/package/package.json"
tar -czf "$tmp/exports.tgz" -C "$tmp/archive" package
expect_failure "dist/cli.mjs, a target of its exports or bin" \
bash -c "cd '$repo' && '$artifact_script' packages/mcp '$tmp/exports.tgz'"
# A pattern target names no file, so the check cannot match it.
printf 'export {};\n' > "$tmp/archive/package/dist/cli.mjs"
jq '.exports["./*"] = "./dist/*.mjs"' "$tmp/archive/package/package.json" > "$tmp/pattern.json"
mv "$tmp/pattern.json" "$tmp/archive/package/package.json"
tar -czf "$tmp/exports.tgz" -C "$tmp/archive" package
expect_failure "Packed @telemetry-dev/mcp has the pattern target ./dist/*.mjs" \
bash -c "cd '$repo' && '$artifact_script' packages/mcp '$tmp/exports.tgz'"
jq -n '{name: "@telemetry-dev/mcp", version: "0.1.1"}' > "$tmp/archive/package/package.json"
tar -czf "$tmp/exports.tgz" -C "$tmp/archive" package
expect_failure "Packed @telemetry-dev/mcp has no target in its exports or bin" \
bash -c "cd '$repo' && '$artifact_script' packages/mcp '$tmp/exports.tgz'"
rm -rf "$tmp/archive/package/dist"

mkdir -p "$tmp/publish/npm"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ jobs:
.packages | to_entries[]
| select(.value["release-type"] == "node" and $manifest[0][.key] != null) | .key
' release-please-config.json)
[[ -n "$packages" ]]
if [[ -z "$packages" ]]; then
echo "No npm package in release-please-config.json has a release version" >&2
exit 1
fi
while IFS= read -r package; do
metadata=$(pnpm --dir "$package" pack --pack-destination "$output" --json)
.github/scripts/release-artifact.sh "$package" "$(jq -r '.filename' <<< "$metadata")"
Expand Down
Loading