Coder Social home page Coder Social logo

stefanzweifel / git-auto-commit-action Goto Github PK

View Code? Open in Web Editor NEW
1.9K 14.0 219.0 423 KB

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.

License: MIT License

Shell 97.58% JavaScript 2.42%
github-action github-actions git github workflow-runs trigger

git-auto-commit-action's Introduction

git-auto-commit Action

The GitHub Action for committing files for the 80% use case.

A GitHub Action to detect changed files during a Workflow run and to commit and push them back to the GitHub repository. By default, the commit is made in the name of "GitHub Actions" and co-authored by the user that made the last commit.

If you want to learn more how this Action works under the hood, check out this article by Michael Heap.

Usage

Adding git-auto-commit to your Workflow only takes a couple lines of code.

  1. Set the contents-permission of the default GITHUB_TOKEN to true. (Required to push new commits to the repository)
  2. Add the following step at the end of your job, after other steps that might add or change files.
- uses: stefanzweifel/git-auto-commit-action@v5

Your Workflow should look similar to this example.

name: Format

on: push

jobs:
  format-code:
    runs-on: ubuntu-latest

    permissions:
      # Give the default GITHUB_TOKEN write permission to commit and push the
      # added or changed files to the repository.
      contents: write

    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.head_ref }}

      # Other steps that change files in the repository go here
      #

      # Commit all changed files back to the repository
      - uses: stefanzweifel/git-auto-commit-action@v5

Note

The Action has to be used in a Job that runs on a UNIX-like system (e.g. ubuntu-latest).

The following is an extended example with all available options.

- uses: stefanzweifel/git-auto-commit-action@v5
  with:
    # Optional. Commit message for the created commit.
    # Defaults to "Apply automatic changes"
    commit_message: Automated Change

    # Optional. Local and remote branch name where commit is going to be pushed
    #  to. Defaults to the current branch.
    #  You might need to set `create_branch: true` if the branch does not exist.
    branch: feature-123

    # Optional. Options used by `git-commit`.
    # See https://git-scm.com/docs/git-commit#_options
    commit_options: '--no-verify --signoff'

    # Optional glob pattern of files which should be added to the commit
    # Defaults to all (.)
    # See the `pathspec`-documentation for git
    # - https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203
    # - https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
    file_pattern: '*.php src/*.js tests/*.js'

    # Optional. Local file path to the repository.
    # Defaults to the root of the repository.
    repository: .

    # Optional commit user and author settings
    commit_user_name: My GitHub Actions Bot # defaults to "github-actions[bot]"
    commit_user_email: [email protected] # defaults to "41898282+github-actions[bot]@users.noreply.github.com"
    commit_author: Author <[email protected]> # defaults to "username <[email protected]>", where "username" belongs to the author of the commit that triggered the run

    # Optional. Tag name being created in the local repository and 
    # pushed to remote repository and defined branch.
    tagging_message: 'v1.0.0'

    # Optional. Option used by `git-status` to determine if the repository is 
    # dirty. See https://git-scm.com/docs/git-status#_options
    status_options: '--untracked-files=no'

    # Optional. Options used by `git-add`.
    # See https://git-scm.com/docs/git-add#_options
    add_options: '-u'

    # Optional. Options used by `git-push`.
    # See https://git-scm.com/docs/git-push#_options
    push_options: '--force'
    
    # Optional. Disable dirty check and always try to create a commit and push
    skip_dirty_check: true    
    
    # Optional. Skip internal call to `git fetch`
    skip_fetch: true    
    
    # Optional. Skip internal call to `git checkout`
    skip_checkout: true

    # Optional. Prevents the shell from expanding filenames. 
    # Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
    disable_globbing: true

    # Optional. Create given branch name in local and remote repository.
    create_branch: true

Please note that the Action depends on bash. If you're using the Action in a job in combination with a custom Docker container, make sure that bash is installed.

Example Workflow

In this example, we're running php-cs-fixer in a PHP project to fix the codestyle automatically, then commit possible changed files back to the repository.

Note that we explicitly specify ${{ github.head_ref }} in the checkout Action. This is required in order to work with the pull_request event (or any other non-push event).

name: php-cs-fixer

on:
  pull_request:
  push:
    branches:
      - main

jobs:
  php-cs-fixer:
    runs-on: ubuntu-latest

    permissions:
      # Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
      contents: write

    steps:
    - uses: actions/checkout@v4
      with:
        ref: ${{ github.head_ref }}

    - name: Run php-cs-fixer
      uses: docker://oskarstark/php-cs-fixer-ga

    - uses: stefanzweifel/git-auto-commit-action@v5
      with:
        commit_message: Apply php-cs-fixer changes

Inputs

Checkout action.yml for a full list of supported inputs.

Outputs

You can use these outputs to trigger other Actions in your Workflow run based on the result of git-auto-commit-action.

  • changes_detected: Returns either "true" or "false" if the repository was dirty and files have changed.
  • commit_hash: Returns the full hash of the commit if one was created.

⚠️ When using outputs, the step needs to be given an id. See example below.

Example

  - uses: stefanzweifel/git-auto-commit-action@v5
    id: auto-commit-action #mandatory for the output to show up in ${{ steps }}
    with:
      commit_message: Apply php-cs-fixer changes

  - name: "Run if changes have been detected"
    if: steps.auto-commit-action.outputs.changes_detected == 'true'
    run: echo "Changes!"

  - name: "Run if no changes have been detected"
    if: steps.auto-commit-action.outputs.changes_detected == 'false'
    run: echo "No Changes!"

Limitations & Gotchas

The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore, you might run into issues if your Workflow falls into the not supported 20% portion.

The following is a list of edge cases the Action knowingly does not support:

No git pull when the repository is out of date with remote. The Action will not do a git pull before doing the git push. You are responsible for keeping the repository up to date in your Workflow runs.

No support for running the Action in build matrices. If your Workflow is using build matrices, and you want that each job commits and pushes files to the remote, you will run into the issue, that the repository in the workflow will become out of date. As the Action will not do a git pull for you, you have to do that yourself.

No support for git rebase or git merge. There are many strategies on how to integrate remote upstream changes to a local repository. git-auto-commit does not want to be responsible for doing that.

No support for detecting line break changes between CR (Carriage Return) and LF (Line Feed). This is a low level issue, you have to resolve differently in your project. Sorry.

If this Action doesn't work for your workflow, check out EndBug/add-and-commit.

Checkout the correct branch

You must use action/checkout@v2 or later versions to check out the repository. In non-push events, such as pull_request, make sure to specify the ref to check out:

- uses: actions/checkout@v4
  with:
    ref: ${{ github.head_ref }}

Do this to avoid checking out the repository in a detached state.

Commits made by this Action do not trigger new Workflow runs

The resulting commit will not trigger another GitHub Actions Workflow run. This is due to limitations set by GitHub.

When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.

You can change this by creating a new Personal Access Token (PAT), storing the token as a secret in your repository and then passing the new token to the actions/checkout Action step.

- uses: actions/checkout@v4
  with:
    token: ${{ secrets.PAT }}

If you create a personal access token, apply the repo and workflow scopes.

If you work in an organization and don't want to create a PAT from your personal account, we recommend using a robot account for the token.

Change to file is not detected

Does your workflow change a file, but "git-auto-commit" does not detect the change? Check the .gitignore that applies to the respective file. You might have accidentally marked the file to be ignored by git.

Advanced Uses

Multiline Commit Messages

If your commit message should span multiple lines, you have to create a separate step to generate the string.

The example below can be used as a starting point to generate a multiline commit meesage. Learn more how multiline strings in GitHub Actions work in the GitHub documentation.

    # Building a multiline commit message
    # Adjust to your liking
    - run: echo "Commit Message 1" >> commitmessage.txt
    - run: echo "Commit Message 2" >> commitmessage.txt
    - run: echo "Commit Message 3" >> commitmessage.txt

    # Create a multiline string to be used by the git-auto-commit Action
    - name: Set commit message
      id: commit_message_step
      run: |
        echo 'commit_message<<EOF' >> $GITHUB_OUTPUT
        cat commitmessage.txt >> $GITHUB_OUTPUT
        echo 'EOF' >> $GITHUB_OUTPUT

    # Quick and dirty step to get rid of the temporary file holding the commit message
    - run: rm -rf commitmessage.txt

    - uses: stefanzweifel/git-auto-commit-action@v5
      id: commit
      with:
        commit_message: ${{ steps.commit_message_step.outputs.commit_message }}

Signing Commits & Other Git Command Line Options

Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regularly.

Use in forks from private repositories

By default, GitHub Actions doesn't run Workflows on forks from private repositories. To enable Actions for private repositories enable "Run workflows from pull requests" in your repository settings.

See this announcement from GitHub or the GitHub docs for details.

Use in forks from public repositories

Note

This Action technically works with forks. However, please note that the combination of triggers and their options can cause issues. Please read the documentation on which triggers GitHub Actions support.
Ensure your contributors enable "Allow edits by maintainers" when opening a pull request. (Learn more)

If you use this Action in combination with a linter/fixer, it's easier if you run the Action on push on your main-branch.

Warning

Due to limitations of GitHub, this Action currently can't push commits to a base repository, if the fork lives under an organisation. See github/community#6634 and this comment for details.

By default, this Action will not run on Pull Requests which have been opened by forks. (This is a limitation by GitHub, not by us.)
However, there are a couple of ways to use this Actions in Workflows that should be triggered by forked repositories.

Workflow should run in base repository

Caution

The following section explains how you can use git-auto-commit in combination with the pull_request_target trigger.
Using pull_request_target in your workflows can lead to repository compromise as mentioned by GitHub's own security team. This means, that a bad actor could potentially leak/steal your GitHub Actions repository secrets.
Please be aware of this risk when using pull_request_target in your workflows.

If your workflow runs code-fixing tools, consider running the workflow on your default branch by listening to the push event or use a third-party tool like autofix.ci.
We keep this documentation around, as many questions came in over the years, on how to use this action for public forks.

The workflow below runs whenever a commit is pushed to the main-branch or when activity on a pull request happens, by listening to the pull_request_target event.

If the workflow is triggered by the pull_request_target-event, the workflow will run in the context of the base of the pull request, rather than in the context of the merge commit, as the pull_request event does. In other words, this will allow your workflow to be run in the repository where the pull request is opened to and will push changes back to the fork.

Check out the discussion in #211 for more information on this.

name: Format PHP

on:
  push:
    branches:
      - main
  pull_request_target:

jobs:
  php-cs-fixer:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
    - uses: actions/checkout@v4
      with:
        # Checkout the fork/head-repository and push changes to the fork.
        # If you skip this, the base repository will be checked out and changes
        # will be committed to the base repository!
        repository: ${{ github.event.pull_request.head.repo.full_name }}

        # Checkout the branch made in the fork. Will automatically push changes
        # back to this branch.
        ref: ${{ github.head_ref }}

    - name: Run php-cs-fixer
      uses: docker://oskarstark/php-cs-fixer-ga

    - uses: stefanzweifel/git-auto-commit-action@v5

For more information about running Actions on forks, see this announcement from GitHub.

Using --amend and --no-edit as commit options

If you would like to use this Action to create a commit using --amend and --no-edit you need to make some adjustments.

Caution

You should understand the implications of rewriting history if you amend a commit that has already been published. See rebasing.

First, you need to extract the previous commit message by using git log -1 --pretty=%s. Then you need to provide this last commit message to the Action through the commit_message input option.

By default, the commit author is changed to username <[email protected]>, where username is the name of the user who triggered the workflow (The github.actor context is used here). If you want to preserve the name and email of the original author, you must extract them from the last commit and provide them to the Action through the commit_author input option.

Finally, you have to use push_options: '--force' to overwrite the git history on the GitHub remote repository. (git-auto-commit will not do a git-rebase for you!)

The steps in your workflow might look like this:

- uses: actions/checkout@4
  with:
    # Fetch the last 2 commits instead of just 1. (Fetching just 1 commit would overwrite the whole history)
    fetch-depth: 2

# Other steps in your workflow to trigger a changed file

- name: Get last commit message
  id: last-commit
  run: |
    echo "message=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
    echo "author=$(git log -1 --pretty=\"%an <%ae>\")" >> $GITHUB_OUTPUT

- uses: stefanzweifel/git-auto-commit-action@v5
  with:
    commit_author: ${{ steps.last-commit.outputs.author }}
    commit_message: ${{ steps.last-commit.outputs.message }}
    commit_options: '--amend --no-edit'
    push_options: '--force'
    skip_fetch: true

See discussion in #159 for details.

Troubleshooting

Action does not push commit to repository

Make sure to checkout the correct branch.

Action does not push commit to repository: Authentication Issue

If your Workflow can't push the commit to the repository because of authentication issues, please update your Workflow configuration and usage of actions/checkout.

Updating the token value with a Personal Access Token should fix your issues.

Push to protected branches

If your repository uses protected branches you have to make some changes to your Workflow for the Action to work properly: You need a Personal Access Token and you either have to allow force pushes or the Personal Access Token needs to belong to an Administrator.

First, you have to create a new Personal Access Token (PAT), store the token as a secret in your repository and pass the new token to the actions/checkout Action step.

- uses: actions/checkout@v4
  with:
    token: ${{ secrets.PAT }}

You can learn more about Personal Access Token in the GitHub documentation.

Tip

If you're working in an organisation, and you don't want to create the PAT from your personal account, we recommend using a bot-account for such tokens.

If you go the "force pushes" route, you have to enable force pushes to a protected branch (see documentation) and update your Workflow to use force push like this.

    - uses: stefanzweifel/git-auto-commit-action@v5
      with:
        commit_message: Apply php-cs-fixer changes
        push_options: --force

No new workflows are triggered by the commit of this action

This is due to limitations set up by GitHub, commits made by this Action do not trigger new Workflow runs.

Pathspec 'x' did not match any files

If you're using the Action with a custom file_pattern and the Action throws a fatal error with the message "Pathspec 'file-pattern' did not match any files", the problem is probably that no file for the pattern exists in the repository.

file_pattern is used both for git-status and git-add in this Action. git-add will throw a fatal error, if for example, you use a file pattern like *.js *.ts but no *.ts files exist in your projects' repository.

See Issue #227 for details.

Custom file_pattern, changed files but seeing "Working tree clean. Nothing to commit." in the logs

If you're using a custom file_pattern and the Action does not detect the changes made in your worfklow, you're probably running into a globbing issue.

Let's imagine you use file_pattern: '*.md' to detect and commit changes to all Markdown files in your repository. If your Workflow now only updates .md-files in a subdirectory, but you have an untouched .md-file in the root of the repository, the git-auto-commit Action will display "Working tree clean. Nothing to commit." in the Workflow log.

This is due to the fact, that the *.md-glob is expanded before sending it to git-status. git-status will receive the filename of your untouched .md-file in the root of the repository and won't detect any changes; and therefore the Action does nothing.

To fix this add disable_globbing: true to your Workflow.

- uses: stefanzweifel/git-auto-commit-action@v5
  with:
    file_pattern: '*.md'
    disable_globbing: true

See Issue #239 for details.

Running the tests

The Action has tests written in bats. Before you can run the test suite locally, you have to install the dependencies with npm or yarn.

npm install
yarn

You can run the test suite with npm or yarn.

npm run test
yarn test

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

We also provide major version tags to make it easier to always use the latest release of a major version. For example, you can use stefanzweifel/git-auto-commit-action@v5 to always use the latest release of the current major version. (More information about this here.)

Credits

This Action has been inspired and adapted from the auto-commit-Action of the Canadian Digital Service and this commit-Action by Eric Johnson.

License

This project is licensed under the MIT License - see the LICENSE file for details.

git-auto-commit-action's People

Contributors

clxmstaab avatar couling avatar cristianpb avatar dependabot[bot] avatar docwhat avatar ericcornelissen avatar fty4 avatar funkjedi avatar gomorizsolt avatar harrisongrodin avatar jkaan avatar jooola avatar karolswdev avatar kenodegard avatar localheinz avatar mattdfloyd avatar npanuhin avatar oskarstark avatar parndt avatar pedroamador avatar ryudaitakai avatar spawnia avatar stefanzweifel avatar teko012 avatar tgtgamer avatar tupaschoal avatar webignition avatar zcong1993 avatar zerorin avatar zhangyoufu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-auto-commit-action's Issues

[FEATURE REQUEST] Support custom git params

Our team uses pre-commit to ensure certain tests pass before committing the changes. However, in some cases, it's unnecessary to run these scripts(e.g. when editing README.md) and so we're able to skip them by appending the --no-verify param to the command.

Example

git commit -m "John Doe" --no-verify

What's your opinion on this feature? Can you see any security issue?

[FEATURE REQUEST] Support custom file pattern

There might be some cases when:

  • the user isn't entirely sure what additional files the workflow/job outputs
  • or just simply wouldn't like to push certain changes, e.g. to master

Wouldn't it be beneficial to accept an optional param to support customizing the file pattern? As I see, specifying the files leads to a much more reliable action.

How to solve this

Link of my github action log:
https://github.com/neodevpro/neodevhost/runs/700663950?check_suite_focus=true

Your branch is up to date with 'origin/master'.
INPUT_FILE_PATTERN: .
INPUT_COMMIT_OPTIONS: --no-verify --signoff
[master e678af0] Auto Update
Author: FusionPlmH [email protected]
9 files changed, 5 insertions(+), 8149 deletions(-)
INPUT_TAGGING_MESSAGE:
No tagging message supplied. No tag will be added.
INPUT_PUSH_OPTIONS: --force
remote: Permission to neodevpro/neodevhost.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/neodevpro/neodevhost/': The requested URL returned error: 403
Error: Invalid status code: 128
at ChildProcess. (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
code: 128

Add "push_options" Input for easier configuration for git-push

Is your feature request related to a problem? Please describe.
Users with protected branches can't easily do a force push to their repo.
#71 (comment)

Describe the solution you'd like
Instead of just adding a force-option, it would make sense to add a push_options-input. User could then write their own logic which will then be passed to the git push command.

Describe alternatives you've considered
None

Additional context
In the README, we would have to make clear, that using git push --force can be dangerous.

How to make changes in a commited branch.

Version of the Action
v4.2.0

Describe the bug
If we run this twice and we have changes in existing target branch, the actions throw error since its expecting that there are other changes in current branch in remote. Possible fix is to allow a -f option to push.

To Reproduce
Refer workflow

Expected behavior
The idea was to run a periodic job which can run every week and update the timestamp in some files, pushes from master to some branch. If there exists a branch with unmerged changes to master, possibly overwrite those changes forcefully.

Screenshots

[tf-drift/build]   ⚙  ::set-output:: changes_detected=true
| INPUT_BRANCH value: drift
| error: Your local changes to the following files would be overwritten by checkout:
| 	conf/account-dns/terragrunt.hcl
| 	conf/account-settings/terragrunt.hcl
| 	conf/cdn/terragrunt.hcl
| 	conf/chamber/terragrunt.hcl
| 	conf/cloudtrail/terragrunt.hcl
| 	conf/config/terragrunt.hcl
| 	conf/ecr/terragrunt.hcl
| 	conf/eks/terragrunt.hcl
| 	conf/guard-duty/terragrunt.hcl
| 	conf/iam/terragrunt.hcl
| 	conf/inspector/terragrunt.hcl
| 	conf/kube-platform/terragrunt.hcl
| 	conf/secrets/terragrunt.hcl
| 	conf/service-roles/terragrunt.hcl
| 	conf/tools/terragrunt.hcl
| 	conf/waf/terragrunt.hcl
| Please commit your changes or stash them before you switch branches.
| Aborting
| Error: Invalid status code: 1
|     at ChildProcess.<anonymous> (/actions/[email protected]/index.js:17:19)
|     at ChildProcess.emit (events.js:311:20)
|     at maybeClose (internal/child_process.js:1021:16)
|     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {
|   code: 1
| }
| Error: Invalid status code: 1
|     at ChildProcess.<anonymous> (/actions/[email protected]/index.js:17:19)
|     at ChildProcess.emit (events.js:311:20)
|     at maybeClose (internal/child_process.js:1021:16)
|     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
[tf-drift/build]   ❌  Failure - stefanzweifel/[email protected]

Used Workflow

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        ref: master
    - run: |
        git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
    - run: for files in $(ls -1A conf/**/terragrunt.hcl); do sed -i '$d' $files && echo $(date '+%d/%m/%Y %H:%M:%S') >> $files ; done;
    - uses: stefanzweifel/[email protected]
      with:
        commit_message: Apply automatic terraform drift
        branch: drift
      env:
        GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}```

commit_options doesn't work with multiple arguments

Version of the Action
v4.1.2

Describe the bug
commit_options option treats space separated arguments as one.

To Reproduce
Use commit_options with multiple arguments like described in README.
I tried both --no-verify --signoff and '--no-verify --signoff' although there should be no difference.
I also tried passing a sequence:

commit_options:
  - '--no-verify'
  - '--no-verify'

but that didn't work either.

Expected behaviour
Arguments to be passed individually instead of being treated as one.
Either the example is wrong and a yaml list should be passed.

Used Workflow

name: clang-format
env:
  CI_BUILD: true

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  format:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Install clang-format
        run: |
          sudo apt-get update -m
          sudo apt-get install clang-format-9
      - name: Run clang-format
        run: clang-format-9 -i $(find -iregex "./src/.*\.[hc]pp" -or -iregex "./include/.*\.[hc]pp" -or -iregex "./test/.*\.[hc]pp" -or -iregex "./fuzz_test/.*\.[hc]pp")
      - name: Install cmake-format
        run: |
          sudo apt-get install python3
          sudo pip install --upgrade pip
          sudo pip install cmake-format
      - name: Run cmake-format
        run: cmake-format -i -c ".cmake-format.yaml" $(find -iregex "./.*\.cmake" -or -name "CMakeLists.txt")
      - uses: stefanzweifel/[email protected]
        with:
          commit_message: Applied automatic formatting
          branch: ${{ github.head_ref }}
          commit_options: --no-verify --signoff
          commit_user_name: Formatting Bot

Also, here's the failed action for convenience.

Can't find branch: pathspec 'branch' did not match any file know to git

Version of the Action
v4

Describe the bug
Because we have a protected develop and master branch, we want to push changelog files to a specific 'changelog' branch. But it seems that the action can't find the branch.

The error message:

Run stefanzweifel/git-auto-commit-action@v4
Started: bash /home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/entrypoint.sh
INPUT_REPOSITORY value: .
INPUT_BRANCH value: changelog
error: pathspec 'changelog' did not match any file(s) known to git
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  code: 1
}
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

Expected behavior
The action pushes and updates the changelog file on the changelog branch.

Used Workflow

name: Changelog

on:
  push:
    branches:
      - develop

jobs:
  write-changelog:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v2
      - name: Update Changelog
        run: echo -en "changes" >$changelog_filepath
        env:
          changelog_filepath: ${{ github.workspace }}/CHANGELOG.md
      - name: Commit changelog
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: Update changelog
          branch: changelog

Thank you!

"tags push" event fails because repo has a detached head

Version of the Action
v4.1.6

Describe the bug
Trying to push from a tag action fails. Repository has a detached head. Originally reported in #69 (comment)

Action trigger is:

  push:
    tags: ["v*"]

git-auto-commit-action fails because the repository is not on a branch.

To Reproduce

  1. Example workflow below, or fork joemaller/push-from-tag-event
  2. Run npm version patch && git push --follow-tags

Expected behavior
Modified README file is committed and updated in the repository.

Additional context
The error message in GitHub Actions is:

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

Error: Invalid status code: 128
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4.1.6/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  code: 128
}
Error: Invalid status code: 128
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4.1.6/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

Sample workflow

name: Push from Tag

on:
  push:
    tags: ["v*"]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Modify Readme
        run: echo $(date) >> README.md

      - name: Commit README
        uses: stefanzweifel/[email protected]
        with:
          commit_message: Update README
          file_pattern: README.md

Fatal Error around head ref

Hey, I'm trying to use this action to build my website on master. I'm seeing changes, but the action isn't setting head right:

[detached HEAD bf27a08] Apply automatic changes
fatal: invalid refspec 'HEAD:'

Here's my action run: https://github.com/RMSD/EdgeSheet/runs/241481009. It's definitely picking up some changes.

Copied straight from the github action marketplace page in my yml:

- name: Auto Commit changed files
      uses: stefanzweifel/[email protected]
      with:
        commit_message: Apply automatic changes
        branch: ${{ github.head_ref }}
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

https://github.com/RMSD/EdgeSheet/blob/master/.github/workflows/deployment.yml

Am I just misreading the docs, or is this a legit error? It seems like github.head_ref is supposed to be a legit env variable from GH.

Private repo?

Hi, I'm trying to use this in a repo that is private. I get this error:

remote: Repository not found.
fatal: repository 'https://github.com/ourcompany/ourapp/' not found
##[error]Docker run failed with exit code 128

Is there some other setup I need to do?

Right now I have:

    - uses: stefanzweifel/[email protected]
      with:
        commit_message: Update file
        branch: ${{ github.head_ref }}
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_BOT_TOKEN }}

actions.yml cleanup

Following lines could be deleted as not used

  args:
    - ${{ inputs.commit_message }}
    - ${{ inputs.commit_options }}
    - ${{ inputs.branch }}
    - ${{ inputs.file_pattern }}
    - ${{ inputs.repository }}

Issue with commit_options - error: unknown switch ` '

Version of the Action
v4.1.3

Describe the bug
Error during task execution: error: unknown option --no-verify --signoff --verbose` as you can see (a workaround I've tried) here:
https://github.com/crossuo/shards/runs/606923804?check_suite_focus=true#step:4:17
or even this as suggested in the readme:
https://github.com/crossuo/shards/runs/606911285?check_suite_focus=true#step:4:17

To Reproduce
Copy-paste the first sample in readme with almost no modification

globbing syntax is limited

Version of the Action
v4.1.0

Describe the bug
Maybe this only requires a bit more documentation. However, it's not clear which syntax file_pattern uses, and under what conditions. Is it a bash glob? Or some other language? Why are the asterixes escaped? The bash syntax \{\*\*/PKGBUILD,\*\*/.SRCINFO\} does not work (escaped out so Workflows doesn't complain about the syntax), and neither does \*\*/PKGBUILD \*\*/.SRCINFO or any combination of syntax I've tried. Wrapping the glob in quotes, various permutations of escaping; I've tried several things.

Curiously, I can see globbing working, except it fails somehow when actually doing the git commit. In many cases, I get errors like:

INPUT_BRANCH value: 
M	aur-bin/.SRCINFO
M	aur-bin/PKGBUILD
M	aur/.SRCINFO
M	aur/PKGBUILD
Your branch is up to date with 'origin/master'.
INPUT_FILE_PATTERN: \{\*\*/PKGBUILD,\*\*/.SRCINFO\}
fatal: pathspec '\{\*\*/PKGBUILD,\*\*/.SRCINFO\}' did not match any files

so the log message is actually getting a proper glob list, but it fails in the actual message.

It'd be great to get some documentation about what is legal glob syntax, and maybe another example of non-trivial globbing. In my case, I'm looking for the result of the bash glob pattern:

{**/PKGBUILD,**/.SRCINFO}

To Reproduce
Make a project in github called globtest

mkdir -p dummy/A dummy/B dummy/.github/workflows/
pushd dummy
touch A/x A/y B/x B/y
cat > .github/workflows/dummy.yml <<EOL
name: dummy
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Get version
        shell: bash
        run: echo 1 > A/x ; echo 2 > A/y ; echo 3 > B/x ; echo 4 > B/y
      - uses: stefanzweifel/[email protected]
        with:
            commit_message: Message
            file_pattern: \{\*\*/x,\*\*/y\}
EOL
git init && git add . && git commit -m "X"
git remote add origin [email protected]:stefanzweifel/globtest.git
git push -f origin master
touch me && git commit -a -m "foo" && git push

Expected behavior
All changed files to be committed.

I didn't try any of that blob of steps above, so YMMV. But you get the idea.

"All checks have passed" disappears

Version of the Action
v2.5.0

Describe the bug
This isn't really a bug, but it's also not a feature request. It is a problem however.

The "All checks have passed" part of the pull request disappers when this action is run.

To Reproduce
Steps to reproduce the behavior:

  1. Run a workflow that runs some actions (but not this one)
  2. When they complete you'll get "All checks have passed, X successful checks"
  3. Run a workflow using this action (or a manual commit).
  4. The "All checks have passed" disappears, I assume because the pull request has now changed.

Expected behavior
The "All checks have passed" part should still display after the commit.

question: trigger a new CI build on commit

Hi there, thanks for this great little github action! We use it to do some automatic cleanup of commits from another bot. I'm in a situation now where I have to push another commit manually in order to be able to merge the PR because this action doesn't trigger another CI build so the last commit on the branch doesn't have the required status checks. Is there some way to circumvent this? I guess I could have a job follow this action to trigger a new build?

Automatically approve pull requests

If the branch requires a review before the merge, the action gives an error:

! [remote rejected] HEAD -> master (protected branch hook declined)

In this regard, is it possible to add to the action automatic approval of pull requests or use with it something like this: hmarr/auto-approve-action?

How to use environment variables in a commit message?

I'd like to use the following commit message to print the commit hash from my PR into the commit to the GitHub Pages branch:

- uses: stefanzweifel/git-auto-commit-action@v4
  with:
    commit_message: Update files with commit $GITHUB_SHA
    branch: gh-pages

Unfortunately, the environment variable $GITHUB_SHA is not replaced, even though it is available by default.

Is there a way to use environment variables in a commit message?

Fatal error when auto-commit

Hello,

I tried to use your action but it doesn't work, I have a fatal error at the end.

Run stefanzweifel/[email protected]
  env:
    GITHUB_TOKEN: ***
    COMMIT_MESSAGE: hello
    COMMIT_AUTHOR_NAME: CS Fixer
    COMMIT_AUTHOR_EMAIL: [email protected]
/usr/bin/docker run --name b3e3f72439fc3af08948f989a19a825463598a_d79f18 --label b3e3f7 --workdir /github/workspace --rm -e GITHUB_TOKEN -e COMMIT_MESSAGE -e COMMIT_AUTHOR_NAME -e COMMIT_AUTHOR_EMAIL -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/php-mime-mail-parser/php-mime-mail-parser":"/github/workspace" b3e3f7:2439fc3af08948f989a19a825463598a
HEAD detached at 8866c5a
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	new file:   build/logs/clover.xml
	new file:   test.log

[detached HEAD 84cac5b] hello
 Author: CS Fixer <[email protected]>
 2 files changed, 515 insertions(+)
 create mode 100644 build/logs/clover.xml
 create mode 100644 test.log
fatal: could not read Username for 'https://github.com': No such device or address
##[error]Docker run failed with exit code 128

FYI my step action:

    - name: Auto Commit changed files
      uses: stefanzweifel/[email protected]
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        COMMIT_MESSAGE: "hello"
        COMMIT_AUTHOR_NAME: "CS Fixer"
        COMMIT_AUTHOR_EMAIL: "[email protected]"

Support for Git LFS

Hi there! I am wondering if it is possible to support Git LFS with this tool.

Is there a way that I could overwrite the Dockerfile or something so that I could install Git LFS before?

error: pathspec '...' did not match any file(s) known to git

Hi,

I was trying your github action for a personnal project and end up with that stack trace

Run stefanzweifel/[email protected]
/usr/bin/docker run --name bb812c55c43200fd4a7694090566760cb690_af6ffa --label 04bb81 --workdir /github/workspace --rm -e GITHUB_TOKEN -e INPUT_COMMIT_AUTHOR_EMAIL -e INPUT_COMMIT_AUTHOR_NAME -e INPUT_COMMIT_MESSAGE -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/git-action-playground-v2/git-action-playground-v2":"/github/workspace" 04bb81:2c55c43200fd4a7694090566760cb690
Checking for uncommitted changes in the git working tree.
error: pathspec '2/merge' did not match any file(s) known to git
##[error]Docker run failed with exit code 1

I searched a bit for this error, and it seems that maybe git does not know the branch i'm trying to checkout (https://stackoverflow.com/questions/5989592/git-cannot-checkout-branch-error-pathspec-did-not-match-any-files-kn)

I think the trick is maybe to add git fetch to your entrypoint.sh to be sure git know all the branches

Error when run this action on pull_request event

Version of the Action
v4.1.15

Describe the bug
When workflow use this action was triggered with pull_request

To Reproduce
Steps to reproduce the behavior:

  1. Add on: [pull_request] to workflow.yml
  2. Commit anything
  3. See error

Expected behavior
This action will fail due to how actions/checkout@v2 handle pull_request event with default ref parameter

Screenshots

image

Additional context
When I have a look at actions/checkout@v2 log or run git branch to debug, seems like it reinitialized .git folder and only has this branch: refs/remotes/pull/1/merge (see image below)
Which leads to, when your action checking out ${{ github.head_ref }} it will report error.
image

Potential fix
Provide ref: ${{ github.head_ref }} to force actions/checkout@v2, checkout the "right way"

on: [pull_request]

jobs:
  test-my-action:
    runs-on: ubuntu-latest
    name: Testing auto log committer action
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}

Make branch optional

Is your feature request related to a problem? Please describe.

I mainly use the action to compile code (e.g. rst to html). Which happens in PR branches on pushing, not in pull request. Currently, I either need to hardcode branch (e.g. master), or add an extra step like following:

    - run: |
        BRANCH="${GITHUB_REF:11}"
        echo "::set-env name=BRANCH::$BRANCH"
    - name: Commit changes
      uses: stefanzweifel/[email protected]
      with:
        branch: ${{ env.BRANCH }}

Describe the solution you'd like

When not set, the branch should be computed. It could be something like this;

BRANCH=${INPUT_BRANCH}
if [[ -z "$INPUT_BRANCH ]]
then
    BRANCH=${GITHUB_REF:11}
fi

Custom 'git add' options or just force add

Is your feature request related to a problem? Please describe.
I want to generate some files automatically and commit/push them back to my repository(same branch) after push. But the generated files are ignored, because of '.gitignore' file. Git can't track the files, so that no commit/push.

Describe the solution you'd like
If I can custom 'git add' command options, I will add '--force' option to ignore '.gitignore' file.

Describe alternatives you've considered
I know I can modify '.gitignore' file to solve my problem, but If I don't ignore the generated files, I must fetch them to local after each push(if the generated files changed).
Just a small function, can you help me?

Question: Signing off commits

Heya guys,

Possibly a stupid question, but I'm doing circles at the moment.

I want to have my workflow signoff the commit, but can't figure out how to do it and the documentation isn't amazing for this xD

You can see the pull request I made to test this here: Resnovas/workflow-mastermind#22
Here's my workflow:

name: Documentation

on:
  push:
    branches:
      - master
      - docs/auto-update
    paths:
      - "docs/**"
      - "README.md"
      - "CHANGELOG.md"

jobs:

  # Automatically copies and renames README, SUMMARY & CHANGELOG to be correct for both github Wiki and Gitbook
  copyfiles:
    name: Copy & Rename docs files
    runs-on: ubuntu-latest
    if: github.event_name != 'gollum'
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Copy Files
        run: |
          cp README.md docs/README.md
          cp README.md docs/Home.md
          cp docs/SUMMARY.md docs/_Sidebar.md
          cp CHANGELOG.md docs/information/changelog.md
      - name: Commit files
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: 'docs: update'
          branch: 'docs/auto-update'
          commit_options: ' --signoff'
          push_options: '--force'
      - name: pull-request
        uses: repo-sync/pull-request@v2
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          source_branch: 'docs/auto-update'
          destination_branch: "master"
          pr_title: "docs: auto-update"
          pr_body: ":crown: *An automated PR*"
          pr_label: "skip-changelog"
      - name: Merge me!
        uses: ridedott/merge-me-action@master
        with:
          GITHUB_LOGIN: github-actions
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          MERGE_METHOD: REBASE

Option to tag the commit as well

Describe the solution you'd like
An optional tag: key with which to tag the commit.

Additional context
This would be useful when the action is being used on an ancillary repository to synchronize workflows.

In my case, I have a project that, when published, triggers a number of other project workflows to start; these helper workflows do things like update Homebrew recipes and build Arch AUR packages. I'm using git-auto-commit-action to commit the changes being made by the workflows; it'd be great if the repos could also be tagged with the same tag as the upstream project tag that kicked everything off; for this, I'd need git-auto-commit-action to also tag the commit.

Push without branch broken in 4.1 but works in 3.0.0

Version of the Action
v4.1.0

Describe the bug
The push when no branch is specified just doesn't make it back to Github in V4.1.0 while it does work in v3.0.0

To Reproduce
Steps to reproduce the behaviour:

  1. Using v4.1.0 I expect after the commit the push back to the originating branch to occur. Instead I get an "everything is up to date" message.
    https://github.com/TSSF-Asia-Pacific/communityobedience/runs/506933775?check_suite_focus=true#step:4:21

Expected behaviour
Instead of everything is up to date, it should show that it pushed back to the branch, like it does in v3.0.0
https://github.com/TSSF-Asia-Pacific/communityobedience/runs/506938310?check_suite_focus=true#step:5:19

[5.0] Rewrite Action to run in nodejs environment / JavaScript rewrite

As filed in #18, this Action currently doesn't run in a nodejs environment and does not have access to node. Therefore tools like husky currently can't be used.

I've thought about this issue for quite a while now and can see that it would be beneficial for users, if they could use the Action in any environment. (In addition, it would make it easier to add a test suite to the project).

However, I'm also not the biggest fan of converting this Action into a JavaScript project. The code is currently quite simple and does it's job well (It's basically just a shell script with ~50 lines of code). Converting it into JS or even TS requires to add a build process and updating JS dependencies if they become a security thread.

My bandwith is currently limited, as I work on other projects. And as I mentioned, the Action already works for 80% of usecases.


For me or for other users who would like to make this change happen here are some notes:

  • Write Action preferrably in JavaScript and not in TypeScript, so more users can contribute
  • Use one of the following libraries to interact with Git
  • Make the process of building the JS file and creating a new release as easy as possible (maybe even use a GitHub Action for that)

Author and Commiter

There are two main use cases and corresponding ways to sign a commit:

Branch Style

Author=Commiter=Custom User
Example: yelizariev/git-auto-commit-action-demo-app@ac69197

PR Style

Author=Actor
Commiter=GitHub Actions
Example: yelizariev/git-auto-commit-action-demo-app@fcee21e


The questions to discuss:

  • Do we agree about described use cases? I.e. do we need another style, e.g. Author=Commiter=Github Actions
  • Do we want to support both styles in the Action?
  • If yes, how to allow both styles? What could be the configs for it (config name, default values, etc.)

Commits not pushed when tag is defined

git push origin --tags;

At https://github.com/projectlint/OS-lifecycle/runs/628003780?check_suite_focus=true I've found that the tags are being pushed, but it fails because master branch didn't, like it was did at https://github.com/projectlint/OS-lifecycle/runs/451499219?check_suite_focus=true.

I've searching for this and according to https://stackoverflow.com/q/57905137/586382 and https://stackoverflow.com/q/3745135/586382, seems when using the --tags flag only the tags are being send, NOT the commits of the actual branch if not set explicitly in the command line, as it's being done at https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh#L90 when branch name is provided.

Maybe INPUT_BRANCH could be initialized to current branch at https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh#L39-L44 if it's not provided, and code https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh#L75-L92 unified and simplified?

Request of credentials

Version of the Action
v4.1.5

Describe the bug
After upgrading to latest version of the Action, I'm getting an error about needing to define my identity:

[master 9f54f5b] 2020.4.26
 Author: piranna <[email protected]>
 4 files changed, 22 insertions(+), 6 deletions(-)
INPUT_TAGGING_MESSAGE: 2020.4.26

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <runner@fv-az16.rubf4iz3or0uhhn53zl4cow15h.bx.internal.cloudapp.net>) not allowed
Error: Invalid status code: 128
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4.1.5/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  code: 128
}
Error: Invalid status code: 128
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4.1.5/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

You can find my workflow at https://github.com/projectlint/OS-lifecycle/blob/master/.github/workflows/nightly.yml and full Action execution at https://github.com/projectlint/OS-lifecycle/runs/625667062

Question: Commits Fill Up Activity Log

Hi everyone, 😄

I have a simple question, I've configured this action to configure small personal repo; https://github.com/SudharakaP/SudharakaP/blob/master/.github/workflows/trivia-update.yml

So every five minutes the action is triggered and for each time a message goes to my activity log and that fills it up, not enabling to see the activity relevant to the people I follow etc.

image

Is there a way such that this apps commits are not included in the activity log? 🤔

pass dynamic message

Is your feature request related to a problem? Please describe.
want to use generated message

Describe the solution you'd like
read from file

Describe alternatives you've considered
none

Additional context

this https://github.com/wenerme/charts ci use auto-commit, want to use generate message like redis 1.1.1 -> 1.1.2 instead just update mirror

branch not found on pull_request

Version of the Action
v4.1.1

Describe the bug
I have an action to change a config file on pull_request because my master branch is protected. I need the file of the branch being pulled into master committed to the current branch.

name: Setup Jazzy Config
on: [pull_request]
jobs:
   add_permalink:
    runs-on: [ubuntu-latest]
    steps:
      - uses: actions/checkout@v2
      - run: |
          echo $PATH
          sed '$d' .jazzy.yaml > temp
          cat temp > .jazzy.yaml
          rm temp
          echo "github_file_prefix: https://github.com/Capstone-Projects-2020-Spring/iASL-iOS/tree/${{ github.sha }}" >> .jazzy.yaml
      - uses: stefanzweifel/[email protected]
        with:
          commit_message: Apply jazzy config changes
          branch: ${{ github.head_ref }}
          commit_user_name: ApplebaumIan
          commit_user_email: [email protected]
          commit_author: Ian Applebaum <[email protected]>
          commit_options: ''
          token: ${{ secrets.KEY_TOKEN }}

I get this error

Started: bash /home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4.1.1/entrypoint.sh
INPUT_REPOSITORY value: .
"::set-output name=changes_detected::true"
INPUT_BRANCH value: finishJazzySetup
error: pathspec 'finishJazzySetup' did not match any file(s) known to git
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4.1.1/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  code: 1
}
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4.1.1/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

To Reproduce
Steps to reproduce the behavior:

  1. have a protected master branch
  2. write an action that uses on: [pull_request]
  3. branch: ${{ github.head_ref }}
  4. make a pull request and git-auto-commit-action will say that git doesn't recognize the branch.

Expected behavior
git should recognize the current branch of the pull request.

[4.x] Checkout and Commit to local temp branch

Is your feature request related to a problem? Please describe.
It's quite hard to use the Action currently for both the push and pull_request-event.
For the pull_request-event, the actions/checkout-Action has to be configured in a specific way as the Action requires the repo to be checked out in a not-detached state.

Describe the solution you'd like

  • Action should work independently on how actions/checkout is configured (with or without ref)
  • Action should for all events checkout the the code in a temporary branch and commit to that branch

Additional context
See discussion in : #55 (comment)

Autodetect branch breaks on creating orphan

Version of the Action
v4.5.0

Describe the bug
When branch is not specified, this action fails

To Reproduce
Steps to reproduce the behavior:

  1. Create a github action which modifies files on master branch
  2. attempt to use git-auto-commit-action@v4 to create a commit, do not specify the branch
  3. observe the failure

Expected behavior
Previous versions correctly identified the master branch.

Specifying branch: master resolves this issue, but branch is listed as optional in the action description.

Used Workflow

      - name: create commit
        id: commit
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: "Automatic changelog update"
          file_pattern: "gradle.properties CHANGELOG.md"

Github Action Log

Run stefanzweifel/git-auto-commit-action@v4
Started: bash /home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/entrypoint.sh
+ _main
+ _switch_to_repository
+ echo 'INPUT_REPOSITORY value: .'
INPUT_REPOSITORY value: .
+ cd .
+ _git_is_dirty
++ git status -s -- gradle.properties CHANGELOG.md
+ '[' -n ' M CHANGELOG.md
 M gradle.properties' ']'
+ echo '::set-output name=changes_detected::true'
+ _switch_to_branch
+ echo 'INPUT_BRANCH value: '
+ git show-ref --verify --quiet refs/heads/
INPUT_BRANCH value: 
+ git checkout --orphan
error: option `orphan' requires a value
Error: Invalid status code: 129
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  code: 129
}
Error: Invalid status code: 129
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)

Can't find node in PATH, trying to find a node binary on your system

Version of the Action
v2.3.0

Describe the bug
I use husky to run lint before commit. An error appear when the action is call, i think is due to the pre commit.

To Reproduce
This my configuration :

name: Build

on:
  push:
    branches:
    - master

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x]

    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: install
      run: npm install
      
    - name: build
      run: npm run build
      
    - name: Commit changed files
      uses: stefanzweifel/[email protected]
      with:
        commit_message: 📦 Build dist
        branch: master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}

And i run this during the pre commit :

  "lint-staged": {
    "{src,test}/**/*.ts": [
      "prettier --write",
      "git add"
    ]
  },

Expected behavior
Run the pre commit before commit without error.

Screenshots
https://github.com/Kamiapp-fr/kami-collection/runs/322604011
image

Notify when there was no commited changes

At

echo "Working tree clean. Nothing to commit."
, if there's no content to commit, the action exit sucessfully, but there's no way to know if there were commited changes or repo is untouched. I need to know this to prevent to publish a package to npm with nightly changes if there has been no changes. Ideally Github Actions should provide a neutral output as it did in legacy version, but it got removed. Maybe one alternative would be to set an environment variable to notify this.

Not working on a protected branch

Version of the Action
v4.4.0

Describe the bug
Not working with a protected branch despite the project enabling force-pushes.

Screenshots
image

Used Workflow
https://github.com/daos-stack/pipeline-lib/blob/master/.github/workflows/update_pipeline_lib_branch.yml

The failed action: https://github.com/daos-stack/pipeline-lib/runs/900246701?check_suite_focus=true

I was able to push from the CLI:

$ git push origin HEAD:master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 380 bytes | 380.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:daos-stack/pipeline-lib.git
   a1bf9ea..fb2658d  HEAD -> master

Using --amend as commit_options doesn't work when working directory is clean

Hello, thanks for this Action. I'm experiencing some kind of unexpected behavior when using the --amend Git option, which I'm describing below.

Version of the Action
v4.3.0

Describe the bug
When using the --amend Git commit option on the commit_options field, the Action doesn't work if the working directory is clean, showing the message "Working tree clean. Nothing to commit.".

To Reproduce
Steps to reproduce the behavior:

  • Use the --amend option on the commit_options field.
  • When the working directory is empty, nothing is changed.

Expected behavior
The commit should be amended and pushed.

Used Workflow

# Some previews manual Git changes …

    - name: Commit changes
      uses: stefanzweifel/[email protected]
      with:
        commit_message: Bump version to ${{ steps.git-version.outputs.tag }}
        commit_options: --amend  # <-- This is 
        tagging_message: ${{ steps.git-version.outputs.tag }}

Additional context
My purpose is to perform some Git operations generating a new commit, and finally using this action and the --amend option to modify the commit and push it.

Permission denied when trying to push

Hi,
I have basically copied the example config from the readme into my project and I just can't make it work and I need some more eyes to spot the error. I have tried it with and without GITHUB_TOKEN but still no luck. Is there anything i need to configure in the settings? The only 2 protected branches are master and 2.0 but the workflow should work for any PR in my opinion.

Version of the Action
v4

Used Workflow

https://github.com/TYPO3/Surf/blob/d7aac7728fd887ff6397e9f3432d449b9706ba2b/.github/workflows/php_cs_fixer.yaml

Additional context

https://github.com/TYPO3/Surf/pull/403/checks?check_run_id=700669827

Run stefanzweifel/git-auto-commit-action@v4
Started: bash /home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/entrypoint.sh
INPUT_REPOSITORY value: .
INPUT_BRANCH value: feature/add-project-base-path
Already on 'feature/add-project-base-path'
M	src/Task/Test/HttpTestTask.php
Your branch is up to date with 'origin/feature/add-project-base-path'.
INPUT_FILE_PATTERN: .
INPUT_COMMIT_OPTIONS: 
[feature/add-project-base-path 1f3600b] Apply php-cs-fixer changes
 Author: simonschaufi <[email protected]>
 1 file changed, 1 deletion(-)
INPUT_TAGGING_MESSAGE: 
 No tagging message supplied. No tag will be added.
INPUT_PUSH_OPTIONS: 
fatal: unable to access 'https://github.com/TYPO3/Surf/': The requested URL returned error: 504
Error: Invalid status code: 128
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  code: 128
}
Error: Invalid status code: 128
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.