|
| 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 | +``` |
0 commit comments