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.92k stars 224 forks source link

New v5.0.1 release broke pushes #328

Closed grossag closed 3 months ago

grossag commented 3 months ago

git-auto-commit Version

v5.0.1

Machine Type

Ubuntu (eg. ubuntu-latest)

Bug description

I am using this workflow to use create-github-app-token to get me a token that can be used to write:

  lint-scons:
    runs-on: [lnxbuild-gh, self-hosted]
    steps:
      - uses: actions/create-github-app-token@v1
        id: app-token
        with:
          app-id: ${{ vars.CREATE_GITHUB_APP_TOKEN_APP_ID }}
          private-key: ${{ secrets.CREATE_GITHUB_APP_TOKEN_PRIVATE_KEY }}
          owner: ${{ github.repository_owner }}
          repositories: "cart"

      - name: Checkout code
        uses: actions/checkout@v4
        with:
          token: ${{ steps.app-token.outputs.token }}

      - name: Lint scons
        uses: psf/black@stable
        with:
          src: "./scons"
          options: ""

      - name: Lint bora/scons
        uses: psf/black@stable
        with:
          src: "./bora/scons"
          options: ""

      - name: Push any changes created by the linter
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "Apply linter fixes"

If black linting wrote any files, the action successfully pushed the files with the v5.0.0 tag but with the new v5.0.1 tag fails with:

error: Your local changes to the following files would be overwritten by checkout:
    bora/scons/products/horizonagent.py

because it checks out the branch before pushing. Is this expected?

Steps to reproduce

I think this can be reproduced with a workflow run on PR that has a vanilla actions/checkout run, modifies a file, then uses this action to push the modified code

Tried solutions

No response

Example Workflow

lint-scons:
    runs-on: [lnxbuild-gh, self-hosted]
    steps:
      - uses: actions/create-github-app-token@v1
        id: app-token
        with:
          app-id: ${{ vars.CREATE_GITHUB_APP_TOKEN_APP_ID }}
          private-key: ${{ secrets.CREATE_GITHUB_APP_TOKEN_PRIVATE_KEY }}
          owner: ${{ github.repository_owner }}
          repositories: "cart"

      - name: Checkout code
        uses: actions/checkout@v4
        with:
          token: ${{ steps.app-token.outputs.token }}

      - name: Lint scons
        uses: psf/black@stable
        with:
          src: "./scons"
          options: ""

      - name: Lint bora/scons
        uses: psf/black@stable
        with:
          src: "./bora/scons"
          options: ""

      - name: Push any changes created by the linter
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "Apply linter fixes"

Relevant log output

024-04-12T17:50:12.9266027Z ##[group]Run stefanzweifel/git-auto-commit-action@v5
2024-04-12T17:50:12.9266869Z with:
2024-04-12T17:50:12.9267352Z   commit_message: Apply linter fixes
2024-04-12T17:50:12.9267983Z   branch: topic/grossag/linter-write
2024-04-12T17:50:12.9268578Z   file_pattern: .
2024-04-12T17:50:12.9269065Z   repository: .
2024-04-12T17:50:12.9269568Z   commit_user_name: github-actions[bot]
2024-04-12T17:50:12.9270443Z   commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com
2024-04-12T17:50:12.9271548Z   commit_author: grossag_euc <grossag_euc@users.noreply.github.com>
2024-04-12T17:50:12.9272378Z   skip_dirty_check: false
2024-04-12T17:50:12.9272965Z   skip_fetch: false
2024-04-12T17:50:12.9273450Z   skip_checkout: false
2024-04-12T17:50:12.9273956Z   disable_globbing: false
2024-04-12T17:50:12.9274474Z   create_branch: false
2024-04-12T17:50:12.9274983Z   internal_git_binary: git
2024-04-12T17:50:12.9275493Z ##[endgroup]
2024-04-12T17:50:12.9585356Z Started: bash /home/bamboo/gh/_work/_actions/stefanzweifel/git-auto-commit-action/v5/entrypoint.sh
2024-04-12T17:50:12.9627309Z INPUT_REPOSITORY value: .
2024-04-12T17:50:12.9628236Z INPUT_STATUS_OPTIONS: 
2024-04-12T17:50:12.9629573Z INPUT_FILE_PATTERN: .
2024-04-12T17:50:13.5558956Z INPUT_BRANCH value: topic/grossag/linter-write
2024-04-12T17:50:18.6123817Z From https://github.com/euc-vdi/cart
<<<redacted a bunch of internal branch names
2024-04-12T17:50:18.7101167Z error: Your local changes to the following files would be overwritten by checkout:
2024-04-12T17:50:18.7102244Z    bora/scons/products/horizonagent.py
2024-04-12T17:50:18.7103091Z Please commit your changes or stash them before you switch branches.
2024-04-12T17:50:18.7103940Z Aborting
2024-04-12T17:50:18.7139953Z Error: Invalid status code: 1
2024-04-12T17:50:18.7141774Z     at ChildProcess.<anonymous> (/home/bamboo/gh/_work/_actions/stefanzweifel/git-auto-commit-action/v5/index.js:17:19)
2024-04-12T17:50:18.7143187Z     at ChildProcess.emit (node:events:514:28)
2024-04-12T17:50:18.7144098Z     at maybeClose (node:internal/child_process:1105:16)
2024-04-12T17:50:18.7145545Z     at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
2024-04-12T17:50:18.7146537Z   code: 1
2024-04-12T17:50:18.7146956Z }
2024-04-12T17:50:18.7147389Z Error: Invalid status code: 1
2024-04-12T17:50:18.7148772Z     at ChildProcess.<anonymous> (/home/bamboo/gh/_work/_actions/stefanzweifel/git-auto-commit-action/v5/index.js:17:19)
2024-04-12T17:50:18.7150008Z     at ChildProcess.emit (node:events:514:28)
2024-04-12T17:50:18.7150770Z     at maybeClose (node:internal/child_process:1105:16)
2024-04-12T17:50:18.7151749Z     at ChildProcess._handle.onexit (node:internal/child_process:305:5)
2024-04-12T17:50:18.7266169Z Post job cleanup.
2024-04-12T17:50:18.8097796Z [command]/usr/bin/git version
2024-04-12T17:50:18.8136232Z git version 2.39.3
stefanzweifel commented 3 months ago

Thanks for reporting @grossag. Will take a look immediately!

grossag commented 3 months ago

Actually I may be wrong here. I am honestly not sure how my workflow worked before because I wasn't following your instructions in how I use actions/checkout. I'll investigate and get back to you.

grossag commented 3 months ago

Sorry, it does look like I was doing it wrong. I don't know how it worked before, but I was using it without passing ref: ${{ github.head_ref }} to actions/checkout and it was working but isn't anymore. I confirmed that today, neither 5.0.0 nor 5.0.1 work with that code but both work as long as I include the ref: line that your README recommends.

Sorry for the confusion!

stefanzweifel commented 3 months ago

@grossag No problem! Glad you could figure out the root cause of the problem.

grossag commented 3 months ago

I wonder if I was partially confused because of the description in https://github.com/marketplace/actions/git-auto-commit . Would it make sense to change that example code's invocation of actions/checkout to include ref:?

stefanzweifel commented 3 months ago

@grossag Sounds like a good idea. Have to double check, if github.head_ref is filled when the workflow is triggered on push.

stefanzweifel commented 3 months ago

This seems to work fine. The README has been updated: https://github.com/stefanzweifel/git-auto-commit-action/commit/4b8a201e31cadd9829df349894b28c54e6c19fe6