-
Notifications
You must be signed in to change notification settings - Fork 350
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
Add prepublish checks to block releases of non-snapshot versionsfirst one #2037
Changes from all commits
774926b
4182157
f721074
5dddee1
165f468
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
"@khanacademy/kas": patch | ||
"@khanacademy/keypad-context": patch | ||
"@khanacademy/kmath": patch | ||
"@khanacademy/math-input": patch | ||
"@khanacademy/perseus": patch | ||
"@khanacademy/perseus-core": patch | ||
"@khanacademy/perseus-editor": patch | ||
"@khanacademy/perseus-linter": patch | ||
"@khanacademy/pure-markdown": patch | ||
"@khanacademy/simple-markdown": patch | ||
--- | ||
|
||
Nothing has changed, but our action requires a changeset per package and I don't know how to do an infrastructure update like this and pass that check |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,47 @@ | |
* Pre-publish utilities to verify that our publish will go smoothly. | ||
*/ | ||
|
||
const checkPublishConfig = ({name, publishConfig, private: isPrivate}) => { | ||
const checkPublishConfig = ({ | ||
name, | ||
publishConfig, | ||
private: isPrivate, | ||
scripts, | ||
}): boolean => { | ||
let returnCode = true; | ||
|
||
// first check if is marked as public and there's access to publish the current package | ||
if (!publishConfig || (!isPrivate && publishConfig.access !== "public")) { | ||
const requiredAccessType = isPrivate ? "restricted" : "public"; | ||
|
||
console.error( | ||
`ERROR: ${name} is missing a "publishConfig": {"access": "${requiredAccessType}"} section.`, | ||
); | ||
process.exit(1); | ||
returnCode = false; | ||
} | ||
|
||
// also check if is marked as private and there's restricted access defined | ||
if (isPrivate && publishConfig.access !== "restricted") { | ||
console.error( | ||
`ERROR: ${name} is marked as private but there is a "publishConfig": {"access": "public"} section already defined. Please change it to "access": "restricted" or remove "private": true to make the package public.`, | ||
); | ||
process.exit(1); | ||
returnCode = false; | ||
} | ||
|
||
// check that we are running our pre-publish check for this package | ||
if ( | ||
!scripts.prepublishOnly || | ||
!scripts.prepublishOnly.includes("utils/package-pre-publish-check.sh") | ||
) { | ||
console.error( | ||
`ERROR: ${name} must have a "prepublishOnly" script that runs "utils/package-pre-publish-check.sh".`, | ||
); | ||
returnCode = false; | ||
} | ||
Comment on lines
+31
to
+40
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. Yay. Thanks for adding this check here too!
Comment on lines
+31
to
+40
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. note: New check to make sure all the packages we publish are running our prepublish check to avoid snapshot releases usurping real releases. |
||
return returnCode; | ||
}; | ||
|
||
const checkField = (pkgJson, field, value) => { | ||
const checkField = (pkgJson, field, value): boolean => { | ||
let returnCode = true; | ||
if (Array.isArray(value)) { | ||
if (!value.includes(pkgJson[field])) { | ||
console.error( | ||
|
@@ -32,29 +52,29 @@ const checkField = (pkgJson, field, value) => { | |
.map((value) => JSON.stringify(value)) | ||
.join(", ")}.`, | ||
); | ||
process.exit(1); | ||
} | ||
} else { | ||
if (pkgJson[field] !== value) { | ||
console.error( | ||
`ERROR: ${ | ||
pkgJson.name | ||
} must have a "${field}" set to ${JSON.stringify(value)}.`, | ||
); | ||
process.exit(1); | ||
returnCode = false; | ||
} | ||
} else if (pkgJson[field] !== value) { | ||
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. note: I just changed that nested |
||
console.error( | ||
`ERROR: ${ | ||
pkgJson.name | ||
} must have a "${field}" set to ${JSON.stringify(value)}.`, | ||
); | ||
returnCode = false; | ||
} | ||
return returnCode; | ||
}; | ||
|
||
const checkMain = (pkgJson) => checkField(pkgJson, "main", "dist/index.js"); | ||
const checkMain = (pkgJson): boolean => | ||
checkField(pkgJson, "main", "dist/index.js"); | ||
|
||
const checkModule = (pkgJson) => | ||
const checkModule = (pkgJson): boolean => | ||
checkField(pkgJson, "module", "dist/es/index.js"); | ||
|
||
const checkSource = (pkgJson) => | ||
const checkSource = (pkgJson): boolean => | ||
checkField(pkgJson, "source", ["src/index.js", "src/index.ts"]); | ||
|
||
const checkPrivate = (pkgJson) => { | ||
const checkPrivate = (pkgJson): boolean => { | ||
if (pkgJson.private) { | ||
console.warn( | ||
`${pkgJson.name} is private and won't be published to NPM.`, | ||
|
@@ -64,9 +84,7 @@ const checkPrivate = (pkgJson) => { | |
return false; | ||
}; | ||
|
||
const checkEntrypoints = (pkgJson) => { | ||
checkModule(pkgJson); | ||
checkMain(pkgJson); | ||
}; | ||
const checkEntrypoints = (pkgJson): boolean => | ||
checkModule(pkgJson) && checkMain(pkgJson); | ||
|
||
export {checkPublishConfig, checkEntrypoints, checkSource, checkPrivate}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Check if SNAPSHOT_RELEASE is set and the version does not start with 0.0.0-PR | ||
if [ "$SNAPSHOT_RELEASE" = "1" ] && ! [[ "$npm_package_version" =~ ^0\.0\.0-PR ]]; then | ||
echo "Error: Snapshot publish attempted, but $npm_package_name@$npm_package_version does not match version scheme for snapshots. Publish disallowed." | ||
exit 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,16 +16,25 @@ import { | |
// eslint-disable-next-line promise/catch-or-return | ||
fg(path.join(__dirname, "..", "packages", "*", "package.json")).then( | ||
(pkgPaths) => { | ||
let allPassed = true; | ||
// eslint-disable-next-line promise/always-return | ||
for (const pkgPath of pkgPaths) { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const pkgJson = require(path.relative(__dirname, pkgPath)); | ||
|
||
if (!checkPrivate(pkgJson)) { | ||
checkPublishConfig(pkgJson); | ||
checkEntrypoints(pkgJson); | ||
checkSource(pkgJson); | ||
if ( | ||
!checkPrivate(pkgJson) && | ||
!checkPublishConfig(pkgJson) && | ||
!checkEntrypoints(pkgJson) && | ||
!checkSource(pkgJson) | ||
) { | ||
allPassed = false; | ||
} | ||
} | ||
|
||
// Exit only after we've processed all the packages. | ||
if (!allPassed) { | ||
process.exit(1); | ||
} | ||
Comment on lines
+25
to
+38
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. note: This means we check all the packages for all the things before we quit, rather than quitting on the first error. Makes it easier to do changes to the overall checks and ensure compliance. |
||
}, | ||
); |
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.
OCD-level 10 comment: looks like all the package.json lost their newline at end of file. I'm not sure if that matters, but Github flags it so... 🤷♂️
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.
It doesn't make a difference. I just saved like usual - no idea why this means it doesn't get a newline.