diff --git a/RELEASE.md b/RELEASE.md index 4b4c98a..03e4e33 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -12,8 +12,30 @@ Releasing the project requires these steps: node scripts/release/release.js minor ``` -2. The above release script should automatically update the package version and regenerate assets in ```dist``` & ```lib``` folders. Once assets are regenerated the script commits and tags the changes and will push them to remote and `npm publish` will be triggered automatically. -3. Once publish is complete make sure it's uploaded to [npm][project-url] +2. The above release script should automatically update the package version and regenerate assets in ```dist``` & ```lib``` folders. Once assets are regenerated the script commits the changes to a new branch and will push them to remote. Go to the branch repository on GitHub and create a PR from the newly created branch to the `master` branch. Once the PR is approved, merge it into the `master` branch. + +## Publishing the Package + +After the PR is created and merged into the `master` branch, follow these steps to publish the npm package: + +1. **Pull the latest changes from the `master` branch**: + ``` + git checkout master + git pull origin master + ``` + +2. **Create a tag and push the tag**: + ``` + git tag v{x.x.x} # Replace {x.x.x} with the next release version + git push origin v{x.x.x} # Replace {x.x.x} with the next release version + ``` + +3. **Publish the package to the npm registry**: + ``` + npm publish + ``` + +4. Once publish is complete make sure it's uploaded to [npm][project-url] Further explanation on the automated steps behind the ```release.js``` script can be found [here][release-documentation] diff --git a/package.json b/package.json index 59def8b..2d0a3aa 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "prepublishOnly": "npm whoami && npm test", "preversion": "npm run test", "version": "npm run build && git add -A", - "postversion": "git push && git push --tags && rm -rf build/temp", "release:major": "node ./scripts/release/release.js major", "release:minor": "node ./scripts/release/release.js minor", "release:patch": "node ./scripts/release/release.js patch" diff --git a/scripts/release/README.md b/scripts/release/README.md index bbb3da7..33f266f 100644 --- a/scripts/release/README.md +++ b/scripts/release/README.md @@ -11,23 +11,23 @@ Once the above ```node``` command gets executed the following takes place automa 1. Tests are triggered with the old version 2. Package version is updated based on the change type provided to the ```node``` command (e.g major, minor, patch, etc) 3. The library/package is rebuilt using new version to regenerate ```lib``` and ```dist``` folders (this includes running tests with new lib version) -4. All latest changes are commited and tagged. -5. Commits and updated tags are pushed to the origin. -6. The package publish mechanism is triggered +4. A new branch is created for the version bump. +5. All latest changes are commited and tagged. +6. A commit with the updated version is pushed to the new branch. +7. manually create a PR from the new branch to the master. -Steps 1-5 are accomplished using the following scripts in ```package.json``` : + +Steps 1-6 are accomplished using the following scripts in ```package.json``` and release.js : ``` "preversion": "npm run test", "version": "npm run build && git add -A", -"postversion": "git push && git push --tags && rm -rf build/temp", ``` ## Testing the release process: While modifying the scripts if in doubt you can always test the release process in a separate branch using the following steps without publishing the library: 1. Clone the project and create a new branch 2. Run ```npm install``` -3. Modify the release script to temporarily remove : ```&& npm publish``` from line 8 of the release script. -4. Run ```node scripts/release/release.js minor``` -5. It should perform the above listed release process steps and push the changes to your branch at origin. -6. Ensure the package version has been updated in ```package.json``` and ```package-lock.json```. The ```dist``` and ```lib``` folders should include files created with the updated version no. +3. Run ```node scripts/release/release.js minor``` +4. It should perform the above listed release process steps and push the changes to your branch at origin. +5. Ensure the package version has been updated in ```package.json``` and ```package-lock.json```. The ```dist``` and ```lib``` folders should include files created with the updated version no. diff --git a/scripts/release/release.js b/scripts/release/release.js index d655a09..317a437 100644 --- a/scripts/release/release.js +++ b/scripts/release/release.js @@ -3,9 +3,24 @@ const shell = require('shelljs'); const releaseType = process.argv[2] || 'patch'; -// npm version triggers scripts added in package.json to test, build, commit, tag and push changes with version update to git. +const newBranch = `release-${releaseType}-${new Date().toISOString().slice(0, 10)}`; + +// Checkout a new branch +if (shell.exec(`git checkout -b ${newBranch}`).code !== 0) { + shell.echo('Error: Git branch creation failed'); + shell.exit(1); +} + +// Run npm version to bump the version and create a commit.npm version triggers scripts added in package.json to test, build, commit, tag and push changes with version update to git. // If the tests fail when ran with preversion script entire release will fail. -if (shell.exec(`npm version ${releaseType} -m "Tagged and released version %s" && npm publish`).code !== 0) { +if (shell.exec(`npm version ${releaseType} -m "Tagged and released version %s"`).code !== 0) { + shell.echo('Error: Version bump failed'); + shell.exit(1); +} + +// Push the new branch to remote +if (shell.exec(`git push origin ${newBranch}`).code !== 0) { + shell.echo('Error: Git push failed'); shell.exit(1); }