Skip to content

Latest commit

 

History

History
68 lines (52 loc) · 2.62 KB

File metadata and controls

68 lines (52 loc) · 2.62 KB

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: no checkout, no git config, the result comes back as step outputs.

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

    - 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.

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.