Skip to content

Commit cad4325

Browse files
committed
feat: Add default inputs to the commit action, add a README for it
1 parent 36f5d99 commit cad4325

2 files changed

Lines changed: 69 additions & 9 deletions

File tree

commit/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# `commit` Github Action
2+
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+
5+
## Usage
6+
7+
```yaml
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v6
11+
12+
- name: Make changes and stage them
13+
run: |
14+
echo "hello" > greeting.txt
15+
git add greeting.txt
16+
17+
- name: Commit through API
18+
uses: apify/workflows/commit@v0.43.0
19+
with:
20+
commit-message: "chore: add greeting"
21+
github-token: ${{ secrets.YOUR_GITHUB_TOKEN_WITH_WRITE_PERMISSION }}
22+
```
23+
24+
### Inputs
25+
26+
- `github-token` (required) — Token used to authenticate the GraphQL call. Must have `contents: write` permission on the target repository.
27+
- `commit-message` (required) — The commit message.
28+
- `repository` (optional, default `${{ github.repository }}`) — Target repository in `<owner>/<repo>` format.
29+
- `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+
- `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.
31+
32+
### Example: commit to a new branch
33+
34+
```yaml
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v
38+
39+
- name: Make changes and stage them
40+
run: |
41+
echo "hello" > greeting.txt
42+
git add greeting.txt
43+
44+
- name: Commit to a new branch
45+
uses: apify/workflows/commit@v0.43.0
46+
with:
47+
commit-message: "chore: add greeting"
48+
github-token: ${{ secrets.YOUR_GITHUB_TOKEN_WITH_WRITE_PERMISSION }}
49+
branch: chore/add-greeting
50+
create-branch: 'true'
51+
```

commit/action.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
name: Commit
22
description: Creates a commit from the staged files through the GitHub GraphQL API (automatically signed)
33
inputs:
4+
github-token:
5+
description: 'Token to authenticate API calls'
6+
required: true
47
commit-message:
58
required: true
69
description: 'The commit message'
7-
branch:
8-
description: 'Target branch name'
9-
required: true
1010
repository:
11-
description: 'Format: <owner>/<repo>'
12-
required: true
13-
github-token:
14-
description: 'Token to authenticate API calls'
15-
required: true
11+
description: 'Format: `<owner>/<repo>`. Defaults to the current repository (`github.repository`).'
12+
required: false
13+
default: ${{ github.repository }}
14+
branch:
15+
description: 'Target branch name. Defaults to the current branch (`github.head_ref` on pull requests, otherwise `github.ref_name`). Required when `create-branch` is `true`.'
16+
required: false
17+
default: ${{ github.head_ref || github.ref_name }}
1618
create-branch:
17-
description: 'Create branch if it does not exist'
19+
description: 'Create branch if it does not exist. When `true`, `branch` must be passed explicitly.'
1820
default: 'false'
1921
required: false
2022

2123
runs:
2224
using: composite
2325
steps:
26+
- name: Validate inputs
27+
if: ${{ inputs.create-branch == 'true' && inputs.branch == (github.head_ref || github.ref_name) }}
28+
shell: bash
29+
run: |
30+
echo "::error::When 'create-branch' is true, 'branch' must be passed explicitly (it cannot default to the current branch '${{ github.head_ref || github.ref_name }}')."
31+
exit 1
32+
2433
- name: Create and checkout target branch
2534
if: ${{ inputs.create-branch == 'true' }}
2635
# The `shell` field is for some reason required when

0 commit comments

Comments
 (0)