Skip to content

Commit 8bf48e0

Browse files
authored
trry this
1 parent 0dd373b commit 8bf48e0

File tree

4 files changed

+267
-16
lines changed

4 files changed

+267
-16
lines changed

README.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# Add, commit, and push
2+
3+
✨ Automagically `git add`, `git commit`, and `git push`
4+
5+
<table align=center><td>
6+
7+
```yml
8+
on:
9+
pull_request:
10+
jobs:
11+
job:
12+
permissions:
13+
contents: write
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- run: npx --yes prettier --write .
18+
- uses: actions4git/add-commit-push@v1
19+
```
20+
21+
</table>
22+
23+
➕ Adds all files by default \
24+
👨 Uses `github.actor` as the default author \
25+
🤖 Uses @github-actions\[bot\] as the default committer \
26+
🔼 Pushes changes to the current branch or tag \
27+
🏷️ Will automatically use `--force` if it's a Git tag
28+
29+
A convenience wrapper with sensible defaults so that you don't have to do
30+
`git add`, `git commit`, and `git push` manually all the time. 😉
31+
32+
## Usage
33+
34+
**🚀 Here's what you want:**
35+
36+
```yml
37+
on:
38+
pull_request:
39+
jobs:
40+
job:
41+
permissions:
42+
contents: write
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- run: npx --yes prettier --write .
47+
- uses: actions4git/add-commit-push@v1
48+
```
49+
50+
🔒 Make sure you have the `permissions` set to `contents: write`! We need to be
51+
able to edit the repository contents to push things.
52+
53+
<details><summary>You can also use this GitHub Action with tags/releases</summary>
54+
55+
```yml
56+
on:
57+
release:
58+
types: released
59+
jobs:
60+
job:
61+
permissions:
62+
contents: write
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v4
66+
- run: echo "$TAG" > VERSION.txt
67+
env:
68+
TAG: ${{ github.event.release.tag_name }}
69+
- uses: actions4git/add-commit-push@v1
70+
```
71+
72+
</details>
73+
74+
If you're looking to have more control than the options provided below, it's
75+
best if you tap in to the `git` CLI directly. The only tricky bit is setting a
76+
default Git user (it's unset by default). You can either set it manually or use
77+
a premade action like [actions4git/setup-git] to configure the `user.name` and
78+
`user.email` settings.
79+
80+
```yml
81+
- uses: actions/checkout@v4
82+
83+
- uses: actions4git/setup-git@v1
84+
# OR
85+
- run: |
86+
git config user.name "$GITHUB_ACTOR"
87+
git config user.email "[email protected]"
88+
# OR
89+
- run: |
90+
git config user.name 'github-actions[bot]'
91+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
92+
93+
# Then you can do whatever you want!
94+
- run: git add ...
95+
- run: git rebase ...
96+
- run: git merge ...
97+
- run: git commit ...
98+
- run: git push ...
99+
```
100+
101+
### Inputs
102+
103+
- **`path`:** The path to the repository root folder to perform the Git
104+
operations in. This defaults to the current working directory (`.`). Change
105+
this to a subfolder if you are using a different folder other than the default
106+
`github.workspace` for your Git repository.
107+
108+
- **`add-pathspec`:** Additional path specifiers to be passed to `git add`.
109+
These can be files, folders, globs, or even some fancy Git pathspec things
110+
such as `:!ignoreme.txt`. Check out the CSS-Tricks [Git Pathspecs and How to
111+
Use Them] article for the highlights of Git pathspecs. If this input is not
112+
specified, `git add --all` will be used instead. Specifying `.` has slightly
113+
different behavior from `--all`.
114+
115+
- **`add-force`:** Whether or not to use the `--force` flag when performing the
116+
`git add` operation. Use this if you really want to add something but it's in
117+
your `.gitignore`. This can be useful if you ever need to commit build
118+
artifacts to Git that are normally ignored by your `.gitignore`. Defaults to
119+
`false`.
120+
121+
- **`commit-author`:** A `Name Here <[email protected]>` AiO author name &
122+
email string. This is a shortcut alternative to the independent
123+
`commit-author-name` and `commit-author-email` options that are also
124+
available. This defaults to the current `github.actor`. Note that this is
125+
different from the `commit-committer`. [The author of a commit is who wrote
126+
the thing, and the committer is who committed it to Git.] It's recommended to
127+
leave this as the default.
128+
129+
- **`commit-author-name`:** The name of the author to associate with the commit.
130+
Should be left unspecified if `commit-author` is specified.
131+
132+
- **`commit-author-email`:** The email address of the author to associate with
133+
the commit. Should be left unspecified if `commit-author` is specified.
134+
135+
- **`commit-committer`:** A `Name Here <[email protected]>` AiO author name
136+
& email string. This input is a shortcut for the `commit-committer-name` and
137+
`commit-committer-email` inputs that can also be individually specified. This
138+
defaults to the `github-actions[bot]` user which is probably what you want.
139+
It's recommended to change the `commit-author` before changing the
140+
`commit-committer`.
141+
142+
- **`commit-committer-name`:** The name of the committer to associate with the
143+
commit. Should be left unspecified if `commit-committer` is specified.
144+
145+
- **`commit-committer-email`:** The email address of the committer to associate
146+
with the commit. Should be left unspecified if `commit-committer` is
147+
specified.
148+
149+
- **`commit-message`:** The `--message` parameter to use for the commit. This
150+
can be a multiline string if you want to specify a title and body. The default
151+
is 'Automated changes'.
152+
153+
- **`push-repository`:** The first argument to
154+
`git push [repository] [refspec]`. You can change this to another remote name
155+
like `upstream` (as long as you have push rights) or another Git remote
156+
entirely like `https://github.com/octocat/another-repo.git`. The default
157+
`origin` is probably what you want.
158+
159+
- **`push-refspec`:** A specific branch or tag name to push to. If this is a
160+
tag, `push-force` will default to `true` unless explicitly set otherwise.
161+
Defaults to whatever the current Git `HEAD` target is.
162+
163+
- **`push-force`:** Whether or not to use the `--force` parameter when doing the
164+
`git push`. You may need to specify this if you are rewriting history or
165+
editing a tag. Defaults to `false` if the `push-refspec` is a branch and
166+
`true` if it's a tag.
167+
168+
### Outputs
169+
170+
TODO!
171+
172+
## Development
173+
174+
![Bun](https://img.shields.io/static/v1?style=for-the-badge&message=Bun&color=000000&logo=Bun&logoColor=FFFFFF&label=)
175+
176+
**How do I test my changes?**
177+
178+
The easiest way is to open a Draft Pull Request either against the upstream
179+
repository or against your own fork's main branch and watch the GitHub Actions
180+
do their thing.
181+
182+
<!-- prettier-ignore-start -->
183+
[Git Pathspecs and How to Use Them]: https://css-tricks.com/git-pathspecs-and-how-to-use-them/
184+
[The author of a commit is who wrote the thing, and the committer is who committed it to Git.]: https://stackoverflow.com/questions/18750808/difference-between-author-and-committer-in-git
185+
<!-- prettier-ignore-end -->

action.yml

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,93 @@ branding:
77

88
inputs:
99
path:
10+
description: >
11+
The path to the repository root folder to perform the Git operations in.
12+
This defaults to the current working directory ('.'). Change this to a
13+
subfolder if you are using a different folder other than the default
14+
'github.workspace' for your Git repository.
1015
default: .
11-
add-pathspec: {}
16+
add-pathspec:
17+
description: >
18+
Additional path specifiers to be passed to 'git add'. These can be files,
19+
folders, globs, or even some fancy Git pathspec things such as
20+
':!ignoreme.txt'. Check out the CSS-Tricks Git Pathspecs and How to Use
21+
Them article for the highlights of Git pathspecs. If this input is not
22+
specified, 'git add --all' will be used instead. Specifying '.' has
23+
slightly different behaviour from '--all'.
1224
add-force:
25+
description: >
26+
Whether or not to use the '--force' flag when performing the 'git add'
27+
operation. Use this if you really want to add something but it's in your
28+
'.gitignore'. This can be useful if you ever need to commit build
29+
artifacts to Git that are normally ignored by your '.gitignore'. Defaults
30+
to 'false'.
1331
default: false
1432
commit-author:
33+
description: >
34+
A 'Name Here <[email protected]>' AiO author name & email string. This
35+
is a shortcut alternative to the independant 'commit-author-name' and
36+
'commit-author-email' options that are also available. This defaults to
37+
the current 'github.actor'. Note that this is different from the
38+
'commit-committer'. The author of a commit is who wrote the thing and the
39+
committer is who committed it to Git. It's recommended to leave this as
40+
the default.
1541
default: |
16-
${{ github.actor }} ${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com
17-
commit-author-name: {}
18-
commit-author-email: {}
42+
${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
43+
commit-author-name:
44+
description: >
45+
The name of the author to associate with the commit. Should be left
46+
unspecified if 'commit-author' is specified.
47+
commit-author-email:
48+
description: >
49+
The email address of the author to associate with the commit. Should be
50+
left unspecified if 'commit-author' is specified.
1951
commit-committer:
52+
description: >
53+
A 'Name Here <[email protected]>' AiO author name & email string. This
54+
input is a shortcut for the 'commit-committer-name' and
55+
'commit-committer-email' inputs that can also be individually specified.
56+
This defaults to the 'github-actions[bot]' user which is probably what you
57+
want. It's recommended to change the 'commit-author' before changing the
58+
'commit-commiter'.
2059
default: |
2160
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
22-
commit-committer-name: {}
23-
commit-committer-email: {}
61+
commit-committer-name:
62+
description: >
63+
The name of the committer to associate with the commit. Should be left
64+
unspecified if 'commit-committer' is specified.
65+
commit-committer-email:
66+
description: >
67+
The email address of the committer to associate with the commit. Should be
68+
left unspecified if 'commit-committer' is specified.
2469
commit-message:
70+
description: >
71+
The '--message' parameter to use for the commit. This can be a multiline
72+
string if you want to specify a title and body. The default is 'Automated
73+
changes'.
2574
default: Automated changes
2675
push-repository:
76+
description: >
77+
The first argument to 'git push [repository] [refspec]'. You can change
78+
this to another remote name like 'upstream' (as long as you have push
79+
rights) or another Git remote entirely like
80+
'https://github.com/octocat/another-repo.git'. The default 'origin' is
81+
probably what you want.
2782
default: origin
28-
push-refspec: {}
29-
push-force: {}
83+
push-refspec:
84+
description: >
85+
A specific branch or tag name to push to. If this is a tag, 'push-force'
86+
will default to 'true' unless explicitly set otherwise. Defaults to
87+
whatever the current Git 'HEAD' target is.
88+
push-force:
89+
description: >
90+
Whether or not to use the '--force' parameter when doing the 'git push'.
91+
You may need to specify this if you are rewriting history or editing a
92+
tag. Defaults to 'false' if the 'push-refspec' is a branch and 'true' if
93+
it's a tag.
3094
3195
outputs:
32-
commit-sha: {}
96+
# commit-sha: {}
3397

3498
# https://github.com/jcbhmr/configure-bun-action
3599
runs:

src/main.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ let GIT_AUTHOR_EMAIL: string;
1717
if (core.getInput("commit-author")) {
1818
assert.equal(core.getInput("commit-author-name"), "");
1919
assert.equal(core.getInput("commit-author-email"), "");
20-
const [part1, part2] = core.getInput("commit-author").trim().split(/\s+/);
21-
GIT_AUTHOR_NAME = part1;
22-
GIT_AUTHOR_EMAIL = part2.replace(/^<|>$/g, "");
20+
[GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL] = core
21+
.getInput("commit-author")
22+
.match(/^\s+(.+)\s+<(.+)>\s+$/)
23+
.slice(1);
2324
} else {
2425
GIT_AUTHOR_NAME = core.getInput("commit-author-name", { required: true });
2526
GIT_AUTHOR_EMAIL = core.getInput("commit-author-email", { required: true });
@@ -30,9 +31,10 @@ let GIT_COMMITTER_EMAIL: string;
3031
if (core.getInput("commit-committer")) {
3132
assert.equal(core.getInput("commit-committer-name"), "");
3233
assert.equal(core.getInput("commit-committer-email"), "");
33-
const [part1, part2] = core.getInput("commit-committer").trim().split(/\s+/);
34-
GIT_COMMITTER_NAME = part1;
35-
GIT_COMMITTER_EMAIL = part2.replace(/^<|>$/g, "");
34+
[GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL] = core
35+
.getInput("commit-committer")
36+
.match(/^\s+(.+)\s+<(.+)>\s+$/)
37+
.slice(1);
3638
} else {
3739
GIT_COMMITTER_NAME = core.getInput("commit-committer-name", {
3840
required: true,

test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
https://github.com/actions4git/add-commit-push/tree/test-branch
1+
https://github.com/actions4git/add-commit-push/tree/test-branch \
22
https://github.com/actions4git/add-commit-push/tree/test-tag

0 commit comments

Comments
 (0)