Skip to content

Commit 7618ed2

Browse files
committed
update pull command default args
1 parent 69c6874 commit 7618ed2

File tree

8 files changed

+71
-27
lines changed

8 files changed

+71
-27
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Mykola Grybyk
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,35 @@ Runs git add, git commit, git pull and git push.
44

55
The action flow:
66

7-
1. `git add .`
7+
1. `git add` (with `add_args`, defaults to `.`)
88
2. check if there are any changed files
9-
3. `git commit`
10-
4. `git pull` (with args)
11-
5. `git push`
9+
3. `git fetch`
10+
4. `git checkout branch` (to allow push in PRs)
11+
5. `git commit`
12+
6. `git pull` (with `pull_args`, defaults to `--rebase`)
13+
7. `git push`
1214

13-
Originally designed to run `git pull --rebase -X ours` or `git pull --rebase -X theirs` after commit to help pushing changed to `gh-pages`.
15+
Originally designed to run `git pull --rebase -X ours` or `git pull --rebase -X theirs` after commit to help pushing changes to `gh-pages`.
1416

1517
## Usage
1618

1719
```yaml
1820
- name: Git Commit and Push Action
1921
uses: mgrybyk/git-commit-pull-push-action@v1
2022
with:
21-
repository: test-action-dir
22-
branch: test-action
23+
repository: gh-pages
24+
branch: gh-pages # ${{ github.head_ref }}
2325
commit_message: Apply automatic changes
24-
pull_args: --rebase -X theirs
26+
pull_args: --rebase -X ours
2527
```
2628
29+
### Merge strategy specific option
30+
31+
`-X` (same as `--strategy-option`).
32+
33+
- `ours`: option forces conflicting chunks to be auto-resolved cleanly by favoring **our** (current) version (instead of incoming).
34+
- `theirs`: is the opposite of **ours**.
35+
36+
## API
37+
38+
Please see [action.yml](./action.yml)

action.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ branding:
66
color: 'gray-dark'
77
inputs:
88
repository:
9-
description: Local file path to the git repository. Defaults to the current directory (`.`)
9+
description: Local file path to the git repository. Defaults to the current directory '.'
1010
required: true
1111
default: '.'
1212
branch:
13-
description: Git branch name, where changes should be pushed too.
13+
description: Git branch name, where changes should be pushed to.
1414
required: true
1515
commit_message:
1616
description: Commit message
@@ -19,7 +19,11 @@ inputs:
1919
pull_args:
2020
description: git pull arguments
2121
required: false
22-
default: --rebase -X ours
22+
default: --rebase
23+
add_args:
24+
description: git add arguments (eg. -u) or 'src/*.js'
25+
required: false
26+
default: '.'
2327
runs:
2428
using: 'node16'
2529
main: 'dist/index.js'

dist/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,38 +2713,40 @@ try {
27132713
const branch = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('branch');
27142714
const commitMessage = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('commit_message');
27152715
const pullArgs = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('pull_args');
2716+
const addArgs = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('add_args');
27162717
// log
27172718
console.log({
27182719
repository,
27192720
branch,
27202721
commitMessage,
27212722
pullArgs,
2723+
addArgs,
27222724
});
27232725
if (!(await (0,_src_isFileExists_js__WEBPACK_IMPORTED_MODULE_1__/* .isFileExist */ .e)(repository))) {
27242726
throw new Error("repository directory doesn't exist: " + repository);
27252727
}
27262728
if (branch.trim() === '') {
27272729
throw new Error('branch is a required field');
27282730
}
2729-
await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['add', '.'], repository);
2731+
await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['config', '--global', 'user.name', '"github-actions[bot]"'], repository);
2732+
await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['config', '--global', 'user.email', '"41898282+github-actions[bot]@users.noreply.github.com"'], repository);
2733+
await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['add', ...addArgs.split(' ')], repository);
27302734
const diff = await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['diff', '--staged', '--name-only'], repository);
27312735
if (diff.trim() === '') {
27322736
console.log('Working tree is empty. Nothing to commit.');
27332737
}
27342738
else {
2739+
await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['fetch', '--depth=1'], repository);
2740+
await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['checkout', branch], repository);
27352741
await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', [
2736-
'-c',
2737-
'user.name="github-actions[bot]"',
2738-
'-c',
2739-
'user.email="41898282+github-actions[bot]@users.noreply.github.com"',
27402742
'commit',
27412743
'-m',
27422744
commitMessage,
27432745
'--author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"',
27442746
'--no-verify',
27452747
], repository);
27462748
await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['pull', ...pullArgs.split(' ')], repository);
2747-
await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['push', '--no-verify', 'origin', branch], repository);
2749+
console.log(await (0,_src_spawnProcess_js__WEBPACK_IMPORTED_MODULE_2__/* .spawnProcess */ .y)('git', ['push', '--no-verify'], repository));
27482750
}
27492751
}
27502752
catch (error) {

index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ try {
88
const branch = core.getInput('branch')
99
const commitMessage = core.getInput('commit_message')
1010
const pullArgs = core.getInput('pull_args')
11+
const addArgs = core.getInput('add_args')
1112

1213
// log
1314
console.log({
1415
repository,
1516
branch,
1617
commitMessage,
1718
pullArgs,
19+
addArgs,
1820
})
1921

2022
if (!(await isFileExist(repository))) {
@@ -25,18 +27,19 @@ try {
2527
throw new Error('branch is a required field')
2628
}
2729

28-
await spawnProcess('git', ['add', '.'], repository)
30+
await spawnProcess('git', ['config', '--global', 'user.name', '"github-actions[bot]"'], repository)
31+
await spawnProcess('git', ['config', '--global', 'user.email', '"41898282+github-actions[bot]@users.noreply.github.com"'], repository)
32+
33+
await spawnProcess('git', ['add', ...addArgs.split(' ')], repository)
2934
const diff = await spawnProcess('git', ['diff', '--staged', '--name-only'], repository)
3035
if (diff.trim() === '') {
3136
console.log('Working tree is empty. Nothing to commit.')
3237
} else {
38+
await spawnProcess('git', ['fetch', '--depth=1'], repository)
39+
await spawnProcess('git', ['checkout', branch], repository)
3340
await spawnProcess(
3441
'git',
3542
[
36-
'-c',
37-
'user.name="github-actions[bot]"',
38-
'-c',
39-
'user.email="41898282+github-actions[bot]@users.noreply.github.com"',
4043
'commit',
4144
'-m',
4245
commitMessage,
@@ -46,7 +49,7 @@ try {
4649
repository
4750
)
4851
await spawnProcess('git', ['pull', ...pullArgs.split(' ')], repository)
49-
await spawnProcess('git', ['push', '--no-verify', 'origin', branch], repository)
52+
console.log(await spawnProcess('git', ['push', '--no-verify'], repository))
5053
}
5154
} catch (error) {
5255
core.setFailed(error.message)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "git-commit-pull-push-action",
3-
"version": "1.0.0",
4-
"description": "",
3+
"version": "1.2.1",
4+
"description": "Runs git add, git commit, git pull and git push",
55
"main": "index.js",
66
"type": "module",
77
"scripts": {

tag.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
TAG_MAJOR=v1
2+
git fetch
3+
git rebase
24
git tag --delete $TAG_MAJOR
35
git push --delete origin $TAG_MAJOR
46
git tag $TAG_MAJOR

0 commit comments

Comments
 (0)