-
Notifications
You must be signed in to change notification settings - Fork 0
feat: preflight new-package check in npm-publish-hardened #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -85,6 +85,49 @@ done | |||||||||||||
| PKG_JSON_FILE="${RUNNER_TEMP:-/tmp}/npm-publish-hardened-pkg-$$.json" | ||||||||||||||
| trap 'rm -f "${PKG_JSON_FILE}"' EXIT | ||||||||||||||
|
|
||||||||||||||
| pkg_name_from_tarball() { | ||||||||||||||
| local tarball="$1" | ||||||||||||||
| tar -xOf "${tarball}" package/package.json > "${PKG_JSON_FILE}" | ||||||||||||||
| node -e ' | ||||||||||||||
| const j = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")); | ||||||||||||||
| console.log(j.name ?? ""); | ||||||||||||||
| ' "${PKG_JSON_FILE}" | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| # Preflight: every package in the queue must already exist on the | ||||||||||||||
| # registry. OIDC trusted publishing cannot create a brand-new package — | ||||||||||||||
| # npm requires a package to exist before a trusted publisher can be | ||||||||||||||
| # configured for it — so a first-ever publish would otherwise burn all | ||||||||||||||
|
Comment on lines
+98
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the Stella GitHub Development Guidelines, we should avoid using em dashes and instead prefer parentheses or other punctuation.
Suggested change
References
|
||||||||||||||
| # retries and fail late with an opaque ENEEDAUTH, after sibling | ||||||||||||||
| # packages already published. Fail fast, before publishing anything, | ||||||||||||||
| # with bootstrap instructions instead. | ||||||||||||||
| declare -a PREFLIGHT_MISSING=() | ||||||||||||||
| for tarball in "${PUBLISH_QUEUE[@]}"; do | ||||||||||||||
| preflight_name=$(pkg_name_from_tarball "${tarball}") | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under
Suggested change
|
||||||||||||||
| if [[ -z "${preflight_name}" || "${preflight_name}" == "null" ]]; then | ||||||||||||||
| printf '::error::Failed to read package name from %s.\n' "${tarball}" | ||||||||||||||
| exit 2 | ||||||||||||||
| fi | ||||||||||||||
| if view_output=$(npm view "${preflight_name}" name 2>&1); then | ||||||||||||||
| continue | ||||||||||||||
| fi | ||||||||||||||
| if grep -q 'E404' <<<"${view_output}"; then | ||||||||||||||
| PREFLIGHT_MISSING+=("${preflight_name}") | ||||||||||||||
| else | ||||||||||||||
| # Transient registry error must not block an otherwise valid | ||||||||||||||
| # release; the publish loop below has its own retries. | ||||||||||||||
| printf '::warning::Could not verify %s exists on the registry; continuing.\n' \ | ||||||||||||||
| "${preflight_name}" | ||||||||||||||
| fi | ||||||||||||||
| done | ||||||||||||||
| if (( ${#PREFLIGHT_MISSING[@]} > 0 )); then | ||||||||||||||
| for preflight_name in "${PREFLIGHT_MISSING[@]}"; do | ||||||||||||||
| printf '::error::%s has never been published. Trusted publishing cannot create new packages. Bootstrap it first: (1) npm publish a placeholder manually (e.g. version 0.0.1-placeholder.0 with --tag placeholder), (2) add a trusted publisher in the package settings on npmjs.com (allow "publish"), then re-run this workflow. Nothing was published in this run.\n' \ | ||||||||||||||
| "${preflight_name}" | ||||||||||||||
| done | ||||||||||||||
| exit 2 | ||||||||||||||
| fi | ||||||||||||||
|
|
||||||||||||||
| publish_one() { | ||||||||||||||
| local tarball="$1" | ||||||||||||||
| local package_name package_version | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the Stella GitHub Development Guidelines, we should avoid using em dashes and instead prefer semicolons or other punctuation.
References