You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add more inputs and outputs to the commit action to make it more useful (#298)
We've decided to add a few inputs and outputs to the shared `commit` action to enable easier usage of it.
The changes are:
- added `path` input specifying which files should be staged before the commit
- added `pull` input specifying whether to call `git pull` before the commit and with what parameters
- added `retries` input specifying how many retries to do in case of errors
- renamed `commit-message` input to `message`
- added `committed` output saying `true` / `false` whether the commit actually happened, or whether there were no changes
- changed `commit-sha` output to `commit_sha`, and it contains the short SHA
- added `commit_long_sha` output
They mirror the interface of `EndBug/add-and-commit` for an easier migration from that action.
Copy file name to clipboardExpand all lines: commit/README.md
+45-13Lines changed: 45 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,54 +2,86 @@
2
2
3
3
This action creates a commit from the staged files through the GitHub GraphQL API, so the commit is automatically signed by GitHub. The author of the commit will be the identity associated with the provided token (typically `github-actions[bot]` when using `${{ secrets.GITHUB_TOKEN }}`).
4
4
5
+
By default the action stages everything in the working tree (`git add .`) before committing. Pass the `add` input to scope the staging, or set it to an empty string if you want to control staging yourself before calling the action.
- `branch`(optional, default `${{ github.head_ref || github.ref_name }}`) — Target branch name. On pull requests this resolves to the PR's source branch (`github.head_ref`); on other events it resolves to `github.ref_name`. Required when `create-branch` is `true`.
30
32
- `create-branch`(optional, default `false`) — When `true`, the action pushes `HEAD` to `branch` as a new remote branch before committing. `branch` must be passed explicitly in this case.
33
+
- `add`(optional, default `.`) — Paths passed to `git add` before committing. Defaults to `.` (everything). When set to an empty string, `git add` is skipped entirely.
34
+
- `pull`(optional, default `''`) — When non-empty, run `git pull <pull>` before staging and committing (e.g. `--rebase --autostash`). The special value `true` runs a plain `git pull` with no arguments. Defaults to an empty string (no pull).
35
+
- `retries`(optional, default `0`) — How many times to retry the commit if it fails because the branch was updated by another author in the meantime. Requires `pull` to be non-empty (otherwise the action would just re-attempt against the same stale HEAD).
31
36
32
37
### Outputs
33
38
34
-
- `commit-sha`— The SHA of the created commit.
39
+
- `commit_sha`— The short (7-character) SHA of the created commit, or the current commit SHA if no new commit was created.
40
+
- `commit_long_sha`— The full 40-character SHA of the created commit, or the current commit SHA if no new commit was created.
41
+
- `committed`— `'true'` when a commit was created, `'false'` when there were no changes to commit.
This will retry the commit up to 3 times if it fails due to the branch being updated by another author, waiting with exponential backoff between attempts. The `pull` input is required for retries to work, as the action needs to fetch the new HEAD between attempts to avoid retrying against the same stale commit.
Copy file name to clipboardExpand all lines: commit/action.yml
+40-9Lines changed: 40 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ inputs:
4
4
github-token:
5
5
description: 'Token to authenticate API calls'
6
6
required: true
7
-
commit-message:
7
+
message:
8
8
required: true
9
9
description: 'The commit message'
10
10
repository:
@@ -19,11 +19,29 @@ inputs:
19
19
description: 'Create branch if it does not exist. When `true`, `branch` must be passed explicitly.'
20
20
default: 'false'
21
21
required: false
22
+
add:
23
+
description: 'Paths to stage before committing, passed to `git add`. Defaults to `.` (everything). When set to an empty string, `git add` is not called.'
24
+
default: '.'
25
+
required: false
26
+
pull:
27
+
description: 'When non-empty, run `git pull <pull>` before staging and committing (e.g. `--rebase --autostash`). The special value `true` runs a plain `git pull` with no arguments. Defaults to an empty string (no pull).'
28
+
default: ''
29
+
required: false
30
+
retries:
31
+
description: 'How many times to retry the commit if it fails because the branch was updated by another author in the meantime. Requires `pull` to be non-empty (so the action can fetch the new HEAD between attempts). Defaults to `0` (no retries).'
32
+
default: '0'
33
+
required: false
22
34
23
35
outputs:
24
-
commit-sha:
25
-
description: 'The SHA of the created commit.'
26
-
value: ${{ steps.commit.outputs.commit-sha }}
36
+
commit_sha:
37
+
description: 'The short (7-character) SHA of the created commit. Falls back to the current HEAD SHA when no commit was made.'
38
+
value: ${{ steps.commit.outputs.commit_sha }}
39
+
commit_long_sha:
40
+
description: 'The full 40-character SHA of the created commit. Falls back to the current HEAD SHA when no commit was made.'
thrownewError(`'retries' must be a non-negative integer, got "${RETRIES}"`);
170
+
}
171
+
if(retries>0&&PULL===''){
172
+
thrownewError(`'retries' is set to ${retries} but 'pull' is empty — retrying requires 'pull' to be set so the action can fetch the new HEAD between attempts.`);
173
+
}
139
174
140
-
// see: man git-diff-index(1) - section RAW OUTPUT FORMAT
0 commit comments