Skip to content

Commit b80e788

Browse files
Add prepublish checks to block releases of non-snapshot versionsfirst one (#2037)
## Summary: This PR implements a simple preventative measure for the race condition described by https://khanacademy.atlassian.net/wiki/spaces/ENG/pages/3571646568/Race+condition+breaks+Perseus+release whereby an in progress release triggered via merging a changesets PR and a snapshot release triggered by a PR update can lead to a snapshot releasing an actual versioned release. The events that cause this look something like: 1. Version Packages merged, updating versions in `main` 2. Someone updates their PR with a merge of `main`, updating its versions to the ones in `main` that are not yet published 3. The PR action to publish a snapshot runs, but the main release isn't done yet so the new releases aren't present in NPM 4. The snapshot release tries to publish those packages before the main release has tried This change should prevent that last step; failing the snapshot release. We could look at trying other ways to prevent this, such as making the `release.yml`` workflow responsible for snapshot releases too and limit concurrency. However, even that won't fully prevent this since the merge of the "Version Packages" PR does not guarantee the run order of the release workflow and the snapshot workflow. So, this helps prevent the incorrect publish occurring without impacting the official release process - only PR snapshot releases get affected in the cases where this might occur (which seem to be rare, for now). This update also modifies our pre-publish checks to look for all errors before quitting, instead of quitting on the first one. This is a quality of life change for devs that modify this script and need to check all packages are passing without having to run, then fix, then run, then fix, repeatedly. Issue: XXX-XXXX ## Test plan: I ran `SNAPSHOT_RELEASE=1 npm publish --dry-run` on a package that had a non-snapshot release version, and it failed as expected. I also ran it on a package that had the correct `0.0.0-PR...` format, and it succeeded. I also ran a `npm publish --dry-run` on a package without the `SNAPSHOT_RELEASE` env var, and it succeeded. Author: somewhatabstract Reviewers: jeremywiebe, somewhatabstract, jandrade Required Reviewers: Approved By: jeremywiebe Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x) Pull Request URL: #2037
1 parent b52310d commit b80e788

File tree

16 files changed

+106
-37
lines changed

16 files changed

+106
-37
lines changed

.changeset/lemon-maps-explain.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.changeset/rotten-squids-act.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@khanacademy/kas": patch
3+
"@khanacademy/keypad-context": patch
4+
"@khanacademy/kmath": patch
5+
"@khanacademy/math-input": patch
6+
"@khanacademy/perseus": patch
7+
"@khanacademy/perseus-core": patch
8+
"@khanacademy/perseus-editor": patch
9+
"@khanacademy/perseus-linter": patch
10+
"@khanacademy/pure-markdown": patch
11+
"@khanacademy/simple-markdown": patch
12+
---
13+
14+
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

packages/kas/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dist"
2323
],
2424
"scripts": {
25+
"prepublishOnly": "../../utils/package-pre-publish-check.sh",
2526
"gen:parsers": "node src/parser-generator.ts",
2627
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
2728
},
@@ -43,4 +44,4 @@
4344
"algebra",
4445
"symbolic"
4546
]
46-
}
47+
}

packages/keypad-context/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dist"
2323
],
2424
"scripts": {
25+
"prepublishOnly": "../../utils/package-pre-publish-check.sh",
2526
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
2627
},
2728
"dependencies": {
@@ -34,4 +35,4 @@
3435
"react": "^18.2.0"
3536
},
3637
"keywords": []
37-
}
38+
}

packages/kmath/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dist"
2222
],
2323
"scripts": {
24+
"prepublishOnly": "../../utils/package-pre-publish-check.sh",
2425
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
2526
},
2627
"dependencies": {
@@ -34,4 +35,4 @@
3435
"underscore": "1.4.4"
3536
},
3637
"keywords": []
37-
}
38+
}

packages/math-input/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"files": [
3737
"dist"
3838
],
39-
"scripts": {},
39+
"scripts": {
40+
"prepublishOnly": "../../utils/package-pre-publish-check.sh"
41+
},
4042
"dependencies": {
4143
"@khanacademy/keypad-context": "^1.0.9",
4244
"@khanacademy/perseus-core": "3.0.3",
@@ -78,4 +80,4 @@
7880
"react-transition-group": "^4.4.1"
7981
},
8082
"keywords": []
81-
}
83+
}

packages/perseus-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dist"
2323
],
2424
"scripts": {
25+
"prepublishOnly": "../../utils/package-pre-publish-check.sh",
2526
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
2627
},
2728
"dependencies": {},
@@ -30,4 +31,4 @@
3031
},
3132
"peerDependencies": {},
3233
"keywords": []
33-
}
34+
}

packages/perseus-editor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"dist"
3232
],
3333
"scripts": {
34+
"prepublishOnly": "../../utils/package-pre-publish-check.sh",
3435
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
3536
},
3637
"dependencies": {
@@ -99,4 +100,4 @@
99100
"underscore": "^1.4.4"
100101
},
101102
"keywords": []
102-
}
103+
}

packages/perseus-linter/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dist"
2323
],
2424
"scripts": {
25+
"prepublishOnly": "../../utils/package-pre-publish-check.sh",
2526
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
2627
},
2728
"dependencies": {
@@ -35,4 +36,4 @@
3536
"prop-types": "15.6.1"
3637
},
3738
"keywords": []
38-
}
39+
}

packages/perseus/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"dist"
3838
],
3939
"scripts": {
40+
"prepublishOnly": "../../utils/package-pre-publish-check.sh",
4041
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
4142
},
4243
"dependencies": {
@@ -124,4 +125,4 @@
124125
"underscore": "^1.4.4"
125126
},
126127
"keywords": []
127-
}
128+
}

0 commit comments

Comments
 (0)