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

`commit_user_name` has no effect #287

Closed adamlui closed 1 year ago

adamlui commented 1 year ago

git-auto-commit Version

v4

Machine Type

Ubuntu (eg. ubuntu-latest)

Bug description

Specifying a custom username in commit_user_name has no effect, instead github-actions[bot] is always the committer

Steps to reproduce

In workflow, set commit_user_name to a value that is not github-actions[bot]

Tried solutions

Example Workflow

name: Sync chatgpt/bravegpt to kudoai/bravegpt/greasemonkey

on:
  push:
    branches:
      - master
    paths:
      - 'chatgpt/bravegpt/**'
    if: 'github.actor != "auto-sync[bot]"'

jobs:
  sync-bravegpt:
    runs-on: ubuntu-latest
    steps:

      # Checkout adamlui/userscripts
      - name: Checkout adamlui/userscripts
        uses: actions/checkout@v2
        with:
          token: ${{ secrets.REPO_SYNC_PAT }}
          repository: adamlui/userscripts
          path: adamlui/userscripts

      # Checkout kudoai/bravegpt
      - name: Checkout kudoai/bravegpt
        uses: actions/checkout@v2
        with:
          token: ${{ secrets.REPO_SYNC_PAT }}
          repository: kudoai/bravegpt
          path: kudoai/bravegpt

      # Sync adamlui/userscripts/chatgpt/bravegpt to kudoai/bravegpt/greasemonkey
      - name: Sync bravegpt
        run: rsync -av --delete ${{ github.workspace }}/adamlui/userscripts/chatgpt/bravegpt/ ${{ github.workspace }}/kudoai/bravegpt/greasemonkey/

      # Push to kudoai/bravegpt
      - name: Push changes
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          push_options: '--force'
          add_options: '--all'
          commit_user_name: auto-sync[bot]
          commit_message: '${{ github.event.head_commit.message }} (synced from adamlui/userscripts)'
          file_pattern: 'greasemonkey/*'
          repository: kudoai/bravegpt

Relevant log output

Activity log shows github-actions[bot] as the constant committer despite above YML

image

stefanzweifel commented 1 year ago

Hm, this should definitely work. We have unit tests that cover this feature: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/tests/git-auto-commit.bats#L261-L289

Can you provide a link to a workflow run, where the action used the wrong commit user name?

adamlui commented 1 year ago

Sure hang on let me run one

adamlui commented 1 year ago

https://github.com/adamlui/userscripts/actions/runs/4543504484/jobs/8008272540 w/ commit_user_name: auto-sync[bot] resulted in https://github.com/kudoai/bravegpt/commit/67ae75faa94073cfe6c39089a268d49d9f4c61e4 w/ commit user name github-actions[bot] instead

image

adamlui commented 1 year ago

btw I really love your script and would be extremely happy just syncing w/ the wrong name, but if I could get the custom username to work it would rock my world

lars-reimann commented 1 year ago

I'd assume that you also need to set the commit_user_email.

adamlui commented 1 year ago

@lars-reimann do you use single, double or no quotes for the value?

lars-reimann commented 1 year ago

It shouldn't matter in this case, test@example.org, 'test@example.org' and "test@example.org" are all the same YAML string. But the rules for strings are rather complicated, so use quotes if you wanna be on the safe side.

adamlui commented 1 year ago

@lars-reimann it worked!!

image

Do you know how I can assign it an icon so visually it looks even more like 2 entities were involved in the commit?

stefanzweifel commented 1 year ago

@adamlui The icon is the avatar of the GitHub user associated with the commit_user_email. So if you want to see a different icon, you would need to create a new GitHub account for the email. Maybe you could also register the email at https://en.gravatar.com and set the profile picture there. Maybe GitHub will pick that up. 🤔

That's also why the commit_user_email-value defaults to the email of the "Actions" GitHub account. To showcase that the commit has been made by 2 entities.

And thanks @lars-reimann for the help here. I didn't make the connection that commit_user_email also has to be updated.

adamlui commented 1 year ago

@lars-reimann @stefanzweifel creating a GitHub acct works beautifully! (the potential en.gravatar.com method awkwardly requires creating a WordPress acct)

image