Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
upload-cloud

GitHub Action

GitHub Action for committing changes to a repository

v0.8

GitHub Action for committing changes to a repository

upload-cloud

GitHub Action for committing changes to a repository

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

Installation

Copy and paste the following snippet into your .yml file.

              

- name: GitHub Action for committing changes to a repository

uses: devops-infra/[email protected]

Learn more about this action in devops-infra/action-commit-push

Choose a version

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 by setting commit_prefix.
  • Can create a new branch when target_branch is set.
  • Can add a timestamp to a branch name, when target_branch is set and add_timestamp is true. Will create a branch named ${branch_name}/${add_timestamp}. Great for cron-based updates.
  • As a commit message will use commit_message if set, or commit_prefix and add changed files or just list changed files.
  • Good to combine with my other action devops-infra/action-pull-request.
  • Can use git push --force for fast-forward changes.

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. Used when target_branch is set. 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 [AUTO-COMMIT] Prefix added to commit message. If commit_message is not used.
commit_message No "" Full commit message to set. Cannot be used together with amend.
force No false Whether to use force push for fast-forward changes (--force). Use only if necessary.
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 "*" -print0 | xargs -0 sed -i "s/foo/bar/g"
      - name: Commit and push changes
        uses: devops-infra/[email protected]
        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 "*" -print0 | xargs -0 sed -i "s/foo/bar/g"
      - name: Commit and push changes
        uses: devops-infra/[email protected]
        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 }}