Skip to content

devops-infra/action-commit-push

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Action for committing changes to a repository

GitHub Action that will create a new commit and push it back to the repository.

Dockerized as devopsinfra/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.
  • Can use git push --force for fast-forward changes with force input.

Badge swag

Master branch Other branches
GitHub repo GitHub code size in bytes GitHub last commit GitHub license
DockerHub Docker version Image size Docker Pulls

Reference

    - 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.

name: Push changes
on:
  push
jobs:
  change-and-push:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - 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.

name: Push changes
on:
  push
jobs:
  change-and-push:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - 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**<br><br>Replaced foo/bar"
          title: ${{ github.event.commits[0].message }}