From 0fc0cf472314a711adbefdbf2ca5bc1b79f59e42 Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Mon, 21 Aug 2023 12:05:34 -0700 Subject: [PATCH] feat: Allow overriding actor (#126) Co-authored-by: Conrad --- README.md | 1 + action.yml | 5 +++++ entrypoint.sh | 13 +++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0df6c6f..f1f0455 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/action.yml b/action.yml index da1e664..de7f649 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/entrypoint.sh b/entrypoint.sh index c7e4588..aece03b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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