Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git config seems to be empty - Please tell me who you are. #2244

Closed
chris-kt opened this issue Aug 16, 2023 · 4 comments
Closed

Git config seems to be empty - Please tell me who you are. #2244

chris-kt opened this issue Aug 16, 2023 · 4 comments

Comments

@chris-kt
Copy link

Git config seems to be empty - Please tell me who you are.

Output

Run peter-evans/create-pull-request@v5
/usr/local/bin/docker exec  20ee3b0a8a9cfe8d1a2e5b8cdc52a19f568407c1f42b583c6978a164b071d5b2 sh -c "cat /etc/*release | grep ^ID"
Prepare git configuration
Determining the base and head repositories
Pull request branch target repository set to krogertechnology/mx-global-message-publisher
Configuring credential for HTTPS authentication
Checking the base repository state
Pull request branch to create or update set to 'feature/update-dependencies'
Configuring the committer and author
Create or update the pull request branch
  /usr/bin/git symbolic-ref HEAD --short
  develop
  Working base is branch 'develop'
  /usr/bin/git checkout --progress -B dc6686d8-5f07-4995-bd1a-0fcc55efdebb HEAD --
  Switched to a new branch 'dc6686d8-5f07-4995-bd1a-0fcc[55](https://github.com/krogertechnology/mx-global-message-publisher/actions/runs/5883237162/job/15955480517#step:8:61)efdebb'
  /usr/bin/git status --porcelain -unormal --
  ?? result
  Uncommitted changes found. Adding a commit.
  /usr/bin/git add -A
  /usr/bin/git -c author.name=chris-kt -c [email protected] -c committer.name=GitHub -c [email protected] commit -m Update dependencies
  
  *** Please tell me who you are.
  
  Run
  
    git config --global user.email "[email protected]"
    git config --global user.name "Your Name"
  
  to set your account's default identity.
  Omit --global to set the identity only in this repository.
  
  fatal: unable to auto-detect email address (got 'root@20ee3b0a8a9c.(none)')
  Error: Unexpected error: 
  *** Please tell me who you are.
  
  Run
  
    git config --global user.email "[email protected]"
    git config --global user.name "Your Name"
  
  to set your account's default identity.
  Omit --global to set the identity only in this repository.
  
  fatal: unable to auto-detect email address (got 'root@20ee3b0a8a9c.(none)')
  
Restore git configuration

ISSUE

Issue is outlined above - seems like when the PR is ready to be created, Git doesn't know who the actor is.

Workflow file

name: Update Dependencies
on:
  # pull_request:
  schedule:
    # https://crontab.guru/#0-59_*_*_*_* (yes, I know it's every minute)
    - cron:  '0-59 * * * *' 
    
env:
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
  JFROG_USERNAME: ${{ secrets.ARTIFACTORY_SAAS_USERNAME }}
  JFROG_PASSWORD: ${{ secrets.ARTIFACTORY_SAAS_TOKEN }}
jobs:
  update-dep:
    runs-on: [ self-hosted, on-prem, kubernetes ]
    container:
      image: MY_CUSTOM_IMAGE
      credentials:
        username: ${{ env.JFROG_USERNAME }}
        password: ${{ env.JFROG_PASSWORD }}
    steps:
      - uses: actions/checkout@v3
      - name: provision the runner
        run: | 
          apt-get update
          apt-get install jq
      - name: Check write access to repo
        run: |
          token_login=$(curl -H "Authorization: Bearer ${token}" https://api.github.com/user | jq -r '.login')
          echo token login is ${token_login}
          echo $(curl  -H "Authorization: Bearer ${token}" https://api.github.com/repos/${repo}/collaborators/${token_login}/permission) > result
          cat result | jq  '.permission == "admin" // .permission == "write"' > /dev/null || ( echo "Token does not have write access to ${repo}" >> ${GITHUB_STEP_SUMMARY}; exit 1)
          curl -sS -f -I -H "Authorization: Bearer ${token}" https://api.github.com | grep 'x-oauth-scopes:' | grep 'repo' > /dev/null && exit 0 || echo "Token does not have repo scope on ${repo}" >> ${GITHUB_STEP_SUMMARY}
        env:
          repo: ${{ github.repository }}
          token: ${{ secrets.PAT }}

      - name: NPM Audit fix
        run: |
          npm audit fix
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v5
        with:
          token: ${{ secrets.PAT }}
          base: ${{ github.head_ref }}
          branch: feature/update-dependencies
          commit-message: Update dependencies
          labels: auto-pr, dependency-audit
          title: Update dependencies  
          body: |
            - Dependency updates

            Auto-generated by [create-pull-request][1]

            [1]: https://github.com/peter-evans/create-pull-request

Steps to reproduce

May be difficult to reproduce as I'm behind a corporate proxy using self-hosted runners and custom images.

If this issue is describing a possible bug please provide (or link to) your GitHub Actions workflow.
image

Repository owner deleted a comment from monjie110 Sep 4, 2023
Repository owner deleted a comment from monjie110 Sep 4, 2023
@peter-evans
Copy link
Owner

Hi @chris-kt

Apologies for the slow response.

I guess git needs to have global config set before some commands will work.

You could try adding these lines in a workflow step before the action runs. I don't think it matters much what email or name you use because the action should override them anyway.

    git config --global user.email "[email protected]"
    git config --global user.name "Your Name"

@chris-kt
Copy link
Author

chris-kt commented Sep 5, 2023

Roger that, I'll give it a go. Thanks for the reply!

@chris-kt
Copy link
Author

chris-kt commented Sep 6, 2023

Hi @chris-kt

Apologies for the slow response.

I guess git needs to have global config set before some commands will work.

You could try adding these lines in a workflow step before the action runs. I don't think it matters much what email or name you use because the action should override them anyway.

    git config --global user.email "[email protected]"
    git config --global user.name "Your Name"

This ended up working, however, the user config does NOT get overridden by the action. So, the PR is opened with my username and email set in this step. I guess that's okay, but it's not what I would expect.

Lastly, I get an unexpected result of the PR containing a file names results that is an object of the results from the action itself.

The meaningful portion of my workflow file is as follows:

      - name: NPM Audit fix
         run: npm audit fix

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v5
        with:
          token: ${{ secrets.PAT }}
          base: ${{ github.head_ref }}
          branch: feature/update-dependencies
          commit-message: Updates dependencies
          labels: auto-pr, dependency-audit
          title: NOJIRA | github | NPM Audit Update
          body: |
            # Dependency updates via `npm audit fix`
            This has been auto-generated.

The body/title of the PR are correct, but when you look at the files inside of the pull request, we see a single file named 'results' with the following:

{ "permission": "admin", "user": { "login": "chris-kt", "id": 77807819, "node_id": "MDQ6VXNlcjc3ODA3ODE5", "avatar_url": "https://avatars.githubusercontent.com/u/77807819?v=4", "gravatar_id": "", "url": "https://api.github.com/users/chris-kt", "html_url": "https://github.com/chris-kt", "followers_url": "https://api.github.com/users/chris-kt/followers", "following_url": "https://api.github.com/users/chris-kt/following{/other_user}", "gists_url": "https://api.github.com/users/chris-kt/gists{/gist_id}", "starred_url": "https://api.github.com/users/chris-kt/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/chris-kt/subscriptions", "organizations_url": "https://api.github.com/users/chris-kt/orgs", "repos_url": "https://api.github.com/users/chris-kt/repos", "events_url": "https://api.github.com/users/chris-kt/events{/privacy}", "received_events_url": "https://api.github.com/users/chris-kt/received_events", "type": "User", "site_admin": false, "permissions": { "admin": true, "maintain": true, "push": true, "triage": true, "pull": true }, "role_name": "admin" }, "role_name": "admin" }

I feel like I must be doing something wrong here, but am unsure what it would be.

@peter-evans
Copy link
Owner

This ended up working, however, the user config does NOT get overridden by the action. So, the PR is opened with my username and email set in this step. I guess that's okay, but it's not what I would expect.

Please check the inputs here. You can override the defaults for committer and author. As for the PR itself, that will always be opened in the username of the account associated with the token you use. You can create a machine account with a PAT if you don't want PRs created by an actual user.

Lastly, I get an unexpected result of the PR containing a file names results that is an object of the results from the action itself.

Fairly sure that result file is being generated by the workflow step Check write access to repo. Make sure that doesn't create files, otherwise they will end up in the diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants