https://github.com/devops-infra/action-commit-push
GitHub Action that will create a new commit and push it to the repository
https://github.com/devops-infra/action-commit-push
automation ci-cd cicd commit devops devops-workflow docker dockerhub github-action github-action-docker github-actions github-actions-docker iaac push
Last synced: 3 months ago
JSON representation
GitHub Action that will create a new commit and push it to the repository
- Host: GitHub
- URL: https://github.com/devops-infra/action-commit-push
- Owner: devops-infra
- License: mit
- Created: 2020-04-12T15:38:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-28T18:51:08.000Z (4 months ago)
- Last Synced: 2025-03-29T03:06:35.619Z (3 months ago)
- Topics: automation, ci-cd, cicd, commit, devops, devops-workflow, docker, dockerhub, github-action, github-action-docker, github-actions, github-actions-docker, iaac, push
- Language: Makefile
- Homepage: https://christophshyper.github.io/
- Size: 223 KB
- Stars: 70
- Watchers: 3
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# GitHub Action for committing changes to a repository.
### Supporting `amd64` and `aarch64/arm64` images!
Useful in combination with my other action [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
Available in Docker Hub: [devopsinfra/action-commit-push:latest](https://hub.docker.com/repository/docker/devopsinfra/action-commit-push)
And GitHub Packages: [ghcr.io/devops-infra/action-commit-push/action-commit-push:latest](https://github.com/orgs/devops-infra/packages/container/package/action-commit-push)Features:
* Can add a custom prefix to commit message title by setting `commit_prefix`.
* As a commit message title will use `commit_message` if set, or `commit_prefix` and add changed files or just list of changed files.
* Can create a new branch when `target_branch` is set.
* Can add a timestamp to a branch name (great for cron-based updates):
* When `target_branch` is set and `add_timestamp` is `true` will create a branch named `${branch_name}/${add_timestamp}`.
* When `target_branch` is not set and `add_timestamp` is `true` will create a branch named `${add_timestamp}`.
* Good to combine with my other action [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
* Can use `git push --force` for fast-forward changes with `force` input.## Badge swag
[




](https://github.com/devops-infra/action-commit-push "shields.io")
[




](https://hub.docker.com/r/devopsinfra/action-commit-push "shields.io")## Reference
```yaml
- name: Run the Action
uses: devops-infra/action-commit-push@master
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
add_timestamp: true
commit_prefix: "[AUTO]"
commit_message: "Automatic commit"
force: false
target_branch: update/version
```| Input Variable | Required | Default | Description |
| ------------------- | -------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| github_token | Yes | `""` | Personal Access Token for GitHub for pushing the code. |
| add_timestamp | No | `false` | Whether to add the timestamp to a new branch name. Uses format `%Y-%m-%dT%H-%M-%SZ`. |
| amend | No | `false` | Whether to make amendment to the previous commit (`--amend`). Cannot be used together with `commit_message` or `commit_prefix`. |
| commit_prefix | No | `""` | Prefix added to commit message. Combines with `commit_message`. |
| commit_message | No | `""` | Commit message to set. Combines with `commit_prefix`. Cannot be used together with `amend`. |
| force | No | `false` | Whether to use force push for fast-forward changes (`--force`). Use only if necessary, e.g. when using `--amend`. And set `fetch-depth: 0` for `actions/checkout`. |
| no_edit | No | `false` | Whether to not edit commit message when using amend (`--no-edit`). |
| organization_domain | No | `github.com` | Github Enterprise domain name. |
| target_branch | No | *current branch* | Name of a new branch to push the code into. Creates branch if not existing. || Outputs | Description |
| ------------- | ------------------------------------------------------------------------ |
| files_changed | List of changed files. As returned by `git diff --staged --name-status`. |
| branch_name | Name of the branch code was pushed into. |## Examples
Commit and push changes to currently checked out branch.
```yaml
name: Push changes
on:
push
jobs:
change-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Change something
run: |
find . -type f -name "*.md" -print0 | xargs -0 sed -i "s/foo/bar/g"
- name: Commit and push changes
uses: devops-infra/action-commit-push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: Replaced foo with bar
```Commit and push changes to a new branch and create pull request using my other action [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
```yaml
name: Push changes
on:
push
jobs:
change-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Change something
run: |
find . -type f -name "*.md" -print0 | xargs -0 sed -i "s/foo/bar/g"
- name: Commit and push changes
uses: devops-infra/action-commit-push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_prefix: "[AUTO-COMMIT] foo/bar replace"
- name: Create pull request
uses: devops-infra/action-pull-request@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
body: "**Automated pull request**
Replaced foo/bar"
title: ${{ github.event.commits[0].message }}
```