feat: Allow overriding actor (#126)

Co-authored-by: Conrad <grosserconrad@gmail.com>
This commit is contained in:
Derek Brown
2023-08-21 12:05:34 -07:00
committed by GitHub
parent 5b5cb513f1
commit 0fc0cf4723
3 changed files with 17 additions and 2 deletions

View File

@@ -30,6 +30,7 @@ A GitHub action for styling files with [prettier](https://prettier.io).
| clean_node_folder | :x: | `true` | Delete the node_modules folder before committing |
| only_changed | :x: | `false` | Only prettify changed files, can't be used with file_pattern! This command works only with the checkout action set to fetch depth '0' (see example 2)|
| github_token | :x: | `${{ github.token }}` | The default [GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret) or a [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token)
| git_identity | :x: | `actions` | Set to `author` to use author's user as committer. This allows triggering [further workflow runs](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs)
> Note: using the same_commit option may lead to problems if other actions are relying on the commit being the same before and after the prettier action has ran. Keep this in mind.

View File

@@ -62,6 +62,10 @@ inputs:
description: Remove the node_modules folder before committing changes
required: false
default: true
git_identity:
description: Which identity is used for git name/email
required: false
default: "actions"
runs:
using: "composite"
@@ -87,6 +91,7 @@ runs:
INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }}
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
INPUT_CLEAN_NODE_FOLDER: ${{ inputs.clean_node_folder }}
INPUT_GIT_IDENTITY: ${{ inputs.git_identity }}
branding:
icon: "award"

View File

@@ -17,8 +17,17 @@ _git_setup ( ) {
EOF
chmod 600 $HOME/.netrc
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Action"
# If GIT_IDENTITY="actor"
if [ "$INPUT_GIT_IDENTITY" = "author" ]; then
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "$GITHUB_ACTOR@@users.noreply.github.com"
elif [ "$INPUT_GIT_IDENTITY" = "actions" ]; then
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Action"
else
echo "GIT_IDENTITY must be either 'actor' or 'actions'";
exit 1;
fi;
}
# Checks if any files are changed