EndBug / add-and-commit

:octocat: Automatically commit changes made in your workflow run directly to your repo
MIT License
1.15k stars 117 forks source link

Fails without an error message #640

Closed johnboiles closed 5 months ago

johnboiles commented 6 months ago

Describe the bug Not sure why, but for some reason recently EndBug/add-and-commit has started to fail when trying to make the commit. It had been working fine for me for 1-2 years up until a month or two ago. It fails without a useful error message:

Add input parsed as single string, running 1 git add command.
> Using 'Clang Robot <robot@example.com>' as author.
> Using "Committing clang-format/clang-tidy changes" as commit message.
Internal logs
  > Staging files...
  > Adding files...
  > No files to remove.
  > Checking for uncommitted changes in the git working tree...
  > Found 1 changed files.
  > Fetching repo...
  Error: Error: From https://github.com/[ORGNAME]/[REPONAME]
   * [new branch]      [BRANCHNAME]          -> origin/[BRANCHNAME]
  ... repeats for other branches until the end of the log...

Workflow used

name: Run Clang Tools

on:
  pull_request:
  push:
    branches:
      - main

jobs:
  clangify:
    runs-on:
      group: Beefy
    container:
      image: espressif/idf:v5.1

    steps:
      - uses: actions/checkout@v3
        with:
          repository: ${{ github.event.pull_request.head.repo.full_name }}
          ref: ${{ github.event.pull_request.head.ref }}
          submodules: "recursive"

      - name: Install tools
        run: |
          . $IDF_PATH/export.sh
          idf_tools.py install esp-clang
          pip install --upgrade pyclang

      # See https://github.com/actions/checkout/issues/1169
      - run: git config --system --add safe.directory /__w/embedded-app/embedded-app
        if: github.event_name == 'pull_request'

      - name: Run clang-tidy
        run: |
          . $IDF_PATH/export.sh
          IDF_TOOLCHAIN=clang idf.py -B build-clang clang-check --run-clang-tidy-py scripts/run-clang-tidy.py --run-clang-tidy-options "-fix -header-filter=embedded-app/src/.*" --exclude-paths managed_components --exclude-paths components

      - uses: DoozyX/clang-format-lint-action@v0.16.2
        with:
          source: "./src"
          extensions: "hpp,h,cpp,c"
          clangFormatVersion: 15
          inplace: True

      - uses: EndBug/add-and-commit@v9
        with:
          author_name: Clang Robot
          author_email: robot@example.com
          message: "Committing clang-format/clang-tidy changes"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        if: github.event_name == 'pull_request'

Seems like there's a good chance it's something related to running inside the Docker container possibly, but like I said it stopped working in the last month or so (and we had not changed the workflow since November '23). How do I debug this?

johnboiles commented 6 months ago

I was able to replace EndBug/add-and-commit with the following (which is working fine 🤷)

      - name: "Commit changes if necessary"
        if: github.event_name == 'pull_request'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          if git diff --exit-code 'src/*/*.hpp' 'src/*/*.h' 'src/*/*.cpp' 'src/*/*.c' > /dev/null; then
            echo "No changes to commit"
          else
            git config --global user.name "Clang Robot"
            git config --global user.email "robot@sindarin.com"
            git add 'src/*/*.hpp' 'src/*/*.h' 'src/*/*.cpp' 'src/*/*.c'
            git commit -m "Committing clang-format/clang-tidy changes"
            git push origin HEAD:${{ github.head_ref }}
          fi
johnboiles commented 6 months ago

Ok I think i'm getting somewhere. If I add this to my script, it fails in a similar unhelpful way:

          git fetch origin
          if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
            echo "Newer changes detected on branch. Skipping commit."
            exit 0
          fi

But at least now I get

fatal: remote error: upload-pack: not our ref b226b5856bc8cf842cb65bec7d8adf44e5ae3595
fatal: the remote end hung up unexpectedly
...
Errors during submodule fetch:
    components/esp-nimble-cpp

I'm unable to repro this locally, even with a fresh clone. It doesn't seem to be the obvious culprits (like an un-pushed submodule commit)

johnboiles commented 6 months ago

The culprit seems to be related to using submodules: "recursive". If I add the same thing to checkout on another action, it fails in a similar way.

johnboiles commented 6 months ago

Ok making my git fetch more specific seemed to solve it:

      - name: "Commit changes if necessary"
        if: github.event_name == 'pull_request'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git fetch origin ${{ github.head_ref }}
          echo "HEAD: $(git rev-parse HEAD)"
          echo "UPSTREAM: $(git rev-parse @{u})"
          if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
            echo "Newer changes detected on branch. Skipping commit."
            exit 0
          fi
          if git diff --exit-code 'src/*/*.hpp' 'src/*/*.h' 'src/*/*.cpp' 'src/*/*.c' > /dev/null; then
            echo "No changes to commit"
          else
            git config --global user.name "Clang Robot"
            git config --global user.email "robot@sindarin.com"
            git add 'src/*/*.hpp' 'src/*/*.h' 'src/*/*.cpp' 'src/*/*.c'
            git commit -m "Committing clang-format/clang-tidy changes"
            git push origin HEAD:${{ github.head_ref }}
          fi

I have no idea where this bad ref is coming from. I can't repro the same issue with local clones 🤷. Seems like this is mostly something funky with one of my submodules and not exactly an add-and-commit issue.

For add-and-commit I have two remaining questions:

github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.