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 }}).
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.
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Make changes
run: |
echo "hello" > greeting.txt
- name: Commit through API
uses: apify/actions/signed-commit@v1.0.0
with:
message: "chore: add greeting"
add: greeting.txt
github-token: ${{ secrets.YOUR_GITHUB_TOKEN_WITH_WRITE_PERMISSION }}github-token(required) — Token used to authenticate the GraphQL call. Must havecontents: writepermission on the target repository.message(required) — The commit message.repository(optional, default${{ github.repository }}) — Target repository in<owner>/<repo>format.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 togithub.ref_name. Required whencreate-branchistrue.create-branch(optional, defaultfalse) — Whentrue, the action pushesHEADtobranchas a new remote branch before committing.branchmust be passed explicitly in this case.add(optional, default.) — Paths passed togit addbefore committing. Defaults to.(everything). When set to an empty string,git addis skipped entirely.pull(optional, default'') — When non-empty, rungit pull <pull>before staging and committing (e.g.--rebase --autostash). The special valuetrueruns a plaingit pullwith no arguments. Defaults to an empty string (no pull).pull-after-push(optional, defaulttrue) — Whether to pull the committed changes back into the local repo clone after pushing the commit. Defaults totrue.retries(optional, default0) — How many times to retry the commit if it fails because the branch was updated by another author in the meantime. Requirespullto be non-empty (otherwise the action would just re-attempt against the same stale HEAD).
commit_sha— The short (7-character) SHA of the created commit, or the current commit SHA if no new commit was created.commit_long_sha— The full 40-character SHA of the created commit, or the current commit SHA if no new commit was created.committed—'true'when a commit was created,'false'when there were no changes to commit.
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Make changes
run: echo "hello" > greeting.txt
- name: Commit to a new branch
uses: apify/actions/signed-commit@v1.0.0
with:
message: "chore: add greeting"
add: greeting.txt
branch: chore/add-greeting
create-branch: 'true'
github-token: ${{ secrets.YOUR_GITHUB_TOKEN_WITH_WRITE_PERMISSION }}When another job may push to the same branch concurrently, use pull and retries to fetch the latest changes before committing.
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Make changes
run: echo "hello" > greeting.txt
# Someone else would push to the same branch at this point.
- name: Commit through API
uses: apify/actions/signed-commit@v1.0.0
with:
message: "chore: add greeting"
add: greeting.txt
pull: --rebase --autostash
retries: 3
github-token: ${{ secrets.YOUR_GITHUB_TOKEN_WITH_WRITE_PERMISSION }}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.