ramda/ramda — pull request #461 by davidchambers (2014-10-20 04:16:42+00:00)
Title: automate release process

There was some discussion of automating the release process in #339. This pull request is my proposed solution.

This pull request adds three release targets to the makefile. If merged, publishing a new release will involve nothing more than running `make release-$LEVEL`.

Below is a walkthrough of what happens when one runs `make release-minor` (to choose a concrete example). I'll keep this up to date as the pull request matures in response to feedback.

1. The `LEVEL` variable in the makefile is assigned the value `minor`.

2. `$(XYZ) --increment $(LEVEL)` is expanded to:

```shell
node_modules/.bin/xyz --repo git@github.com:ramda/ramda.git --script scripts/prepublish --increment minor
```

3. The above command is run.

4. xyz checks that the current branch is `master`. If it is not, xyz will exit with an exit status of 1 after printing the following message to stderr:

```
Current branch does not match specified --branch
```

5. xyz checks that the working directory contains no unstaged changes. If this is not the case, xyz will exit with an exit status of 1 after printing the following message to stderr:

```
Working directory contains unstaged changes
```

6. xyz reads `name` and `version` from __package.json__ and assigns these values to variables.

7. xyz uses the [semver][1] executable to determine the new version string by running:

```shell
"$dir/node_modules/.bin/semver" -i "$increment" "$version"
```

8. xyz presents a confirmation prompt:

```
Current version is 0.6.0. Press [enter] to publish ramda@0.7.0.▌
```

This provides on opportunity to abort by pressing Ctrl-C.

9. xyz runs the prepublish script with appropriate environment variables:

```shell
VERSION=0.7.0 PREVIOUS_VERSION=0.6.0 'scripts/prepublish'
```

10. The prepublish script updates Ramda version strings in __README.md__:

```bash
README="$(cat README.md)"
README="${README//"$PREVIOUS_VERSION/ramda.min.js"/"$VERSION/ramda.min.js"}"
README="${README//"${PREVIOUS_VERSION%.*}/ramda.min.js"/"${VERSION%.*}/ramda.min.js"}"
echo "$README" >README.md
```

11. The prepublish script adds __README.md__ to the index:

```bash
git add README.md
```

12. The prepublish script updates Ramda version strings in __ramda.js__:

```bash
RAMDA="$(cat ramda.js)"
RAMDA="${RAMDA//$PREVIOUS_VERSION/$VERSION}"
echo "$RAMDA" >ramda.js
```

13. The prepublish script adds __ramda.js__ to the index:

```bash
git add ramda.js
```

14. The prepublish script runs `make ramda.min.js`.

15. Make expands the body of the target to:

```shell
node_modules/.bin/uglifyjs --compress --mangle --preamble '/*! ramda 2014-10-19 */' <'ramda.js' >'ramda.min.js'
```

The current date will appear in place of `2014-10-19`.

16. The prepublish script adds __ramda.min.js__ to the index.

17. xyz updates `version` in __package.json__ and __bower.json__, and adds these files to the index.

18. xyz runs `git commit --message 'Version 0.7.0'`.

19. xyz runs `git tag --annotate 'v0.7.0' --message 'Version 0.7.0'`.

20. xyz runs `git push 'git@github.com:ramda/ramda.git' 'refs/heads/master' 'refs/tags/v0.7.0'`.

21. xyz runs `npm publish`.

---

### What this release process does *not* do

This does not create nifty GitHub release thingamajigs (à la [ramda/ramda/releases][2]). Instead, it creates run-of-the-mill releases (à la [davidchambers/xyz/releases][3]). I don't know whether the fancy release notes are a GitHub-specific feature or whether GitHub is exposing Git functionality. I suspect the former, but I'll read about the feature to find out.

[1]: https://www.npmjs.org/package/semver
[2]: https://github.com/ramda/ramda/releases
[3]: https://github.com/davidchambers/xyz/releases