stefanzweifel / git-auto-commit-action

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.
MIT License
1.97k stars 226 forks source link

git auto commit failing due to Your local changes to the following files would be overwritten by checkout even after using --force push option. #217

Closed dayananda30 closed 2 years ago

dayananda30 commented 2 years ago

Yes, I set the branch value explicitly but still the issue persists.

Version of the Action v4.14.1

Describe the bug As part of the pipeline, I am checking out the code and running a script which does modifications to existing files in the repository. I am using auto-git-commit action to publish the changes to remote repository but auto commit is failing even after I am specifying force push option.

error: Your local changes to the following files would be overwritten by checkout:
    manifest_files/azure/azure-India/manifest.yaml
Please commit your changes or stash them before you switch branches.
Aborting
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/__w/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:[31](https://github.com/greenqloud/production-deployment-files/runs/6349307047?check_suite_focus=true#step:7:31)4:20)
    at maybeClose (internal/child_process.js:1022:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) {
  code: 1
}
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/__w/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:314:20)
    at maybeClose (internal/child_process.js:1022:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)

To Reproduce Steps to reproduce the behavior: Refer workflow

Expected behavior Changed files should be checked in to remote branch.

Screenshots

Run stefanzweifel/git-auto-commit-action@v4
/usr/bin/docker exec  983faa3e033a06a7a3a8f2a617673d6508d4ff39a99e7fbdf74ee[26](https://github.com/dayananda/pdb/runs/6349307047?check_suite_focus=true#step:7:26)58c338340 sh -c "cat /etc/*release | grep ^ID"
Started: bash /__w/_actions/stefanzweifel/git-auto-commit-action/v4/entrypoint.sh
INPUT_REPOSITORY value: ./manifest_files/azure/
INPUT_STATUS_OPTIONS: 
INPUT_BRANCH value: NFSAAS-34309
error: Your local changes to the following files would be overwritten by checkout:
    manifest_files/azure/azure-India/manifest.yaml
Please commit your changes or stash them before you switch branches.
Aborting
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/__w/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:314:20)
    at maybeClose (internal/child_process.js:1022:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:[28](https://github.com/dayananda/pdb/runs/6349307047?check_suite_focus=true#step:7:28)7:5) {
  code: 1
}
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/__w/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:[31](https://github.com/dayananda/pdb/runs/6349307047?check_suite_focus=true#step:7:31)4:20)
    at maybeClose (internal/child_process.js:1022:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)

Used Workflow

  create_all_manifest_files_for_azure:
      runs-on: [ self-hosted, linux ]
      name: Create Files
      steps:
        - name: Checkout
          uses: actions/checkout@v2
          with:
            fetch-depth: 0

        - name: Create manifest files for azure
          run: |
            chmod +x ./create_files.sh
            ./create_files.sh "all"

        - uses: stefanzweifel/git-auto-commit-action@v4
          with:
            repository: ./manifest_files/azure/
            commit_message: ${{ needs.create_variables_needed_in_jobs.outputs.auto-commit-message-prefix }}-Automated-Change
            push_options: --force
stefanzweifel commented 2 years ago

[…] but auto commit is failing even after I am specifying force push option.

I think using --force as a push option will not help you here. The Action fails to create the commit, not to push the commit back to GitHub.

I think you've mixed up some options in your workflow. The checkout step clones the repository to . but the git-auto-commit-action looks in ./manifest_files/azure/ for a Git repository.

Could it be that you meant to use file_pattern: ./manifest_files/azure/ in git-auto-commit-action? I assume your script changes files inside ./manifest_files/azure/ and you want to only commit those?

    create_all_manifest_files_for_azure:
        runs-on: [ self-hosted, linux ]
        name: Create Files
        steps:
          - name: Checkout
            uses: actions/checkout@v2
            with:
              fetch-depth: 0

          - name: Create manifest files for azure
            run: |
              chmod +x ./create_files.sh
              ./create_files.sh "all"

          - uses: stefanzweifel/git-auto-commit-action@v4
            with:
-             repository: ./manifest_files/azure/
+             file_pattern: ./manifest_files/azure/
              commit_message: ${{ needs.create_variables_needed_in_jobs.outputs.auto-commit-message-prefix }}-Automated-Change
-             push_options: --force
dayananda30 commented 2 years ago

@stefanzweifel , I assume your script changes files inside ./manifest_files/azure/ and you want to only commit those? Yes, Your assumption is right. I want to include only files changed under ./manifest_files/azure/ directory. Let me change the lines as you suggested. Thank so much for prompt response.

dayananda30 commented 2 years ago

closing this issue as changing repository to file_pattern attribute resolved my issue.