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
2.05k stars 230 forks source link

nothing to commit, working tree clean Error: Invalid status code: 1 #204

Closed dmason30 closed 2 years ago

dmason30 commented 2 years ago

Version of the Action v4.x.x

Describe the bug We seem to be getting this error on every run when there are no change. It only started erroring recently. The file it says is modified is a built javascript file but is probably only whitespace changes hence nothing to commit, we have been using this action for over a year without issue until this point.

Unfortunately this is in a private repo so I am unable to link you and have redacted the repository info below but everything else is verbatim.

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_STATUS_OPTIONS: 
INPUT_BRANCH value: 
From https://github.com/xxx/xxx
 * [new branch]      3.23.0         -> origin/3.23.0
 * [new branch]      TA-1911-Cordova-->-Code-Push-->-Ionic/Applow -> origin/TA-1911-Cordova-->-Code-Push-->-Ionic/Applow
 * [new branch]      master         -> origin/master
 * [new tag]         3.22.0         -> 3.22.0
 * [new tag]         3.23.0-beta.0  -> 3.23.0-beta.0
 * [new tag]         3.23.0.alpha.9 -> 3.23.0.alpha.9
M   site/public/vendor/nova-tools/app.js
Your branch is up to date with 'origin/develop'.
INPUT_ADD_OPTIONS: 
INPUT_FILE_PATTERN: .
warning: CRLF will be replaced by LF in site/public/vendor/nova-tools/app.js.
The file will have its original line endings in your working directory
INPUT_COMMIT_OPTIONS: 
INPUT_COMMIT_USER_NAME: GitHub Actions
INPUT_COMMIT_USER_EMAIL: actions@github.com
INPUT_COMMIT_MESSAGE: Publish laravel package assets
INPUT_COMMIT_AUTHOR: dmason30 <dmason30@users.noreply.github.com>
On branch develop
Your branch is up to date with 'origin/develop'.

nothing to commit, working tree clean
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:[17](https://github.com/TMCApplications/TMC-BACKEND/runs/5316717959?check_suite_focus=true#step:10:17):[19](https://github.com/TMCApplications/TMC-BACKEND/runs/5316717959?check_suite_focus=true#step:10:19))
    at ChildProcess.emit (events.js:[21](https://github.com/xxx/xxx/runs/5316717959?check_suite_focus=true#step:10:21)0:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:[28](https://github.com/xxx/xxx/runs/5316717959?check_suite_focus=true#step:10:28)3: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)

Used Workflow

name: "Publish assets"

on:
  push:
    branches:
      - develop

jobs:
  publish:

    runs-on: ubuntu-latest

    env:
      TELESCOPE_ENABLED: true

    name: Publish assets

    defaults:
      run:
        working-directory: site

    services:
      mysql:
        image: mysql:8.0
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: yes
          MYSQL_DATABASE: tmc_test
        ports:
          - 3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}

      - name: Cache composer dependencies
        uses: actions/cache@v2
        with:
          path: ~/.composer/cache/files
          key: dependencies-php-8.0-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            dependencies-php-8.0-composer-

      - name: Setup PHP 8.0
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.0
          extensions: ctype, curl, date, dom, fileinfo, filter, gd, hash, iconv, intl, json, libxml, mbstring, openssl, pcntl, pcre, pdo, pdo_sqlite, pdo_mysql, phar, posix, simplexml, spl, sqlite, tokenizer, tidy, xml, xmlreader, xmlwriter, zip, zlib
          coverage: none

      - name: Reset MySQL root user authentication method
        run: mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports[3306] }} -uroot -e "alter user 'root'@'%' identified with mysql_native_password by ''"

      - name: Prepare Laravel Application
        run: cp .env.testing .env

      - name: Install PHP dependencies (composer)
        run: |
          composer config "http-basic.nova.laravel.com" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_PASSWORD }}"
          composer install --no-interaction

      - name: Run migration and publish
        run: |
          php artisan migrate --force
          composer publish
        env:
          DB_HOST: 127.0.0.1
          DB_PORT: ${{ job.services.mysql.ports[3306] }}

      - uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: Publish laravel package assets
stefanzweifel commented 2 years ago

Thanks for reporting!

It only started erroring recently.

Can you pin-point this to an exact date? The last release (v4.13.1) was on 13th January 2022. v4.13.0 was released on January 10th, which added a new skip_checkout-option.

I have a workflow that runs on a schedule in a repo that regularly has nothing to commit, and it doesn't break the workflow run. 🤔

The file it says is modified is a built javascript file but is probably only whitespace changes hence nothing to commit […]

Even if there are only whitespace changes, these are changes which should be committed.


From the log and workflow, it seems you're not using any special options the Action exposes besides commit_message. Did you maybe – by accident – remove some options? (commit_options, status_options, push_options, add_options)

Maybe it's related to the trigger? That is ommited from the workflow file too. As you're using github.head_ref I assume it's on pull_request?

dmason30 commented 2 years ago

Thanks for the reply, updated above with full workflow, it only runs on push to the develop branch and the idea is to run composer publish which runs various commands which may modify files and then commit any changes back to develop.

The workflow itself hasn't changed since September 2021 and that was just to bump the PHP version. I'll see if adding skip_checkout or some of the other options helps in some way.

dmason30 commented 2 years ago

I ran the above workflow but changing to use v3 of your action instead and I do not encounter the above error.

Run stefanzweifel/git-auto-commit-action@v3
/usr/bin/docker run --name db2d73ba30ecc82754bdbb2609ffb28a7fd[15](https://github.com/xxx/xxx/runs/5321542307?check_suite_focus=true#step:11:15)_f77e40 --label 7db2d7 --workdir /github/workspace --rm -e TELESCOPE_ENABLED -e COMPOSER_PROCESS_TIMEOUT -e COMPOSER_NO_INTERACTION -e INPUT_COMMIT_MESSAGE -e INPUT_BRANCH -e INPUT_COMMIT_OPTIONS -e INPUT_FILE_PATTERN -e INPUT_REPOSITORY -e INPUT_COMMIT_USER_NAME -e INPUT_COMMIT_USER_EMAIL -e INPUT_COMMIT_AUTHOR -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true --network github_network_2302029a948e46faa76[18](https://github.com/xxx/xxxx/runs/5321542307?check_suite_focus=true#step:11:18)2d4bbdc7b79 -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/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/xxx/xxx":"/github/workspace" 7db2d7:3ba30ecc82754bdbb2609ffb28a7fd15
INPUT_REPOSITORY value: .
INPUT_BRANCH value: 
M   site/public/vendor/nova-tools/app.js
Your branch is up to date with 'origin/develop'.
INPUT_FILE_PATTERN: .
warning: CRLF will be replaced by LF in site/public/vendor/nova-tools/app.js.
The file will have its original line endings in your working directory
INPUT_COMMIT_OPTIONS: 
On branch develop
Your branch is up to date with 'origin/develop'.

nothing to commit, working tree clean

I then ran on 4.0.0 and the error occurs as described in the original post so I guess its some difference between the docker and node environments.

I will just stick with v4 and add continue-on-error: true for now to the step and keep an eye on it to make sure it does commit when there are changes.

stefanzweifel commented 2 years ago

Thanks for the update. Maybe this is related to the working-directory-setting.

    defaults:
      run:
        working-directory: site

But it's weird that the Action finds changes, commits them but in the end can't seem to push it. The message "nothing to commit, working tree clean" also differs slightly from the default "nothing-happend" message from the Action ("Working tree clean. Nothing to commit.").

Even if the Action can't push the commit to remote, it should at least have been echoing INPUT_PUSH_OPTIONS, but it didn't.


I'm closing this issue for now, as I can't seem to find a way to reproduce this. Feel free to reopen if the issue persits on your end.

emepetres commented 2 years ago

Hi @stefanzweifel, I've been able to reproduce it with different versions of v4 (I've tested with v4.11.0, v4.14.1 and v4).

I've notice that both original issue and mine have in common the LF warning: warning: LF will be replaced by CRLF in....

Could be related with it?

- name: Commit if update
  uses: stefanzweifel/git-auto-commit-action@v4.14.1
  with:
    commit_message: Updating Imgui version
    add_options: "-u"
nothing to commit, working tree clean
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (D:\a\_actions\stefanzweifel\git-auto-commit-action\v4.14.1\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) {
  code: 1
}
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (D:\a\_actions\stefanzweifel\git-auto-commit-action\v4.14.1\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)

Full source to reproduce it and logs: https://github.com/EvergineTeam/ImGui.Net/runs/6866268664?check_suite_focus=true

stefanzweifel commented 2 years ago

Hey @emepetres, the Action currently doesn't support to be run on windows-latest unfortunately:

Note that the Action has to be used in a Job that runs on a UNIX system (eg. ubuntu-latest). If you don't use the default permission of the GITHUB_TOKEN, give the Job or Workflow at least the contents: write permission.

As mentioned in this comment, I haven't touched a Windows machine in years. This makes debugging hard. I see you're a .NET-shop and therefore rely on Windows … so this is a bummer of course.

Another user mentioned that he even has issues running the Action on Ubuntu (https://github.com/stefanzweifel/git-auto-commit-action/issues/177#issuecomment-1018275327) which I can't reproduce.

If you have any insights that could make this Action compatible with Windows let me now! Will try to install a Windows VM on my machine in the next few weeks. Maybe I can find a solution.

Grldk commented 2 years ago

@stefanzweifel I think I'm running into this bug too. Although my process is slightly different.

I'm using this action to force commit some css/js assets that are in .gitignore, as a way to manage compiled assets and reduce merge conflicts. This works fine when there are changes in the compiled assets, but fails when there are no changes, similar to other failures in this issue.

I've reproduced this in this repo: https://github.com/Grldk/LaravelTest

As you can see, the first action runs fine because there are actual changes, second actions with an empty commit fails with:

Started: bash /home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/entrypoint.sh
INPUT_REPOSITORY value: .
INPUT_STATUS_OPTIONS: 
INPUT_BRANCH value: 
Your branch is up to date with 'origin/master'.
INPUT_ADD_OPTIONS: -f
INPUT_FILE_PATTERN: public/css/*.css public/js/*.js public/mix-manifest.json
INPUT_COMMIT_OPTIONS: 
INPUT_COMMIT_USER_NAME: github-actions[bot]
INPUT_COMMIT_USER_EMAIL: github-actions[bot]@users.noreply.github.com
INPUT_COMMIT_MESSAGE: Compile Assets
INPUT_COMMIT_AUTHOR: Grldk <Grldk@users.noreply.github.com>
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
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:314: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> (/home/runner/work/_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)
stefanzweifel commented 2 years ago

@Grldk Maybe a silly question, but why are you adding these files to .gitignore just to then force add them in CI? Did you run into so many merge conflicts before? Does this reliably work on your local machine? Did you try this workflow without setting add_options: '-f' and skip_dirty_check : true?

My gut tells me, that this might be related to the findings from here: https://github.com/stefanzweifel/git-auto-commit-action/issues/227#issuecomment-1169075106

The Action breaks on this line when creating the commit: https://github.com/stefanzweifel/git-auto-commit-action/blob/dce7e85096193516db2ae686bd562faf5bc7f4ea/entrypoint.sh#L95-L98. Maybe you would also have to add a commit option to make this work?

Grldk commented 2 years ago

@stefanzweifel Yeah I know it's probably not the cleanest approach, but it does work. Alternative would be to leave compiled assets out completely, and compile them while deploying, but that's not an option for now unfortunately. The merge conflicts did get very annoying.

Without add_options: '-f' and skip_dirty_check : true this workflow does not work. Without those options git will not pick up changes in the compiled assets, because they are in .gitignore...

But thanks for pointing me in the right direction (feel kinda stupid that I missed this myself), it does work when adding the --allow-empty commit option!

stefanzweifel commented 2 years ago

@Grldk Great that it works now! Will definitely add your case to our test suite. Always great to have "real-world"-scenarios covered by tests.

Grldk commented 2 years ago

This does mean that I end up with empty commits in case nothing has changed, which is not the most ideal situation I guess, but that's more a problem of my specific workflow than within the scope of this action probably

stefanzweifel commented 2 years ago

@Grldk I could reproduce your error in a test case: https://github.com/stefanzweifel/git-auto-commit-action/commit/4e7c0d67cd27ac96adcf4d3e06db1070c1a3c4f0

The message nothing to commit, working tree clean comes from git-commit. There's no neat try/catch functionality in Bash to catch this error. What we could do is, add || true to the git-commit command.

Our code would look like this:

git commit -m "$INPUT_COMMIT_MESSAGE" || "$INPUT_SKIP_DIRTY_CHECK";

($INPUT_SKIP_DIRTY_CHECK contains the skip_dirty_check value).

But this fails the "If SKIP_DIRTY_CHECK is set to true on a clean repo it fails to push"-test. What you experience is basically "expected behaviour".

Letting the skip_dirty_check-option dictating this behaviour is probably a bad idea in the long run. Maybe a new no_failure_on_clean_repo option (or something better named) would be a good fit here. (But I'm also torn as I generally don't want to add more options to this Action).

In my mind, letting the Action fail if nothing can be committed if someone explicitly disables the dirty check is also okay. But you seem to have a very unique workflow that just doesn't fit into this Action. 🤔

Grldk commented 2 years ago

@stefanzweifel

But you seem to have a very unique workflow that just doesn't fit into this Action.

That's ok, like I said, it's probably out of your scope. I'd like to move away from this workflow in the long term anyway. Thanks for your time!

JustinElst commented 5 months ago

Unfortunately i have the same workflow, does anyone have a solution for this?

stefanzweifel commented 5 months ago

@JustinElst Which exact workflow do you have? Please share your workflow-yaml file and exact error message and I'm happy to help. :)