|
| 1 | +# Version check |
| 2 | + |
| 3 | +You can use this GitHub action to check whether your npm package version has been updated: this can be extremely helpful if you want to automate your release process. |
| 4 | +The main difference between this action and many others out there is that this doesn't do a specific task (it doesn't publish to registries, create tags or releases, send notifications, ...) but instead gives you an output that you can use in other steps of your workflow as you prefer: this way you don't have to deal with stuff you don't care about ;) |
| 5 | + |
| 6 | +This action is heavily inspired by [`npm-publish-action`](https://github.com/pascalgn/npm-publish-action) by [pascal](https://github.com/pascalgn): if you only care about publishing your package to npm automatically, this is the simplest solution :thumbsup: |
| 7 | + |
| 8 | +## Usage |
| 9 | + |
| 10 | +You have to set up a step like this in your workflow (this assumes you've already [checked out](https://github.com/actions/checkout) your repo and [set up Node](https://github.com/actions/setup-node)): |
| 11 | + |
| 12 | +```yaml |
| 13 | +- name: Check if version has been updated # You can edit this |
| 14 | + id: check # This will be the reference for getting the outputs |
| 15 | + uses: EndBug/[email protected] # You can choose teh version/branch you prefer |
| 16 | + with: # You can find more info about inputs below |
| 17 | + file-name: package.json |
| 18 | + diff-search: true |
| 19 | +``` |
| 20 | +
|
| 21 | +### Inputs |
| 22 | +
|
| 23 | +- `file-name` (optional) : you can use this to indicate a custom path to your `package.json`; if you keep your package file in the root directory (as every normal person would do) you can omit this. |
| 24 | +- `diff-search` (optional) : whether to search in every commit's diff. This is useful if you often do change the version manually without including it in the title: you can find more info on how the action detects the version change [here](doc/logic_chain.md). If you only use `npm version` to bump versions then you can omit this. |
| 25 | + |
| 26 | +### Outputs |
| 27 | + |
| 28 | +This action sets two outputs: |
| 29 | + |
| 30 | +- `changed` : either "true" or "false", indicates whether the version has changed. |
| 31 | +- `type` : if the version has changed, it tries to find the type of bump (e.g. "patch", "minor", ...) |
| 32 | + |
| 33 | +To access these outputs, you need to access the context of the step you previously set up: you can find more info about steps contexts [here](https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions#steps-context). |
| 34 | +If you set your step id to `check` you'll find the outputs at `steps.check.outputs.changed` and `steps.check.outputs.type`: you can use these outputs as conditions for other steps. |
| 35 | +Here's an example: |
| 36 | + |
| 37 | +```yaml |
| 38 | +- name: Check if version has been updated |
| 39 | + id: check |
| 40 | + |
| 41 | +
|
| 42 | +- name: Log when changed |
| 43 | + if: steps.check.outputs.changed == 'true' |
| 44 | + run: 'echo "Version change! -> ${{ steps.check.outputs.type }}"' |
| 45 | +
|
| 46 | +- name: Log when unchanged |
| 47 | + if: steps.check.outputs.changed != 'true' |
| 48 | + run: 'echo "No version change :/"' |
| 49 | +``` |
| 50 | + |
| 51 | +## License |
| 52 | + |
| 53 | +This action is distributed under the MIT license, check the [license](LICENSE) for more info. |
0 commit comments