Skip to content

Commit

Permalink
[fei6062.releaseprotections] Update prepublish checks to add SNAPSHOT…
Browse files Browse the repository at this point in the history
…_RELEASE support (#2412)

## Summary:
This brings over the latest updates from Perseus, and edits them for Wonder Blocks. The changes are:

1. New `prepublishOnly` script in each package that blocks publishing non-snapshot packages when publishing snapshots
2. Updates 'publish-snapshot.sh' to set the `SNAPSHOT_RELEASE` env var
3. Updates `pre-publish-check-ci.js` and `pre-publish-utils.js` files to TypeScript
4. Makes `pre-publish-check-ci.ts` executable
5. Adds a check to `pre-publish-check-ci.ts` to ensure that each public package has the `prepublishOnly` script
6. Updates `pre-publish-utils.ts` and `pre-publish-check-ci.ts` to perform all checks before erroring, instead of quitting on the first failure. This is a quality of life change to make it easier on devs having to update multiple packages to conform

Long term, might be nice to have a `wonder-stuff-cli` or something that can encapsulate this stuff across our packages.

This change adds initial protection against accidentally publishing release package versions under a snapshot tag. It protects both automated runs and runs done by a user locally.

The next PR will add workflow changes to block the snapshot publish jobs from running when there is a release workflow in progress. This adds an additional layer of protection and also provides a nicer dev experience by adding a useful PR comment on why it failed.

### Methodology:
I diffed the Perseus and Wonder Blocks scripts to work out what was different, then updated things to TS. I then modified the publish script and workflows, as necessary. Finally, I used Copilot Edits in VSCode to update the package.json files with the new `prepublishOnly` script.

Issue: FEI-6062

## Test plan:
This stuff is working in Perseus already. I've tested the new executable nature of the pre-publish checks, and verified the `SNAPSHOT_RELEASE` behavior for packages by running `SNAPSHOT_RELEASE=1 yarn run prepublishOnly` in a few packages.

Author: somewhatabstract

Reviewers: somewhatabstract, jandrade

Required Reviewers:

Approved By: jandrade

Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Test / Test (ubuntu-latest, 20.x, 2/2), ✅ Test / Test (ubuntu-latest, 20.x, 1/2), ✅ Lint / Lint (ubuntu-latest, 20.x), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ⏭️  Chromatic - Skip on Release PR (changesets), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏭️  dependabot, ✅ gerald

Pull Request URL: #2412
  • Loading branch information
somewhatabstract authored Dec 20, 2024
1 parent c58e3fa commit 11a0f5c
Show file tree
Hide file tree
Showing 43 changed files with 286 additions and 135 deletions.
35 changes: 35 additions & 0 deletions .changeset/good-stingrays-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
"@khanacademy/wonder-blocks-progress-spinner": patch
"@khanacademy/wonder-blocks-birthday-picker": patch
"@khanacademy/wonder-blocks-labeled-field": patch
"@khanacademy/wonder-blocks-search-field": patch
"@khanacademy/wonder-blocks-testing-core": patch
"@khanacademy/wonder-blocks-breadcrumbs": patch
"@khanacademy/wonder-blocks-icon-button": patch
"@khanacademy/wonder-blocks-typography": patch
"@khanacademy/wonder-blocks-accordion": patch
"@khanacademy/wonder-blocks-clickable": patch
"@khanacademy/wonder-blocks-dropdown": patch
"@khanacademy/wonder-blocks-popover": patch
"@khanacademy/wonder-blocks-testing": patch
"@khanacademy/wonder-blocks-theming": patch
"@khanacademy/wonder-blocks-toolbar": patch
"@khanacademy/wonder-blocks-tooltip": patch
"@khanacademy/wonder-blocks-banner": patch
"@khanacademy/wonder-blocks-button": patch
"@khanacademy/wonder-blocks-layout": patch
"@khanacademy/wonder-blocks-switch": patch
"@khanacademy/wonder-blocks-timing": patch
"@khanacademy/wonder-blocks-tokens": patch
"@khanacademy/wonder-blocks-modal": patch
"@khanacademy/wonder-blocks-cell": patch
"@khanacademy/wonder-blocks-core": patch
"@khanacademy/wonder-blocks-data": patch
"@khanacademy/wonder-blocks-form": patch
"@khanacademy/wonder-blocks-grid": patch
"@khanacademy/wonder-blocks-icon": patch
"@khanacademy/wonder-blocks-link": patch
"@khanacademy/wonder-blocks-pill": patch
---

No functional changes. Adding prepublishOnly script.
2 changes: 2 additions & 0 deletions .changeset/perfect-pens-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion .github/workflows/node-ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ jobs:
run: yarn build:types

- name: Check package.json files
run: node utils/publish/pre-publish-check-ci.js
run: ./utils/publish/pre-publish-check-ci.ts
5 changes: 5 additions & 0 deletions .github/workflows/node-ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
with:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Get changed files
uses: Khan/actions@get-changed-files-v2
id: changed
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lint:watch": "esw --watch --config ./eslint/eslintrc packages",
"lint": "yarn lint:ci .",
"lint:ci": "eslint --ext .ts --ext .js --ext .tsx --ext .jsx",
"publish:ci": "yarn run lint:pkg-json && node utils/publish/pre-publish-check-ci.js && git diff --stat --exit-code HEAD && yarn build && yarn build:types && changeset publish",
"publish:ci": "yarn run lint:pkg-json && ./utils/publish/pre-publish-check-ci.ts && git diff --stat --exit-code HEAD && yarn build && yarn build:types && changeset publish",
"start": "yarn start:storybook",
"start:storybook": "storybook dev -p 6061",
"test:common": "yarn run build && yarn run lint && yarn run typecheck && yarn run alex",
Expand Down Expand Up @@ -81,6 +81,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
"alex": "^11.0.0",
"ancesdir": "^6.0.0",
"babel-jest": "^29.7.0",
"babel-loader": "^8.2.3",
"babel-plugin-dynamic-import-node": "^2.3.3",
Expand Down Expand Up @@ -149,4 +150,4 @@
"strip-ansi": "6.0.1",
"strip-ansi-explanation": "There's an issue with strip-ansi v7 which causes conflicts with the Khan/changeset-per-package action"
}
}
}
3 changes: 2 additions & 1 deletion packages/wonder-blocks-accordion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "dist/es/index.js",
"source": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"types": "dist/index.d.ts",
"author": "",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-banner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-birthday-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"dependencies": {
"@babel/runtime": "^7.18.6",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-breadcrumbs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-cell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"dependencies": {
"@babel/runtime": "^7.18.6",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-clickable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"dependencies": {
"@babel/runtime": "^7.18.6"
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"dependencies": {
"@babel/runtime": "^7.18.6",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-dropdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-icon-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-icon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-labeled-field/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"dependencies": {
"@babel/runtime": "^7.18.6",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"types": "dist/index.d.ts",
"module": "dist/es/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-pill/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"types": "dist/index.d.ts",
"source": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-popover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-progress-spinner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-search-field/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-switch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-testing-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"dependencies": {
"@babel/runtime": "^7.18.6"
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"dependencies": {
"@babel/runtime": "^7.18.6",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-theming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"dependencies": {},
"peerDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-timing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"peerDependencies": {
"react": "18.2.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-toolbar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-tooltip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/wonder-blocks-typography/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
},
"author": "",
"license": "MIT",
Expand Down
7 changes: 7 additions & 0 deletions utils/publish/package-pre-publish-check.sh
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
Loading

0 comments on commit 11a0f5c

Please sign in to comment.