Skip to content

voidmason/git-identity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git-identity

Resolve the git committer identity - name and email - from the token a workflow already has, instead of hardcoding a committer into every action that commits. Pure resolution by default: no checkout, no git config, the result comes back as step outputs. With setup: true the action also applies the pair with git config in the checked-out repo.

What it does

Picks the committer in this order, first match wins:

  1. explicit name/email inputs, taken as is - no lookup;
  2. the run's own workflow token (GITHUB_TOKEN) resolves to github-actions[bot], the standard identity for commits made with it;
  3. a PAT resolves to its owner via GET /user: login as the name, <id>+<login>@users.noreply.github.com as the email - the noreply address GitHub links back to the profile;
  4. default_name/default_email inputs, when the token resolves to no one (an installation token of some GitHub App, for example);
  5. otherwise the step fails.

Both pairs are all-or-nothing: passing one half fails loud. Values with control characters are rejected - a newline in an input could forge extra step outputs.

The committer email is what decides whether GitHub renders the commit author as a clickable profile: addresses of real accounts (a user's noreply address, the Actions bot) are linked, arbitrary strings are not.

Usage

    - uses: voidmason/git-identity@v1
      with:
        token: ${{ secrets.RELEASE_TOKEN }}
        setup: true

Without setup the action only resolves, and the pair goes wherever the workflow needs it - git config by hand, another action's inputs, an API call:

    - id: committer
      uses: voidmason/git-identity@v1
      with:
        token: ${{ secrets.RELEASE_TOKEN }}

    - env:
        NAME: ${{ steps.committer.outputs.name }}
        EMAIL: ${{ steps.committer.outputs.email }}
      run: |
        git config user.name "$NAME"
        git config user.email "$EMAIL"

Inputs

Input Required Description
token yes Token to resolve; a PAT resolves to its owner.
name no Explicit committer name; skips the lookup.
email no Explicit committer email; goes with name.
default_name no Fallback name for a token that resolves to no one.
default_email no Fallback email; goes with default_name.
setup no Also run git config with the resolved pair.

Outputs

Output Description
name Resolved committer name.
email Resolved committer email (id+login noreply for a PAT).

Requirements

The runner needs gh; ubuntu-latest ships it. The /user lookup is a single API call and happens only when no explicit pair is given and the token is not the workflow token. setup: true writes the pair into the local repo config, so the step must run after checkout.

About

Resolve the git committer identity - name and email - from the token

Topics

Resources

Stars

Watchers

Forks

Releases

Contributors

Languages