Skip to content

Commit c698699

Browse files
authored
feat: add default_author (#181)
* feat: add deafult_author and start using actions-toolkit * fix: go back to @actions/core for logs * chore: add debug after fetching user * test: keep build not minified * fix: don't use tools.exit * fix: author_displayname * fix: check github_token * fix: back to minified builds * fix: fetch email too * fix: change option names * docs: document changes * docs: update "github-actions" example
1 parent eb4e956 commit c698699

File tree

7 files changed

+1490
-144
lines changed

7 files changed

+1490
-144
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ Add a step like this to your workflow:
2020
add: 'src'
2121

2222
# The name of the user that will be displayed as the author of the commit
23-
# Default: author of the commit that triggered the run
23+
# Default: depends on the default_author input
2424
author_name: Your Name
2525

2626
# The email of the user that will be displayed as the author of the commit
27-
# Default: author of the commit that triggered the run
27+
# Default: depends on the default_author input
2828
author_email: [email protected]
2929

3030
# Name of the branch to use, if different from the one that triggered the workflow
@@ -35,6 +35,13 @@ Add a step like this to your workflow:
3535
# Default: '.'
3636
cwd: './path/to/the/repo'
3737

38+
# Determines the way the action fills missing author name and email. Three options are available:
39+
# - github_actor -> UserName <[email protected]>
40+
# - user_info -> Your Display Name <[email protected]>
41+
# - github_actions -> github-actions <email associated with the github logo>
42+
# Default:
43+
default_author: github_actor
44+
3845
# The message for the commit
3946
# Default: 'Commit from GitHub Actions (name of the workflow)'
4047
message: 'Your commit message'
@@ -97,6 +104,8 @@ You can use the `tag` option to enter the arguments for a `git add` command. In
97104
When pushing, the action uses the token that the local git repository has been configured with: that means that if you want to change it you'll need to do it in the steps that run before this action. For example: if you set up your repo with [`actions/checkout`](https://github.com/actions/checkout/) then you have to add the token there.
98105
Changing the token with which the repo is configured can be useful if you want to run CI checks on the commit pushed by this action; anyway, it has to be set up outside of this action.
99106

107+
The action automatically gets the GitHub token from a `github_token` input: this input should not be modified by the user, since it doesn't affect the commits as it's only used to access the GitHub API to get user info, in case they selected that option for the commit author.
108+
100109
### About `actions/checkout`
101110

102111
The token you use when setting up the repo with this action will determine what token `add-and-commit` will use.
@@ -120,7 +129,9 @@ For more info on how to use outputs, see ["Context and expression syntax"](https
120129

121130
### Examples:
122131

123-
If you don't want to use your GitHub username for the CI commits, you can [also use the user provided by GitHub for this task](https://github.com/actions/checkout/#push-a-commit-using-the-built-in-token):
132+
If you don't want to use your GitHub username for the CI commits, you can use the `default_author` option to make it appear as if it was made by "github-actions"
133+
134+
<img src="https://user-images.githubusercontent.com/26386270/115738624-80b51780-a38d-11eb-9bbe-77461654274c.png" height=40/>
124135

125136
```yaml
126137
on: push
@@ -130,11 +141,9 @@ jobs:
130141
steps:
131142
- uses: EndBug/[email protected]
132143
with:
133-
author_name: github-actions
134-
author_email: 41898282+github-actions[bot]@users.noreply.github.com
144+
default_author: github_actions
135145
```
136146

137-
`41898282+github-actions[bot]@users.noreply.github.com` is the mail of the original GitHub Actions bot. If you use that, [the GitHub avatar is shown for the commits](https://github.community/t/github-actions-bot-email-address/17204).
138147

139148
Do you want to lint your JavaScript files, located in the `src` folder, with ESLint, so that fixable changes are done without your intervention? You can use a workflow like this:
140149

action.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ inputs:
99
author_name:
1010
description: The name of the user that will be displayed as the author of the commit
1111
required: false
12-
default: ${{ github.actor }}
1312
author_email:
1413
description: The email of the user that will be displayed as the author of the commit
1514
required: false
16-
default: ${{ github.actor }}@users.noreply.github.com
1715
branch:
1816
description: Name of the branch to use, if different from the one that triggered the workflow
1917
required: false
2018
cwd:
2119
description: The directory where your repository is located. You should use actions/checkout first to set it up
2220
required: false
2321
default: '.'
22+
default_author:
23+
description: How the action should fill missing author name or email.
24+
required: false
25+
default: 'github_actor'
2426
message:
2527
description: The message for the commit
2628
required: false
@@ -41,6 +43,12 @@ inputs:
4143
tag:
4244
description: Arguments for the git tag command (the tag name always needs to be the first word not preceded by a hyphen)
4345
required: false
46+
47+
# Input not required from the user
48+
github_token:
49+
description: The token used to make requests to the GitHub API. It's NOT used to make commits and should not be changed.
50+
required: false
51+
default: ${{ github.token }}
4452

4553
outputs:
4654
committed:

lib/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)