Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to customize deployment commit message #80

Closed
IndCore opened this issue Feb 9, 2022 · 2 comments
Closed

How to customize deployment commit message #80

IndCore opened this issue Feb 9, 2022 · 2 comments
Assignees
Labels

Comments

@IndCore
Copy link

IndCore commented Feb 9, 2022

When I run npm run deploy , it commits to my gh-pages branch with the commit message Updates , which is not very descriptive and I would want to customize, how can I do that?

@gitname gitname self-assigned this Feb 16, 2022
@gitname
Copy link
Owner

gitname commented Feb 16, 2022

Hi @IndCore, thanks for asking. When I first saw this Issue, I didn't know how to do this. Since then, I looked into it and found a way.

As a reminder:

  • In step 5, we currently add the following to package.json:

    "scripts": {
    +   "predeploy": "npm run build",
    +   "deploy": "gh-pages -d build",
        "start": "react-scripts start",
        "build": "react-scripts build",
  • And, in step 7, we currently run this CLI command:

    $ npm run deploy

The CLI command we run in step 7 causes the predeploy and deploy scripts defined in package.json to run.

The deploy script runs a program called gh-pages, which can also be run directly, like this:

# In repository root...

$ ./node_modules/.bin/gh-pages --version
3.2.3

$ ./node_modules/.bin/gh-pages --help
Usage: gh-pages [options]

Options:

  # ...(this is an EXCERPT of the full output)...

  -m, --message <message>  commit message (default: "Updates")
  -n, --no-push            Commit only (with no push)
  -h, --help               output usage information

As shown in the --help output above, the gh-pages program supports a -m option, which can be used to customize the commit message.

Currently, as the tutorial is written today, the developer (e.g. you, me) isn't running gh-pages directly; he or she is running it via npm run deploy. However, he or she could run it directly instead. That would allow him or her to specify a custom commit message. Here's how that would look:

# INSTEAD of running `$ npm run deploy`, I would run...

$ npm run build
$ ./node_modules/.bin/gh-pages -d build -m "This is a custom commit message"

Or, as a one-liner:

# INSTEAD of running `$ npm run deploy`, I would run...

$ npm run build && ./node_modules/.bin/gh-pages -d build -m "This is a custom commit message"

Other than the -m part, those commands are the same as the ones npm run deploy would cause to run. Here, I am just running them directly (instead of via npm run deploy) so I have the opportunity to add the -m option followed by a custom commit message.

Thanks again for asking this question. I also was dissatisfied with the default commit message, but hadn't looked into customizing it. Seeing this Issue motivated me to do so.

@gitname gitname closed this as completed Feb 16, 2022
@gitname
Copy link
Owner

gitname commented Feb 17, 2022

Hi again @IndCore, I just learned something new (after posting my previous comment).

When issuing the npm run deploy command, the developer can append arguments to that command and npm will apply them to the deploy script!

In our case, we can append -- -m "Custom commit message..." to the npm run deploy command, like this (this is on a Windows machine, so the slashes are "backwards"):

image

So, the procedure I recommend for specifying a custom commit message is:

In step 7, instead of running this (which -- under the hood -- causes gh-pages to use its default commit message of "Updates"):

$ npm run deploy

Run this:

$ npm run deploy -- -m "Your custom message"

In fact, that is what I plan to start doing, myself, when I make deployments. I also plan to update the tutorial with this tip!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants