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

chore(repo): add --local to release and publish script #2323

Merged
merged 1 commit into from
Jan 20, 2020

Conversation

juristr
Copy link
Member

@juristr juristr commented Jan 16, 2020

The best way to test fully test new Nx builds locally (especially migrations etc) is by releasing it to a local npm repo.

This PR adds some flags to the nx-release.js as well as publish.sh to automate some parts of the local release.

How does it work

Install Verdaccio & set it up

Installing Verdaccio is quite simple. Just add it as a global package:

$ npm install -g verdaccio
// or
$ yarn global add verdaccio

(Using Docker could be an alternative. There's an official docker image for it)

Run it with

$ verdaccio

image

Setup a dummy user:

$ npm adduser --registry http://localhost:4873

You can just use username: nrwl, pwd:nrwl and email: a@a.com.

Set the npm registry

Make your yarn & npm registry point to the local Verdaccio server with

$ npm config set registry http://localhost:4873
$ yarn config set registry http://localhost:4873/

You can always roll it back to the originals with

$ npm config delete registry
$ yarn config delete registry

I've created a simple script for that in case (which you can add to your PATH):

// setNpmReg.sh
#!/usr/bin/env bash

LOCALBUILD=$1

if [ "$LOCALBUILD" = "--local" ]; then
	echo "Setting registry to http://localhost:4873/"
	npm config set registry http://localhost:4873/
	yarn config set registry http://localhost:4873/
else
	npm config delete registry
	yarn config delete registry
	CURRENT_NPM_REGISTRY=`npm config get registry`
	CURRENT_YARN_REGISTRY=`yarn config get registry`
	
	echo "Reverting registries"
	echo "  > NPM:  $CURRENT_NPM_REGISTRY"
	echo "  > YARN: $CURRENT_YARN_REIGSTRY"
fi

Releasing a new Nx version locally

First make sure you set the NPM / Yarn registry

With this PR, to release a new version locally, just do

$ yarn nx-release 8.12.0-beta.104 --local

The release-it process will ask a couple of questions:

  • Ready to release 8.12.0-beta.105? => y
  • Show staged files? => y (or no, doesn't really matter)
  • Commit (Release 8.12.0-beta.105)? => n
  • Tag (8.12.0-beta.105)? => n
  • Push? => n
  • Create a release on GitHub (Release 8.12.0-beta.105)? => n

When asked for the credentials, just add the one of ur local repo (i.e. nrwl:nrwl)

You can then go to http://localhost:4873 which opens Verdaccio's web interface to see the published versions

image

Want to delete all locally published packages (for whatever reason)?

All the packages are stored in Verdaccio's storage folder which (if you didn't change it) by default resides in ~/.local/share/verdaccio/storage.

As a result, executing...

$ rm -rf ~/.local/share/verdaccio/storage/@nrwl/

...removes all @nrwl packages

This allows for easier publishing to a local npm registry (i.e. Verdaccio)
@juristr juristr force-pushed the automate-local-nx-release branch from 8248414 to 596b169 Compare January 16, 2020 09:22
@catfireparty
Copy link
Contributor

This looks really useful. I'd consider putting all the instructions you've added above into a readme, perhaps linked from the contributing document?

@juristr
Copy link
Member Author

juristr commented Jan 16, 2020

@jdpearce absolutely. Once we agree on this being useful, I definitely go and update either the CONTRIBUTIONS.md or somewhere else to have these instructions persisted 👍

Copy link
Collaborator

@FrozenPandaz FrozenPandaz left a comment

Choose a reason for hiding this comment

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

This looks good as is. It's going to be very useful for testing create-nx-workspace and migrations.

For future work, is it possible to create a .npmrc file inside this repository so people don't have to setup verdaccio?

@juristr
Copy link
Member Author

juristr commented Jan 20, 2020

For future work, is it possible to create a .npmrc file inside this repository so people don't have to setup verdaccio?

@FrozenPandaz I can take that on my list of future improvements for this. Just to be more clear, you would add a local .npmrc to avoid having to set the "global" one, right? Not sure how that'd work, but I'd like to discuss if you have more insights. The main reasoning is the following: we could have a local .npmrc probably, even set that during the script execution. However, some local npm proxy would still have to run (i.e. Verdaccio). We could even have that as a dev-dep in the repo and launch it as well during publishing. The thing is: when do you then stop it again? Because if you want to test the package & install it from the local repo from some other workspace on your machine, you'd have to have Verdaccio still respond, and at that point you'd even have to have the global .npmrc file configured properly I guess. But happy to discuss this 😃

Another improvement I'd like to add is to customize the releaseIt options s.t. when doing a --local build, s.t. you don't get all the questions about tagging, pushing to GitHub etc..which you wouldn't want to do anyways when testing locally.

@FrozenPandaz FrozenPandaz merged commit 7729879 into nrwl:master Jan 20, 2020
@juristr juristr deleted the automate-local-nx-release branch April 9, 2020 12:14
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants