Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Stop Worrying and Let the Robot Publish to NPM

Evan Tahler
September 02, 2020

Stop Worrying and Let the Robot Publish to NPM

Managing and Automating Package Testing and Releases

For CascadiaJS 2020

https://github.com/evantahler/cascadiajs

Evan Tahler

September 02, 2020
Tweet

More Decks by Evan Tahler

Other Decks in Technology

Transcript

  1. Stop Worrying and Let the Robot Publish to NPM Managing

    and Automating Package Testing and Releases @evantahler - Grouparoo
  2. 02 Metaphors How can we apply the best ideas about

    deployment and release management to our NPM packages?
  3. CONTINUOUS INTEGRATION & CONTINUOUS DEPLOYMENT CI - Merge back to

    the ‘integration branch’ often Small units of work Tests to know that the feature is done & that it will continue to work CD - Deploy the ‘integration branch’ often Allows for ‘human’ testing and acceptance The real ‘end-to-end’ testing of the work Determines if the work can go to users (production)
  4. CONTINUOUS INTEGRATION & CONTINUOUS DEPLOYMENT CI - Merge back to

    the ‘integration branch’ often Small units of work Tests to know that the feature is done & that it will continue to work CD - Deploy the ‘integration branch’ often Allows for ‘human’ testing and acceptance The real ‘end-to-end’ testing of the work Determines if the work can go to users (production) Testing Builds Confidence
  5. NPM FLOW! (™) Feature Branch v1.0.0-feature.0
For Package Developers Integration Branch

    v0.9.0-alpha.1 v0.9.0-alpha.2 v1.0.0-alpha.0 v1.0.0-alpha.1
For Testers Stable Branch v0.9.0 v1.0.0
For Package Consumers
  6. Metaphors GIT FLOW Git Branches NPM FLOW NPM Tags Example

    Projects #next tag #latest tag CI/CD Review Apps Staging Server Production Deploy
  7. `NPM PREPARE` LIFECYCLE HOOK “Run both BEFORE the package is

    packed and published, on local npm install without any arguments, and when installing git dependencies (See below). This is run AFTER prepublish, but BEFORE prepublishOnly”
  8. `NPM PREPARE` LIFECYCLE HOOK “Run both BEFORE the package is

    packed and published, on local npm install without any arguments, and when installing git dependencies (See below). This is run AFTER prepublish, but BEFORE prepublishOnly”
  9. `NPM VERSION` ON CI AND BACK AGAIN Custom NPM Version

    Commands: npm version prepatch --preid=alpha --message “[no ci] new version!!!” Based on the Branch Name or Feature
  10. `NPM VERSION` ON CI AND BACK AGAIN Custom NPM Version

    Commands: npm version prepatch --preid=alpha --message “[no ci] new version!!!” Based on the Branch Name or Feature Grant CI Access to NPM: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc Generate a NPM Auth Token on npmjs.org
  11. `NPM VERSION` ON CI AND BACK AGAIN Custom NPM Version

    Commands: npm version prepatch --preid=alpha --message “[no ci] new version!!!” Based on the Branch Name or Feature Grant CI Access to NPM: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc Generate a NPM Auth Token on npmjs.org Push to NPM: npm publish --tag alpha Or use custom tags for your branch
  12. `NPM VERSION` ON CI AND BACK AGAIN Custom NPM Version

    Commands: npm version prepatch --preid=alpha --message “[no ci] new version!!!” Based on the Branch Name or Feature Grant CI Access to NPM: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc Generate a NPM Auth Token on npmjs.org Push to NPM: npm publish --tag alpha Or use custom tags for your branch Push the new version back to Git: git push && git push --tags Only on the Integration Branch Make sure CI has access to Git. You can usual use a commit message [no ci] to prevent loops
  13. PRODUCTION === STABLE BRANCH When on the Stable Branch: Make

    a new ‘release’ tag: npm version patch Grant CI Access to NPM: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc Push to NPM: npm publish --tag latest (or skip the --tag) Push the new version back to Git: git checkout master && git rebase stable && git push && git push --tags
  14. PRODUCTION === STABLE BRANCH When on the Stable Branch: Make

    a new ‘release’ tag: npm version patch Grant CI Access to NPM: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc Push to NPM: npm publish --tag latest (or skip the --tag) Push the new version back to Git: git checkout master && git rebase stable && git push && git push --tags human discretion here
  15. PRODUCTION === STABLE BRANCH When on the Stable Branch: Make

    a new ‘release’ tag: npm version patch Grant CI Access to NPM: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc Push to NPM: npm publish --tag latest (or skip the --tag) Push the new version back to Git: git checkout master && git rebase stable && git push && git push --tags human discretion here Or maybe semantic-release
  16. NPM FLOW! (™) Feature Branch v1.0.0-feature.0
For Package Developers Integration Branch

    v0.9.0-alpha.1 v0.9.0-alpha.2 v1.0.0-alpha.0 v1.0.0-alpha.1
v1.0.1-alpha.0 v1.0.1-alpha.1 v1.0.2-alpha.0
For Testers Stable Branch v0.9.0 v1.0.0
v1.0.1
For Package Consumers
  17. Stop Worrying and Let the Robot Publish to NPM 
Thank

    You All my Co-workers & Grouparoo SlidesGo, Flaticon, Freepik BenSound.com Unsplash Carbon.now.sh NPM (Sorry!) Code: github.com/evantahler/cascadiajs