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
21 changes: 14 additions & 7 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,20 @@ jobs:
test "${#packages[@]}" -eq 1
package=${packages[0]}
candidate_integrity=$(node -e 'const fs=require("fs"); const p=JSON.parse(fs.readFileSync(process.argv[1],"utf8"))[0]; process.stdout.write(p.integrity)' "$RUNNER_TEMP/npm-artifact/npm-pack.json")
published_integrity=$(npm view "@createitv/agc-cli@$version" dist.integrity --json 2>/dev/null | tr -d '"\n' || true)
if test -n "$published_integrity"; then
test "$candidate_integrity" = "$published_integrity" || { echo "published npm package integrity differs from this release" >&2; exit 1; }
echo "@createitv/agc-cli@$version already matches the release; skipping immutable version."
else
npm publish "$package" --access public
fi
published_integrity=$(npm view "@createitv/agc-cli@$version" dist.integrity 2>/dev/null || true)
case "$published_integrity" in
sha512-*)
test "$candidate_integrity" = "$published_integrity" || { echo "published npm package integrity differs from this release" >&2; exit 1; }
echo "@createitv/agc-cli@$version already matches the release; skipping immutable version."
;;
"")
npm publish "$package" --access public
;;
*)
echo "unexpected npm integrity response: $published_integrity" >&2
exit 1
;;
esac
- name: Verify registry installation
run: |
version=${RELEASE_TAG#v}
Expand Down
15 changes: 15 additions & 0 deletions scripts/test_npm_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ def test_setup_node_does_not_use_boolean_cache_value(self):
"omit cache to disable it",
)

def test_missing_version_does_not_turn_npm_json_error_into_integrity(self):
workflow = NPM_WORKFLOW.read_text(encoding="utf-8")

self.assertNotIn(
'dist.integrity --json',
workflow,
"npm view --json prints an error object to stdout for a missing "
"version, which must not be mistaken for an existing integrity",
)
self.assertIn(
'case "$published_integrity" in',
workflow,
"the workflow must only treat an sha512 integrity as published",
)


if __name__ == "__main__":
unittest.main()
Loading