-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
46 lines (41 loc) · 1.7 KB
/
action.yml
File metadata and controls
46 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
name: "git-config-from-token"
author: "Marco Ieni"
description: "Configure the git user corresponding to the `GITHUB_TOKEN` environment variable."
branding:
icon: "zap"
color: "yellow"
outputs:
name:
description: "Git author name"
value: ${{ steps.git-author.outputs.name }}
email:
description: "Git author email"
value: ${{ steps.git-author.outputs.email }}
runs:
using: "composite"
steps:
- id: git-author
name: Determine Git user info from GitHub token
shell: bash
run: |
if [ -z "${GITHUB_TOKEN+x}" ]; then
echo "Error: environment variable GITHUB_TOKEN is undefined"
exit 1
fi
if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: environment variable GITHUB_TOKEN is empty"
exit 1
fi
# The environment variable GITHUB_TOKEN is read by the `gh` cli
VIEWER_JSON=$(gh api graphql -f query='query { viewer { name login databaseId }}' --jq '.data.viewer')
VIEWER_NAME=$(jq --raw-output '.name | values' <<< "${VIEWER_JSON}")
VIEWER_LOGIN=$(jq --raw-output '.login' <<< "${VIEWER_JSON}")
VIEWER_DATABASE_ID=$(jq --raw-output '.databaseId' <<< "${VIEWER_JSON}")
# Set the variable USER_NAME to the value of VIEWER_NAME if VIEWER_NAME is set and not null.
# Otherwise, set USER_NAME to the value of VIEWER_LOGIN.
USER_NAME="${VIEWER_NAME:-${VIEWER_LOGIN}}"
USER_EMAIL="${VIEWER_DATABASE_ID}+${VIEWER_LOGIN}@users.noreply.github.com"
git config --global user.name "${USER_NAME}"
git config --global user.email "${USER_EMAIL}"
echo "name=${USER_NAME}" >> "${GITHUB_OUTPUT}"
echo "email=${USER_EMAIL}" >> "${GITHUB_OUTPUT}"