Skip to content
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

feat(dev-tools): add new modes to ocular-publish #461

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
dist/

.idea/
.nx/
yarn-error.log
.DS_Store
.vscode/
Expand Down
3 changes: 3 additions & 0 deletions modules/dev-tools/docs/cli/ocular-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ npx ocular-publish [mode] [npm-tag]

- `beta` - bump pre-release version and publish with beta flag.
- `prod` - bump patch version and publish.
- `version-beta` - bump pre-release version only.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These docs looks quite terse, perhaps we can be a bit more verbose. Without reading the source I can't quite tell what these do.

Nit: The docs make it look like these two modules don't actually publish? If that is true, should we call them ocular-bump instead of ocular-publish then? or maybe ocular-publish bump-beta or ocular-publish bump beta ocular-publish bump-only beta

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In npm, yarn, and lerna, the "version" verb means incrementing the release number, and the "publish" verb means pushing that change to a registry. A postversion script might also run publish if projects prefer to do it all in one step, which seems common.

I'd prefer if ocular could reuse these terms as much as possible — "bump" has no precise meaning to me.

I do see your point that ocular-publish version-beta feels unclear, though...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use two words as the second argument is currently used as a custom NPM dist tag. This can of course change because it's not actively used by any repo and it seems like we are going with publishConfig.tag instead (I think that's a better approach).

Otherwise, does version-only-beta sound better?

- `version-prod` - bump patch version only.
- `from-git`: publish from the current git tag.
Pessimistress marked this conversation as resolved.
Show resolved Hide resolved

## npm-tag

Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.0.0",
"glob": "^7.1.4",
"lerna": "^3.14.1",
"lerna": "^8.1.0",
"minimatch": "^3.0.0",
"prettier": "3.0.3",
"prettier-check": "2.0.0",
Expand Down
144 changes: 73 additions & 71 deletions modules/dev-tools/scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,86 @@ usage() {
open "https://uber-web.github.io/ocular/docs/dev-tools/cli/ocular-publish"
}

BASEDIR=$(dirname "$0")
# beta, prod, version-beta or version-prod
MODE=$1

ocular-bootstrap
ocular-test
ocular-test dist
bumpVersion() {
local versionType
if [[ $1 == "beta" ]]; then
versionType=prerelease
else
versionType=patch
fi

# beta or prod
MODE=$1
# custom tag
TAG=$2
if [ -d "modules" ]; then
(set -x; lerna version $versionType --force-publish --exact --no-commit-hooks)
else
# -f includes any changes in the version commit
(set -x; npm version $versionType --force)
# push to branch
(set -x; git push && git push --tags)
fi
}

if [ -d "modules" ]; then
case $MODE in
"help")
usage
;;
publishToNPM() {
local tag=$1
if [ -d "modules" ]; then
if [ -z $tag ]; then
# use default tag ('latest' or publishConfig.tag in package.json)
(set -x; lerna publish from-git --force-publish --no-commit-hooks)
else
(set -x; lerna publish from-git --force-publish --dist-tag $tag --no-commit-hooks)
fi
else
if [ -z $tag ]; then
(set -x; npm publish)
else
(set -x; npm publish --tag $tag)
fi
fi
}

"beta")
# npm-tag argument: npm publish --tag <beta>
# cd-version argument: increase <prerelease> version
if [ -z "$TAG" ]
then
(set -x; lerna publish prerelease --force-publish --exact --dist-tag beta --no-commit-hooks)
else
(set -x; lerna publish prerelease --force-publish --exact --dist-tag $TAG --no-commit-hooks)
fi
;;
if [[ $MODE != "version-"* && $MODE != "help" ]]; then
# will build and publish to NPM
ocular-bootstrap
ocular-test
ocular-test dist
fi

"prod")
if [ -z "$TAG" ]
then
# latest
(set -x; lerna publish patch --force-publish --exact --no-commit-hooks)
else
(set -x; lerna publish patch --force-publish --exact --dist-tag $TAG --no-commit-hooks)
fi
;;
case $MODE in
"help")
usage
;;

*)
echo -e "\033[91mUnknown publish mode. ocular-publish ['prod' | 'beta']\033[0m"
exit 1;;
esac
else
case $MODE in
"help")
usage
;;
"version-beta")
bumpVersion beta
;;

"beta")
# -f includes any changes in the version commit
(set -x; npm version prerelease --force)
# push to branch
(set -x; git push && git push --tags)
if [ -z "$TAG" ]
then
(set -x; npm publish --tag beta)
else
(set -x; npm publish --tag $TAG)
fi
;;
"version-prod")
bumpVersion prod
;;

"prod")
# -f includes any changes in the version commit
(set -x; npm version patch --force)
# push to branch
(set -x; git push && git push --tags)
"beta")
bumpVersion beta
publishToNPM ${2:-beta}
;;

if [ -z "$TAG" ]
then
# latest
(set -x; npm publish)
else
(set -x; npm publish --tag $TAG)
fi
;;
"prod")
bumpVersion beta
publishToNPM $2
;;

*)
echo -e "\033[91mUnknown publish mode. ocular-publish ['prod' | 'beta']\033[0m"
exit 1;;
esac
fi
"from-git")
# publish from existing tag
gitTag=$(git describe)
if [[ $gitTag == *"-"* ]]; then
publishToNPM ${2:-beta}
else
publishToNPM $2
fi
;;

*)
echo -e "\033[91mUnknown publish mode. ocular-publish ['prod' | 'beta' | 'version-prod' | 'version-beta' | 'from-git']\033[0m"
exit 1;;
esac
Loading
Loading