From 762be8468532113b0ea26fbe7ebf816085fe2579 Mon Sep 17 00:00:00 2001 From: Lance Hasson Date: Tue, 21 Sep 2021 09:17:32 -0700 Subject: [PATCH 01/11] use 'main' instead of 'master' for examples --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4d0fb81..847d722 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). ### Example Config -#### Example 1 (run on push in master) +#### Example 1 (run on push in main) ```yaml name: Continuous Integration @@ -41,7 +41,7 @@ on: pull_request: push: branches: - - master + - main jobs: prettier: @@ -67,7 +67,7 @@ name: Continuous Integration on: pull_request: - branches: [master] + branches: [main] jobs: prettier: @@ -96,7 +96,7 @@ name: Continuous Integration on: pull_request: - branches: [master] + branches: [main] jobs: prettier: @@ -126,7 +126,7 @@ name: Continuous Integration on: pull_request: - branches: [master] + branches: [main] jobs: prettier: From a6d8de1638eada26996e42f0e5451d7b3d7be59b Mon Sep 17 00:00:00 2001 From: Andy Armstrong Date: Tue, 19 Oct 2021 13:42:28 +0100 Subject: [PATCH 02/11] Don't delete package-lock.json --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index d3a358b..a51b289 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -74,7 +74,7 @@ else fi if [ -f 'package-lock.json' ]; then - git reset --hard package-lock.json || rm package-lock.json + git checkout -- package-lock.json else echo "No package-lock.json file." fi From 23135339e395050fe1c9bf742be04993a210d660 Mon Sep 17 00:00:00 2001 From: insyri <60794909+insyri@users.noreply.github.com> Date: Fri, 22 Oct 2021 08:49:41 -0400 Subject: [PATCH 03/11] added `commit-description` as option in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4d0fb81..dabf0c1 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | push_options | :x: | - | Custom git push options | | same_commit | :x: | `false` | Update the current commit instead of creating a new one, created by [Joren Broekema](https://github.com/jorenbroekema), this command works only with the checkout action set to fetch depth '0' (see example 2) | | commit_message | :x: | `"Prettified Code!"` | Custom git commit message, will be ignored if used with `same_commit` | +| commit_description | :x: | - | Custom git exteneded commit message, will be ignored if used with `same_commit` | | file_pattern | :x: | `*` | Custom git add file pattern, can't be used with only_changed! | | prettier_plugins | :x: | - | Install Prettier plugins, i.e. `@prettier/plugin-php @prettier/plugin-other` | | 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)| From 6296a68dfd7364abd48265b48d33c48801bc7842 Mon Sep 17 00:00:00 2001 From: insyri <60794909+insyri@users.noreply.github.com> Date: Fri, 22 Oct 2021 08:52:00 -0400 Subject: [PATCH 04/11] added `commit-description` as option to action.yml --- action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/action.yml b/action.yml index 3217353..691269a 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,10 @@ inputs: description: Commit message, will be ignored if used with same_commit required: false default: "Prettified Code!" + commit_description: + description: Extended commit message, will be ignored if used with same_commit + required: false + default: "" same_commit: description: Update the current commit instead of creating a new one required: false @@ -58,6 +62,7 @@ runs: ${{ github.action_path }}/entrypoint.sh env: INPUT_COMMIT_MESSAGE: ${{ inputs.commit_message }} + INPUT_COMMIT_DESCRIPTION: ${{ inputs.commit_description }} INPUT_SAME_COMMIT: ${{ inputs.same_commit }} INPUT_COMMIT_OPTIONS: ${{ inputs.commit_options }} INPUT_FILE_PATTERN: ${{ inputs.file_pattern }} From 39357d386aec8ee2998ad788926e6a96172dc24e Mon Sep 17 00:00:00 2001 From: insyri <60794909+insyri@users.noreply.github.com> Date: Fri, 22 Oct 2021 09:03:21 -0400 Subject: [PATCH 05/11] added `$INPUT_COMMIT_DESCRIPTION` to entrypoint.sh im unfamiliar with shell so this is what i did with some research, the inline if statement is just a personal design/formatting choice. --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index d3a358b..b8216b4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -109,7 +109,7 @@ if _git_changed; then git commit --amend --no-edit git push origin -f else - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} || echo "No files added to commit" + git commit -m "$INPUT_COMMIT_MESSAGE" if [ "$INPUT_COMMIT_DESCRIPTION" != "" ]; then echo '-m "$INPUT_COMMIT_DESCRIPTION"' fi --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} || echo "No files added to commit" git push origin ${INPUT_PUSH_OPTIONS:-} fi echo "Changes pushed successfully." From 902197aeb222fe6f283a10b8e6f6a0a1349a10f8 Mon Sep 17 00:00:00 2001 From: insyri <60794909+insyri@users.noreply.github.com> Date: Fri, 22 Oct 2021 09:04:15 -0400 Subject: [PATCH 06/11] typo fix in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dabf0c1..78239a7 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | push_options | :x: | - | Custom git push options | | same_commit | :x: | `false` | Update the current commit instead of creating a new one, created by [Joren Broekema](https://github.com/jorenbroekema), this command works only with the checkout action set to fetch depth '0' (see example 2) | | commit_message | :x: | `"Prettified Code!"` | Custom git commit message, will be ignored if used with `same_commit` | -| commit_description | :x: | - | Custom git exteneded commit message, will be ignored if used with `same_commit` | +| commit_description | :x: | - | Custom git extended commit message, will be ignored if used with `same_commit` | | file_pattern | :x: | `*` | Custom git add file pattern, can't be used with only_changed! | | prettier_plugins | :x: | - | Install Prettier plugins, i.e. `@prettier/plugin-php @prettier/plugin-other` | | 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)| From b90e27731a3b704a89ede9a5fe78a91219f27cd5 Mon Sep 17 00:00:00 2001 From: sksat Date: Wed, 24 Nov 2021 00:30:10 +0900 Subject: [PATCH 07/11] fix: handle space in changed file name --- entrypoint.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index d3a358b..ae57463 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -93,10 +93,13 @@ if _git_changed; then if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files + OLDIFS="$IFS" + IFS=$'\n' for file in $(git diff --name-only --diff-filter=d HEAD^..HEAD) do - git add $file + git add "$file" done + IFS="$OLDIFS" else # Add changes to git git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}" From 8efb5a885e55ab5d3c36d834e87bc0fa86766b86 Mon Sep 17 00:00:00 2001 From: Conrad Date: Tue, 30 Nov 2021 17:18:31 +0100 Subject: [PATCH 08/11] Added working_directory parameter --- README.md | 1 + action.yml | 8 ++++++-- entrypoint.sh | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 78239a7..b1774de 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | - | :-: | :-: | - | | dry | :x: | `false` | Runs the action in dry mode. Files wont get changed and the action fails if there are unprettified files. Recommended to use with prettier_options --check | | prettier_version | :x: | `false` | Specific prettier version (by default use latest) | +| working_directory | :x: | `false` | Specify a directory to cd into before installing prettier and running it | | prettier_options | :x: | `"--write **/*.js"` | Prettier options (by default it applies to the whole repository) | | commit_options | :x: | - | Custom git commit options | | push_options | :x: | - | Custom git push options | diff --git a/action.yml b/action.yml index 691269a..c709804 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,10 @@ inputs: description: Specific version of prettier (by default just use the latest version) required: false default: false + working_directory: + description: Specify a directory to cd into before installing prettier and running it + required: false + default: false only_changed: description: Only prettify files changed in the last commit, can't be used with file_pattern! required: false @@ -45,13 +49,12 @@ inputs: prettier_plugins: description: Install Prettier plugins, i.e. `@prettier/plugin-php @prettier/plugin-other` required: false - default: '' + default: "" github_token: description: GitHub Token or PAT token used to authenticate against a repository required: false default: ${{ github.token }} - runs: using: "composite" steps: @@ -71,6 +74,7 @@ runs: INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }} INPUT_ONLY_CHANGED: ${{ inputs.only_changed }} INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }} + INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }} INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} branding: diff --git a/entrypoint.sh b/entrypoint.sh index b0b08ec..88f2df6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,6 +37,14 @@ cd "$GITHUB_ACTION_PATH" echo "Installing prettier..." +case $INPUT_WORKING_DIRECTORY in + false) + ;; + *) + cd $INPUT_WORKING_DIRECTORY + ;; +esac + case $INPUT_PRETTIER_VERSION in false) npm install --silent prettier From b072432b6b4394a932e10bb40449cc7c81944993 Mon Sep 17 00:00:00 2001 From: Conrad Date: Tue, 30 Nov 2021 17:22:11 +0100 Subject: [PATCH 09/11] Added slight explanation to the readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ad66466..b01e7c2 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,8 @@ A GitHub action for styling files with [prettier](https://prettier.io). ### Example Config -#### Example 1 (run on push in main) +> Hint: if you still use the old naming convention or generally a different branch name, please replace the `main` in the following configurations. +#### Example 1 (run on push in branch main) ```yaml name: Continuous Integration From fabe625ef24cc1766f34410bebac4baf8b2651d4 Mon Sep 17 00:00:00 2001 From: Conrad Date: Tue, 30 Nov 2021 17:52:15 +0100 Subject: [PATCH 10/11] Bumped versions --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b01e7c2..66283dd 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ jobs: ref: ${{ github.head_ref }} - name: Prettify code - uses: creyD/prettier_action@v4.0 + uses: creyD/prettier_action@v4.1 with: # This part is also where you can pass other options, for example: prettier_options: --write **/*.{js,md} @@ -86,7 +86,7 @@ jobs: fetch-depth: 0 - name: Prettify code - uses: creyD/prettier_action@v4.0 + uses: creyD/prettier_action@v4.1 with: # This part is also where you can pass other options, for example: prettier_options: --write **/*.{js,md} @@ -115,7 +115,7 @@ jobs: persist-credentials: false - name: Prettify code - uses: creyD/prettier_action@v4.0 + uses: creyD/prettier_action@v4.1 with: prettier_options: --write **/*.{js,md} only_changed: True @@ -145,7 +145,7 @@ jobs: persist-credentials: false - name: Prettify code - uses: creyD/prettier_action@v4.0 + uses: creyD/prettier_action@v4.1 with: dry: True github_token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} From 9accc7b9f5faa21f1873795ea9894c70eb7c4f8e Mon Sep 17 00:00:00 2001 From: Conrad Date: Tue, 30 Nov 2021 18:03:30 +0100 Subject: [PATCH 11/11] Added further context for the working_directory --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 66283dd..707adc0 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | - | :-: | :-: | - | | dry | :x: | `false` | Runs the action in dry mode. Files wont get changed and the action fails if there are unprettified files. Recommended to use with prettier_options --check | | prettier_version | :x: | `false` | Specific prettier version (by default use latest) | -| working_directory | :x: | `false` | Specify a directory to cd into before installing prettier and running it | +| working_directory | :x: | `false` | Specify a directory to cd into before installing prettier and running it, use relative file path to the repository root for example `app/` | | prettier_options | :x: | `"--write **/*.js"` | Prettier options (by default it applies to the whole repository) | | commit_options | :x: | - | Custom git commit options | | push_options | :x: | - | Custom git push options |