1 | # auto CLI
|
2 |
|
3 | `auto` is a tool designed to seamlessly automate the release workflow.
|
4 | It is powered by [semantic version](https://semver.org/) labels on pull requests.
|
5 | This approach does not require you to change your code or make any drastic changes to your current workflow.
|
6 |
|
7 | While intended to run in a continuous integration (CI) environment, all `auto` commands can run locally as well.
|
8 |
|
9 | ## Installation
|
10 |
|
11 | `auto` is distributed through npm, but you can use it with a variety of package management platforms.
|
12 |
|
13 | ```bash
|
14 | npm install auto
|
15 | ```
|
16 |
|
17 | For `auto` installation in `non-npm` environments follow these [instructions](https://intuit.github.io/auto/pages/non-npm.html#installation).
|
18 |
|
19 | ## Getting Started
|
20 |
|
21 | Getting started with `auto` is super easy.
|
22 |
|
23 | ### Prerequisites
|
24 |
|
25 | If your project is already published or has releases then you need to make sure that your last release is tagged and that it's the `Latest Release` on GitHub.
|
26 |
|
27 | To tag your last release find the last commit where you bumped the version and run the following commands with your version number.
|
28 |
|
29 | ```bash
|
30 | git tag v1.2.3
|
31 | git push --tags
|
32 | ```
|
33 |
|
34 | Then on GitHub go to your project's releases and click `Draft a new release`.
|
35 | In the `Tag version` field enter the version number you just tagged and click `Publish release`.
|
36 |
|
37 | ### Setup Steps
|
38 |
|
39 | 1. **(OPTIONAL)** Initialize all options and configure label text.
|
40 | If this is not run then `auto` will use the default configuration.
|
41 | This command will produce an `.autorc`.
|
42 | You can configure most flags and all labels/changelogTitles.
|
43 |
|
44 | ```bash
|
45 | auto init
|
46 | ```
|
47 |
|
48 | All options can also be configured via the `.autorc` file.
|
49 | As CLI options you supply them in snake-case `(--foo-bar)`, but as `.autorc` options you supply them in camelCase `(fooBar)`,
|
50 |
|
51 | [Exclusive options](https://intuit.github.io/auto/pages/autorc.html#exclusive) (extends, labels) can only be set in the `.autorc` and do not exist as CLI flags.
|
52 |
|
53 | Any option in the `.autorc` will get overridden by the CLI flags if provided.
|
54 | The following are options that might be more useful to set in the `.autorc` than with a flag:
|
55 |
|
56 | ```txt
|
57 | baseBranch Configure what your repo considers the base branch.
|
58 | plugins Specify your plugins to load
|
59 | githubApi If you are using enterprise github, `auto` lets you configure the github API URL that it uses.
|
60 | githubGraphqlApi If you are using enterprise github and your company hosts the graphql at some other URL than the
|
61 | `githubApi`, you can use `githubGraphqlApi` to set the base path for `auto`. The `githubGraphqlApi` gets
|
62 | merged with `/graphql` to build the final URL.
|
63 | ```
|
64 |
|
65 | 2. Configure environment variables
|
66 |
|
67 | You must configure some environment variables for publishing and releasing to work properly.
|
68 |
|
69 | - `GH_TOKEN` - Used for updating the changelog and publishing the GitHub release
|
70 | - `NPM_TOKEN` - Used to publish to npm. (only with NPM plugin)
|
71 |
|
72 | **Local `.env`:**
|
73 |
|
74 | You can also store these values in a local file at the root of your project named `.env`.
|
75 | Make sure to add this file to your `.gitignore` so you don't commit any keys!
|
76 | These environment variables will override any variable already set on the process.
|
77 | This enables you to have a per project configuration that isn't effected by your global setup.
|
78 |
|
79 | `PROJECT_ROOT/.env`:
|
80 |
|
81 | ```bash
|
82 | GH_TOKEN=YOUR_TOKEN
|
83 | NPM_TOKEN=PUBLISH_TOKEN
|
84 | ```
|
85 |
|
86 | 3. Create your project's labels on github. If a label already exist, it will be updated.
|
87 |
|
88 | The types of labels that `auto` uses are:
|
89 |
|
90 | - Versioning Labels - used to calculate version numbers and make releases.
|
91 | - Changelog Labels - These labels do not effect the version calculation but they will change the section the PR displays in the changelog.
|
92 | These are customizable too, and you can even add your own sections. Read more [here](https://intuit.github.io/auto/pages/autorc.html#changelog-titles).
|
93 |
|
94 | To create the labels for your project on GitHub, run the following command with your `GH_TOKEN`.
|
95 |
|
96 | ```bash
|
97 | GH_TOKEN=YOUR_TOKEN auto create-labels
|
98 | # or with .env file
|
99 | auto create-labels
|
100 | ```
|
101 |
|
102 | 4. Set up script
|
103 |
|
104 | `auto` is written so that each tool it exposes is useful in isolation.
|
105 | To version, changelog, publish and release your code all at the same time we've included the `shipit` tool.
|
106 | This tool takes the default `auto` workflow and puts it into one command.
|
107 |
|
108 | It will:
|
109 |
|
110 | - Publish canary releases when run from a PR or locally on any branch other than the `baseBranch`
|
111 | - Generate a changelog and publish a "latest" release to a package manager when run from the `baseBranch`
|
112 |
|
113 | ```json
|
114 | {
|
115 | "scripts": {
|
116 | "release": "auto shipit"
|
117 | }
|
118 | }
|
119 | ```
|
120 |
|
121 | For detailed setup instructions,refer [here](https://intuit.github.io/auto/pages/getting-started.html#detailed-setup)
|
122 |
|
123 | ## Usage (`--help`)
|
124 |
|
125 | ```txt
|
126 | $ auto --help
|
127 |
|
128 | auto
|
129 |
|
130 | Generate releases based on semantic version labels on pull requests, and
|
131 | other pull request automation tools.
|
132 |
|
133 | Synopsis
|
134 |
|
135 | $ auto <command> <options>
|
136 |
|
137 | Setup Command
|
138 |
|
139 | init Interactive setup for minimum working configuration.
|
140 | info Determine the environment and check if auto is set up correctly
|
141 | create-labels Create your project's labels on github. If labels exist it will update them.
|
142 |
|
143 | Pull Request Interaction Commands
|
144 |
|
145 | label Get the labels for a pull request. Doesn't do much, but the return value lets you write you own
|
146 | scripts based off of the PR labels!
|
147 | comment Comment on a pull request with a markdown message. Each comment has a context, and each context only
|
148 | has one comment.
|
149 | pr-check Check that a pull request has a SemVer label
|
150 | pr-status Set the status on a PR commit
|
151 | pr-body Update the body of a PR with a message. Appends to PR and will not overwrite user content. Each
|
152 | comment has a context, and each context only has one comment.
|
153 |
|
154 | Release Commands
|
155 |
|
156 | version Get the semantic version bump for the given changes. Requires all PRs to have labels for the change
|
157 | type. If a PR does not have a label associated with it, it will default to `patch`.
|
158 | changelog Prepend release notes to `CHANGELOG.md`, create one if it doesn't exist, and commit the changes.
|
159 | release Auto-generate a github release
|
160 | shipit Context aware publishing.
|
161 |
|
162 | 1. call from base branch -> latest version released (LATEST)
|
163 | 2. call from prerelease branch -> prerelease version released (NEXT)
|
164 | 3. call from PR in CI -> canary version released (CANARY)
|
165 | 4. call locally when not on base/prerelease branch -> canary version released (CANARY)
|
166 | latest Run the full `auto` release pipeline. Force a release to latest and bypass `shipit` safeguards.
|
167 | canary Make a canary release of the project. Useful on PRs. If ran locally, `canary` will release a canary
|
168 | version for your current git HEAD. This is ran automatically from "shipit".
|
169 |
|
170 | 1. In PR: 1.2.3-canary.123.0 + add version to PR body
|
171 | 2. Locally: 1.2.3-canary.1810cfd
|
172 | next Make a release for your "prerelease" release line. This is ran automatically from "shipit".
|
173 |
|
174 | 1. Creates a prerelease on package management platform
|
175 | 2. Creates a "Pre Release" on GitHub releases page.
|
176 |
|
177 | Calling the `next` command from a prerelease branch will publish a prerelease, otherwise it will
|
178 | publish to the default prerelease branch.
|
179 |
|
180 | Global Options
|
181 |
|
182 | -V, --version Display auto's version
|
183 | -v, --verbose Show some more logs. Pass -vv for very verbose logs.
|
184 | --repo string The repo to set the status on. Defaults to looking in the package definition
|
185 | for the platform
|
186 | --owner string The owner of the GitHub repo. Defaults to reading from the package definition
|
187 | for the platform
|
188 | --github-api string GitHub API to use
|
189 | --plugins string[] Plugins to load auto with. (defaults to just npm)
|
190 | -h, --help Display the help output
|
191 | ```
|
192 |
|
193 | ## Merging Quickly
|
194 |
|
195 | One caveat of `auto` is that you need to be mindful of merging multiple PRs at once. You **must not** merge a PR while another is publishing (ex: `lerna publish`). While this window is small, it exists and you should know about it.
|
196 |
|
197 | `auto` works by looking at the `git` tree to calculate the version bump then makes commits for the `CHANGELOG.md` and the new version. If you merge a PR while another is publishing:
|
198 |
|
199 | - they might try to publish the same version number
|
200 | - one will try to push over the other's changes and fail
|
201 |
|
202 | The one [exception](https://intuit.github.io/auto/pages/quick-merge.html#with-skip-release) to this rule with when merging a bunch of PRs with `skip-release` labels.
|
203 |
|
204 | You still can't merge a PR that triggers a release and then merge a PR with `skip-release`. This will result in problem 3 from above.
|
205 | But you can merge a bunch of PRs with `skip-release` then merge a PR that triggers a release.
|
206 | Because `skip-release` is present no commits are made and the release is fine!
|
207 |
|
208 | ## Enterprise
|
209 |
|
210 | If you are using enterprise Github, `auto` lets you configure the Github API URL that it uses. You can configure this by using the CLI option --github-api, by setting the value in your `.autorc`, or during `auto init`.
|