From e338a630e679fac7089c57b02995c9e8942a19e6 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Fri, 19 Feb 2021 00:49:16 -0500 Subject: [PATCH 01/43] Tag entrypoint as a bash script This script uses bashisms --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 023e697..df967f4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set # x would be for showing the commands before they are executed set -eu From 7326fa4da43356c2b1d4d4bc0714fcee6652e407 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Fri, 19 Feb 2021 00:49:40 -0500 Subject: [PATCH 02/43] Switch to composite --- action.yml | 18 ++++++++++++++++-- entrypoint.sh | 15 ++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index a0d155c..7fa1af2 100644 --- a/action.yml +++ b/action.yml @@ -41,8 +41,22 @@ inputs: default: '' runs: - using: 'docker' - image: 'Dockerfile' + using: 'composite' + steps: + - name: prettier + shell: bash + run: >- + PATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH + INPUT_COMMIT_MESSAGE="${{ inputs.commit_message }}" + INPUT_COMMIT_OPTIONS="${{ inputs.commit_options }}" + INPUT_DRY="${{ inputs.dry }}" + INPUT_FILE_PATTERN="${{ inputs.file_pattern }}" + INPUT_ONLY_CHANGED="${{ inputs.only_changed }}" + INPUT_PRETTIER_OPTIONS="${{ inputs.prettier_options }}" + INPUT_PRETTIER_PLUGINS="${{ inputs.prettier_plugins }}" + INPUT_PRETTIER_VERSION="${{ inputs.prettier_version }}" + INPUT_SAME_COMMIT="${{ inputs.same_commit }}" + $GITHUB_ACTION_PATH/entrypoint.sh branding: icon: 'award' diff --git a/entrypoint.sh b/entrypoint.sh index df967f4..9a3812a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,14 +25,22 @@ _git_changed() { [[ -n "$(git status -s)" ]] } +( +if [ -n "$GITHUB_ACTION_PATH" ]; then + cd $GITHUB_ACTION_PATH + maybe_global='' +else + maybe_global=--global +fi + # PROGRAM echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) - npm install --silent --global prettier + npm install --silent $maybe_global prettier ;; *) - npm install --silent --global prettier@$INPUT_PRETTIER_VERSION + npm install --silent $maybe_global prettier@$INPUT_PRETTIER_VERSION ;; esac @@ -46,8 +54,9 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then exit 1 fi done - npm install --silent --global $INPUT_PRETTIER_PLUGINS + npm install --silent $maybe_global $INPUT_PRETTIER_PLUGINS fi +) echo "Prettifing files..." echo "Files:" From 8a68c5b4d367a45b57eef4580cff1f058fefcf07 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 17:45:52 +0100 Subject: [PATCH 03/43] Experimenting with a simpler form of composite actions --- action.yml | 29 +++++++++-------------------- entrypoint.sh | 4 ++-- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/action.yml b/action.yml index 7fa1af2..988fdf6 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: commit_message: description: Commit message, will be ignored if used with same_commit required: false - default: 'Prettified Code!' + default: "Prettified Code!" same_commit: description: Update the current commit instead of creating a new one required: false @@ -18,11 +18,11 @@ inputs: file_pattern: description: File pattern used for `git add`, can't be used with only_changed! required: false - default: '*' + default: "*" prettier_options: description: Options for the `prettier` command required: false - default: '--write **/*.js' + default: "--write **/*.js" dry: description: Running the script in dry mode just shows whether there are files that should be prettified or not required: false @@ -38,26 +38,15 @@ inputs: prettier_plugins: description: Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin` required: false - default: '' + default: "" runs: - using: 'composite' + using: "composite" steps: - - name: prettier + - name: Prettify code! shell: bash - run: >- - PATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH - INPUT_COMMIT_MESSAGE="${{ inputs.commit_message }}" - INPUT_COMMIT_OPTIONS="${{ inputs.commit_options }}" - INPUT_DRY="${{ inputs.dry }}" - INPUT_FILE_PATTERN="${{ inputs.file_pattern }}" - INPUT_ONLY_CHANGED="${{ inputs.only_changed }}" - INPUT_PRETTIER_OPTIONS="${{ inputs.prettier_options }}" - INPUT_PRETTIER_PLUGINS="${{ inputs.prettier_plugins }}" - INPUT_PRETTIER_VERSION="${{ inputs.prettier_version }}" - INPUT_SAME_COMMIT="${{ inputs.same_commit }}" - $GITHUB_ACTION_PATH/entrypoint.sh + run: ${{ github.action_path }}/entrypoint.sh branding: - icon: 'award' - color: 'green' + icon: "award" + color: "green" diff --git a/entrypoint.sh b/entrypoint.sh index 9a3812a..afc91d6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,10 +37,10 @@ fi echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) - npm install --silent $maybe_global prettier + npm install --silent -g prettier ;; *) - npm install --silent $maybe_global prettier@$INPUT_PRETTIER_VERSION + npm install --silent -g prettier@$INPUT_PRETTIER_VERSION ;; esac From 3aa6d7608dfc60b75f92b937f82af1650f29ca3a Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 17:54:00 +0100 Subject: [PATCH 04/43] Added testing variable --- entrypoint.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index afc91d6..1b6ef8c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,12 +26,8 @@ _git_changed() { } ( -if [ -n "$GITHUB_ACTION_PATH" ]; then - cd $GITHUB_ACTION_PATH - maybe_global='' -else - maybe_global=--global -fi + +echo ${{ inputs.prettier_options }} # PROGRAM echo "Installing prettier..." From 5f9fa33c3d44a904b690f93f53648263779c1997 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 17:58:30 +0100 Subject: [PATCH 05/43] Fixed variable problem --- action.yml | 10 ++++++++++ entrypoint.sh | 2 -- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 988fdf6..b23b101 100644 --- a/action.yml +++ b/action.yml @@ -46,6 +46,16 @@ runs: - name: Prettify code! shell: bash run: ${{ github.action_path }}/entrypoint.sh + env: + INPUT_COMMIT_MESSAGE: ${{ inputs.commit_message }} + INPUT_SAME_COMMIT: ${{ inputs.same_commit }} + INPUT_COMMIT_OPTIONS: ${{ inputs.commit_options }} + INPUT_FILE_PATTERN: ${{ inputs.file_pattern }} + INPUT_PRETTIER_OPTIONS: ${{ inputs.prettier_options }} + INPUT_DRY: ${{ inputs.dry }} + INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }} + INPUT_ONLY_CHANGED: ${{ inputs.only_changed }} + INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }} branding: icon: "award" diff --git a/entrypoint.sh b/entrypoint.sh index 1b6ef8c..f5dcad8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,8 +27,6 @@ _git_changed() { ( -echo ${{ inputs.prettier_options }} - # PROGRAM echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in From b5409d48a9aed968ed3fa12eeb5bd80fffbc328c Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:02:12 +0100 Subject: [PATCH 06/43] Removed global option for testing --- entrypoint.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f5dcad8..a463036 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -31,10 +31,10 @@ _git_changed() { echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) - npm install --silent -g prettier + npm install --silent prettier ;; *) - npm install --silent -g prettier@$INPUT_PRETTIER_VERSION + npm install --silent prettier@$INPUT_PRETTIER_VERSION ;; esac @@ -48,7 +48,7 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then exit 1 fi done - npm install --silent $maybe_global $INPUT_PRETTIER_PLUGINS + npm install --silent $INPUT_PRETTIER_PLUGINS fi ) From 5c365ab3fa00072450bddc018c60fc181d133e6d Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:10:42 +0100 Subject: [PATCH 07/43] Another bugfix attempt trying to generate the global flag only if needed --- Dockerfile | 4 ---- action.yml | 1 + entrypoint.sh | 14 +++++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index cfd542a..0000000 --- a/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM node:lts-alpine3.9 -RUN apk update && apk add --no-cache bash git openssh -COPY entrypoint.sh /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yml b/action.yml index b23b101..3a70533 100644 --- a/action.yml +++ b/action.yml @@ -56,6 +56,7 @@ runs: INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }} INPUT_ONLY_CHANGED: ${{ inputs.only_changed }} INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }} + PATH: $(cd $GITHUB_ACTION_PATH; npm bin):$PATH branding: icon: "award" diff --git a/entrypoint.sh b/entrypoint.sh index a463036..a5b1b55 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash # e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set # x would be for showing the commands before they are executed -set -eu +set -eux # FUNCTIONS # Function for setting up git env in the docker container (copied from https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh) @@ -25,16 +25,20 @@ _git_changed() { [[ -n "$(git status -s)" ]] } -( +if [ -n "$GITHUB_ACTION_PATH" ]; then + INPUT_IS_GLOBAL='' +else + INPUT_IS_GLOBAL=--global +fi # PROGRAM echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) - npm install --silent prettier + npm install --silent $INPUT_IS_GLOBAL prettier ;; *) - npm install --silent prettier@$INPUT_PRETTIER_VERSION + npm install --silent $INPUT_IS_GLOBAL prettier@$INPUT_PRETTIER_VERSION ;; esac @@ -48,7 +52,7 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then exit 1 fi done - npm install --silent $INPUT_PRETTIER_PLUGINS + npm install --silent $INPUT_IS_GLOBAL $INPUT_PRETTIER_PLUGINS fi ) From 4d25f0bd7c27dc7997a445df40a4fcb24178ad4e Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:13:22 +0100 Subject: [PATCH 08/43] Moving the path to the run part of the yml --- action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 3a70533..ebe05a8 100644 --- a/action.yml +++ b/action.yml @@ -45,7 +45,9 @@ runs: steps: - name: Prettify code! shell: bash - run: ${{ github.action_path }}/entrypoint.sh + run: >- + PATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH + ${{ github.action_path }}/entrypoint.sh env: INPUT_COMMIT_MESSAGE: ${{ inputs.commit_message }} INPUT_SAME_COMMIT: ${{ inputs.same_commit }} @@ -56,7 +58,6 @@ runs: INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }} INPUT_ONLY_CHANGED: ${{ inputs.only_changed }} INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }} - PATH: $(cd $GITHUB_ACTION_PATH; npm bin):$PATH branding: icon: "award" From 857bc257e2c663554e254924e3d851b80edbd84b Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:15:37 +0100 Subject: [PATCH 09/43] Added missing bracket --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index a5b1b55..593a26b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,6 +25,7 @@ _git_changed() { [[ -n "$(git status -s)" ]] } +( if [ -n "$GITHUB_ACTION_PATH" ]; then INPUT_IS_GLOBAL='' else From 35d0d93afdf524b00ae09d73d99385e8a42228b2 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:19:17 +0100 Subject: [PATCH 10/43] Removed global parameter --- entrypoint.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 593a26b..fc08fbe 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,20 +26,16 @@ _git_changed() { } ( -if [ -n "$GITHUB_ACTION_PATH" ]; then - INPUT_IS_GLOBAL='' -else - INPUT_IS_GLOBAL=--global -fi +cd "$GITHUB_ACTION_PATH" # PROGRAM echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) - npm install --silent $INPUT_IS_GLOBAL prettier + npm install --silent prettier ;; *) - npm install --silent $INPUT_IS_GLOBAL prettier@$INPUT_PRETTIER_VERSION + npm install --silent prettier@$INPUT_PRETTIER_VERSION ;; esac @@ -53,7 +49,7 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then exit 1 fi done - npm install --silent $INPUT_IS_GLOBAL $INPUT_PRETTIER_PLUGINS + npm install --silent $INPUT_PRETTIER_PLUGINS fi ) From 01e9c566d8a487eed64fb1c27dee4790f880671f Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:31:20 +0100 Subject: [PATCH 11/43] Trying to exclude the useless package files --- entrypoint.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index fc08fbe..b10056d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash # e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set # x would be for showing the commands before they are executed -set -eux +set -eu # FUNCTIONS # Function for setting up git env in the docker container (copied from https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh) @@ -26,9 +26,11 @@ _git_changed() { } ( -cd "$GITHUB_ACTION_PATH" # PROGRAM +# Changing to the directory +cd "$GITHUB_ACTION_PATH" + echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) @@ -66,6 +68,13 @@ if _git_changed; then # Calling method to configure the git environemnt _git_setup + # Ignore node modules and other action created files + "/node_modules/ + package-lock.json + package.json + " >> .git/info/exclude + git update-index --assume-unchanged */node_modules/* package.json package-lock.json + if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files for file in $(git diff --name-only --diff-filter=d HEAD^..HEAD) From 3b82dd7e9544c7679a6cdbcc572c3867331dc5aa Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:36:38 +0100 Subject: [PATCH 12/43] Fixed missing command --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index b10056d..4e647d3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -69,7 +69,7 @@ if _git_changed; then _git_setup # Ignore node modules and other action created files - "/node_modules/ + echo "/node_modules/ package-lock.json package.json " >> .git/info/exclude From c5dd36440fbdebc6c7f06f73695788df401b3a72 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:40:27 +0100 Subject: [PATCH 13/43] Updating the ignore mechanism --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4e647d3..8765acb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -69,11 +69,11 @@ if _git_changed; then _git_setup # Ignore node modules and other action created files - echo "/node_modules/ + echo "*/node_modules/* package-lock.json package.json " >> .git/info/exclude - git update-index --assume-unchanged */node_modules/* package.json package-lock.json + git update-index --assume-unchanged node_modules/ package.json package-lock.json if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files From 5564e3ef42cba75236e3f6b5d7946f911d006689 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:41:32 +0100 Subject: [PATCH 14/43] Updating ignore mechanism 2 --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8765acb..0ae80e3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -73,7 +73,7 @@ if _git_changed; then package-lock.json package.json " >> .git/info/exclude - git update-index --assume-unchanged node_modules/ package.json package-lock.json + git update-index --assume-unchanged node_modules/ package-lock.json if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files From 77af3031890381afb940b22ac4f118a8c507b38b Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:44:35 +0100 Subject: [PATCH 15/43] Bugfixing ignore mechanism --- entrypoint.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0ae80e3..ef53904 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -69,11 +69,9 @@ if _git_changed; then _git_setup # Ignore node modules and other action created files - echo "*/node_modules/* - package-lock.json - package.json - " >> .git/info/exclude - git update-index --assume-unchanged node_modules/ package-lock.json + git update-index --skip-worktree package.json + git update-index --skip-worktree node_modules/ + git update-index --skip-worktree package-lock.json if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files From 9acb5d89b9931334fba7886750dcaafe327b4e03 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:47:01 +0100 Subject: [PATCH 16/43] Still debugging ignoring --- entrypoint.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index ef53904..0baf63f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -69,9 +69,10 @@ if _git_changed; then _git_setup # Ignore node modules and other action created files - git update-index --skip-worktree package.json - git update-index --skip-worktree node_modules/ - git update-index --skip-worktree package-lock.json + echo "package_lock.json + node_modules/ + .gitignore + " >> .gitignore if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files From 172c413f01afa0e9e6d7a175ad75acad76043479 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:51:11 +0100 Subject: [PATCH 17/43] Added .gitignore exclusion --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index 0baf63f..bda7d7f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -73,6 +73,7 @@ if _git_changed; then node_modules/ .gitignore " >> .gitignore + git config --global core.excludesfile .gitignore_global if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files From 1a89f28d0fbdf06934d64cf7ad3945ce9c1409b3 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:54:40 +0100 Subject: [PATCH 18/43] Added .gitignore to exclusion - for real --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index bda7d7f..9359c77 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -73,7 +73,7 @@ if _git_changed; then node_modules/ .gitignore " >> .gitignore - git config --global core.excludesfile .gitignore_global + git config --global core.excludesfile .gitignore if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files From f4e4fcde26edbdcb6ebf00b43865070acb78ffc4 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 18:56:55 +0100 Subject: [PATCH 19/43] Added .gitignore to exclusion - for real II --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 9359c77..16a4b42 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -73,7 +73,7 @@ if _git_changed; then node_modules/ .gitignore " >> .gitignore - git config --global core.excludesfile .gitignore + git update-index --skip-worktree .gitignore if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files From c9d8181bcf28179ff4cbb6627fb63c8045027ef0 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 19:04:18 +0100 Subject: [PATCH 20/43] Moved ignore part to before git checks changed --- entrypoint.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 16a4b42..6ed784c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -59,6 +59,12 @@ echo "Prettifing files..." echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" +# Ignore node modules and other action created files +echo "package_lock.json +node_modules/ +" >> .gitignore +git update-index --assume-unchanged .gitignore + # To keep runtime good, just continue if something was changed if _git_changed; then if $INPUT_DRY; then @@ -68,13 +74,6 @@ if _git_changed; then # Calling method to configure the git environemnt _git_setup - # Ignore node modules and other action created files - echo "package_lock.json - node_modules/ - .gitignore - " >> .gitignore - git update-index --skip-worktree .gitignore - if $INPUT_ONLY_CHANGED; then # --diff-filter=d excludes deleted files for file in $(git diff --name-only --diff-filter=d HEAD^..HEAD) From 19d31cb26373ebe7506c96f03e0d073e0e93a8dc Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 19:07:12 +0100 Subject: [PATCH 21/43] Another try at bugfixing the ignore mechanism --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6ed784c..8dc8c5f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -63,7 +63,6 @@ prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_P echo "package_lock.json node_modules/ " >> .gitignore -git update-index --assume-unchanged .gitignore # To keep runtime good, just continue if something was changed if _git_changed; then @@ -84,6 +83,7 @@ if _git_changed; then # Add changes to git git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}" fi + git rm .gitignore # Commit and push changes back if $INPUT_SAME_COMMIT; then From 7d4939bf14f5b8e790b0c6232801ec61c371f476 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 19:09:45 +0100 Subject: [PATCH 22/43] Another try at bugfixing the ignore mechanism --- entrypoint.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8dc8c5f..978dce1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -60,9 +60,8 @@ echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" # Ignore node modules and other action created files -echo "package_lock.json -node_modules/ -" >> .gitignore +git update-index --skip-worktree package_lock.json +git update-index --skip-worktree node_modules/ # To keep runtime good, just continue if something was changed if _git_changed; then @@ -83,7 +82,6 @@ if _git_changed; then # Add changes to git git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}" fi - git rm .gitignore # Commit and push changes back if $INPUT_SAME_COMMIT; then From 5e56c643886c64170505a86fa95a03744b6f6bd2 Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 19:13:29 +0100 Subject: [PATCH 23/43] Another try at bugfixing the ignore mechanism --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 978dce1..98bcc42 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -60,8 +60,8 @@ echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" # Ignore node modules and other action created files -git update-index --skip-worktree package_lock.json -git update-index --skip-worktree node_modules/ +rm -r node_modules/ +git reset --hard package-lock.json || rm package-lock.json # To keep runtime good, just continue if something was changed if _git_changed; then From 1f62e028b6c963411bf7a172190b76c0627e418c Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 19:16:25 +0100 Subject: [PATCH 24/43] Added exceptions to improve stability --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 98bcc42..1a9e514 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -60,8 +60,8 @@ echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" # Ignore node modules and other action created files -rm -r node_modules/ -git reset --hard package-lock.json || rm package-lock.json +rm -r node_modules/ || echo "No node_modules/ folder." +git reset --hard package-lock.json || rm package-lock.json || echo "No node_modules/ folder." # To keep runtime good, just continue if something was changed if _git_changed; then From b81496839ae01ebae5800ff4146f9168ea4c46eb Mon Sep 17 00:00:00 2001 From: creyD Date: Fri, 19 Feb 2021 19:18:23 +0100 Subject: [PATCH 25/43] Adjusted exception message and finalized changes --- entrypoint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1a9e514..eb078cb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,7 +26,6 @@ _git_changed() { } ( - # PROGRAM # Changing to the directory cd "$GITHUB_ACTION_PATH" @@ -61,7 +60,7 @@ prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_P # Ignore node modules and other action created files rm -r node_modules/ || echo "No node_modules/ folder." -git reset --hard package-lock.json || rm package-lock.json || echo "No node_modules/ folder." +git reset --hard package-lock.json || rm package-lock.json || echo "No package-lock.json file." # To keep runtime good, just continue if something was changed if _git_changed; then From d48a703bcde4732389f7b303a300239d619aa796 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Fri, 19 Feb 2021 14:52:10 -0500 Subject: [PATCH 26/43] Handle bash globs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous system relied on a different shell's magic for handling `*` / `**` nullglob - If set, Bash allows filename patterns which match no files to expand to a null string, rather than themselves. globstar - If set, the pattern ‘**’ used in a filename expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a ‘/’, only directories and subdirectories match. --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index eb078cb..b51fd1a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,6 +2,7 @@ # e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set # x would be for showing the commands before they are executed set -eu +shopt -s globstar nullglob # FUNCTIONS # Function for setting up git env in the docker container (copied from https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh) From e81db121ba2beda9348d54c43b80d04b87e5711a Mon Sep 17 00:00:00 2001 From: Wojtek Siudzinski Date: Sun, 28 Feb 2021 11:16:39 +0100 Subject: [PATCH 27/43] Allow unofficial plugins --- entrypoint.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 023e697..d884057 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -38,14 +38,6 @@ esac # Install plugins if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then - for plugin in $INPUT_PRETTIER_PLUGINS; do - echo "Checking plugin: $plugin" - # check regex against @prettier/xyz - if ! echo "$plugin" | grep -Eq '(@prettier\/)+(plugin-[a-z\-]+)'; then - echo "$plugin does not seem to be a valid @prettier/plugin-x plugin. Exiting." - exit 1 - fi - done npm install --silent --global $INPUT_PRETTIER_PLUGINS fi From 6c3c102255fb4b1628be21ff61c609617f888969 Mon Sep 17 00:00:00 2001 From: Roger Sheen Date: Mon, 1 Mar 2021 00:25:35 +0100 Subject: [PATCH 28/43] Fix plugin name syntax in README & description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The entrypoint script checks for correctly named Prettier plugins on [lines 44–45](https://github.com/creyD/prettier_action/blob/master/entrypoint.sh#L44-L45), but the description in the config file and README are not consistent. This updates those references to clarify how plugins should be specified. --- README.md | 2 +- action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e689898..025a7bf 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | 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` | | file_pattern | :x: | `*` | Custom git add file pattern, can't be used with only_changed! | -| prettier_plugins | :x: | ` ` | Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin` | +| 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)| > 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 a0d155c..6aef0b8 100644 --- a/action.yml +++ b/action.yml @@ -36,7 +36,7 @@ inputs: required: false default: false prettier_plugins: - description: Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin` + description: Install Prettier plugins, i.e. `@prettier/plugin-php @prettier/plugin-other` required: false default: '' From 53d0f90f4e22ebd8fb8a0f7bd9e53fd6e32e206c Mon Sep 17 00:00:00 2001 From: Conrad Date: Mon, 1 Mar 2021 15:18:08 +0100 Subject: [PATCH 29/43] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 025a7bf..6fb4f6f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | 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` | | 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` | +| 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)| > 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. From bc1e95cc3023831f262a4a06591304e89e924afa Mon Sep 17 00:00:00 2001 From: Conrad Date: Mon, 1 Mar 2021 15:20:54 +0100 Subject: [PATCH 30/43] Adjusted the prettier_plugins variable to documentation --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index 5c09572..68f612f 100644 --- a/action.yml +++ b/action.yml @@ -38,7 +38,6 @@ inputs: prettier_plugins: description: Install Prettier plugins, i.e. `@prettier/plugin-php @prettier/plugin-other` required: false - default: "" runs: using: "composite" From b40e4ba1c813c997fcea24414d52d49af2629b2c Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 19:48:04 -0300 Subject: [PATCH 31/43] fix(issue-37): adds logic to handle prettier cmd output to shell dry-run exit --- entrypoint.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 023e697..2b53342 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -52,12 +52,21 @@ fi echo "Prettifing files..." echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" +PRETTIER_RESULT=$? + +# Ignore node modules and other action created files +rm -r node_modules/ || echo "No node_modules/ folder." +git reset --hard package-lock.json || rm package-lock.json || echo "No package-lock.json file." # To keep runtime good, just continue if something was changed if _git_changed; then if $INPUT_DRY; then - echo "Prettier found unpretty files!" - exit 1 + if [[ "$PRETTIER_RESULT" -eq 1 ]]; then + echo "Prettier found unpretty files!" + exit 1 + else + echo "No unpretty files! Finishing dry-run." + fi else # Calling method to configure the git environemnt _git_setup From 0e4ccc84cf13030bb1b5ea60e79c0f42ec7f6803 Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 20:13:05 -0300 Subject: [PATCH 32/43] style: fixes log message --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2b53342..28f5385 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -49,7 +49,7 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then npm install --silent --global $INPUT_PRETTIER_PLUGINS fi -echo "Prettifing files..." +echo "Prettifying files..." echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" PRETTIER_RESULT=$? From 217be60a6abae5d780f55e69365015e1969c5846 Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 20:22:03 -0300 Subject: [PATCH 33/43] fix: removes code block added by mistake from dev branch --- entrypoint.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 28f5385..d427fa4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -54,10 +54,6 @@ echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" PRETTIER_RESULT=$? -# Ignore node modules and other action created files -rm -r node_modules/ || echo "No node_modules/ folder." -git reset --hard package-lock.json || rm package-lock.json || echo "No package-lock.json file." - # To keep runtime good, just continue if something was changed if _git_changed; then if $INPUT_DRY; then From 70f47fbe7e497da674d53a18f8a175fb85c23f3f Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 20:50:30 -0300 Subject: [PATCH 34/43] fix: fixes handling of bad case where there are unpretty files and command output is not 0 --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index d427fa4..0705eef 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -51,13 +51,14 @@ fi echo "Prettifying files..." echo "Files:" -prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" +prettier $INPUT_PRETTIER_OPTIONS PRETTIER_RESULT=$? # To keep runtime good, just continue if something was changed if _git_changed; then if $INPUT_DRY; then if [[ "$PRETTIER_RESULT" -eq 1 ]]; then + echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" echo "Prettier found unpretty files!" exit 1 else From 341259c9e6420252eaaa8d5f079f3bfe261b4d4f Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 20:59:41 -0300 Subject: [PATCH 35/43] other: testing another approach to handle both cases --- entrypoint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0705eef..c8802ba 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -51,8 +51,7 @@ fi echo "Prettifying files..." echo "Files:" -prettier $INPUT_PRETTIER_OPTIONS -PRETTIER_RESULT=$? +PRETTIER_RESULT=$(prettier $INPUT_PRETTIER_OPTIONS) # To keep runtime good, just continue if something was changed if _git_changed; then From 2602a7aad827775d3e97025995f8ba95bed5b777 Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 21:10:04 -0300 Subject: [PATCH 36/43] other: testing approach using pipefail --- entrypoint.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index c8802ba..1a7d0eb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,6 +2,7 @@ # e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set # x would be for showing the commands before they are executed set -eu +set -o pipefail # FUNCTIONS # Function for setting up git env in the docker container (copied from https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh) @@ -51,13 +52,14 @@ fi echo "Prettifying files..." echo "Files:" -PRETTIER_RESULT=$(prettier $INPUT_PRETTIER_OPTIONS) +prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" +PRETTIER_RESULT=$? # To keep runtime good, just continue if something was changed if _git_changed; then if $INPUT_DRY; then if [[ "$PRETTIER_RESULT" -eq 1 ]]; then - echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" + echo "Prettier found unpretty files!" exit 1 else From 67234beef0016ee36fc3f28eeb0575fd1b9ee7c0 Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 21:21:06 -0300 Subject: [PATCH 37/43] other: testing approach with multiple commands on fail --- entrypoint.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1a7d0eb..1ee50b1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,7 +2,6 @@ # e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set # x would be for showing the commands before they are executed set -eu -set -o pipefail # FUNCTIONS # Function for setting up git env in the docker container (copied from https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh) @@ -52,14 +51,12 @@ fi echo "Prettifying files..." echo "Files:" -prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" -PRETTIER_RESULT=$? +prettier $INPUT_PRETTIER_OPTIONS || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; } # To keep runtime good, just continue if something was changed if _git_changed; then if $INPUT_DRY; then if [[ "$PRETTIER_RESULT" -eq 1 ]]; then - echo "Prettier found unpretty files!" exit 1 else From 3d912f60d11e7fd9e30fe89f9d7413a1de5130ed Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 21:28:17 -0300 Subject: [PATCH 38/43] fix: added variable declaration --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index 1ee50b1..3c001a8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -49,6 +49,7 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then npm install --silent --global $INPUT_PRETTIER_PLUGINS fi +PRETTIER_RESULT="" echo "Prettifying files..." echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; } From 5b4a6a018311e155aafab3aeaf546ea383ff3b59 Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 21:34:44 -0300 Subject: [PATCH 39/43] docs: note about using --check on options to help in dry running --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e689898..000f716 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | Parameter | Required | Default | Description | | - | :-: | :-: | - | -| dry | :x: | `false` | Runs the action in dry mode. Files wont get changed and the action fails if there are unprettified files. | +| 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) | | prettier_options | :x: | `"--write **/*.js"` | Prettier options (by default it applies to the whole repository) | | commit_options | :x: | - | Custom git commit options | From 2069f26b6edf8dab3498f1dfb74d7d7f3ab3af7a Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 21:36:51 -0300 Subject: [PATCH 40/43] other: improves the log output by not having and out of range message --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3c001a8..f61da4b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -49,7 +49,7 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then npm install --silent --global $INPUT_PRETTIER_PLUGINS fi -PRETTIER_RESULT="" +PRETTIER_RESULT=0 echo "Prettifying files..." echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; } From c2e2730594c7f4286b43b7d43c6b3a18c5e05523 Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Thu, 25 Mar 2021 21:56:57 -0300 Subject: [PATCH 41/43] fix: fixes codefactor recommendation --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index f61da4b..501660f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -57,7 +57,7 @@ prettier $INPUT_PRETTIER_OPTIONS || { PRETTIER_RESULT=$?; echo "Problem running # To keep runtime good, just continue if something was changed if _git_changed; then if $INPUT_DRY; then - if [[ "$PRETTIER_RESULT" -eq 1 ]]; then + if [ "$PRETTIER_RESULT" -eq 1 ]; then echo "Prettier found unpretty files!" exit 1 else From 634a3d2075a4b775044879c9465589be8f64f3f0 Mon Sep 17 00:00:00 2001 From: Fabricio Sander <79223916+fsz-codeshop@users.noreply.github.com> Date: Tue, 13 Apr 2021 16:34:40 -0300 Subject: [PATCH 42/43] fix: changes the logic to handle dry-run with --write option and corrects the logic as it will never have changes on dry-run --- entrypoint.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 501660f..43bd364 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,6 +25,10 @@ _git_changed() { [[ -n "$(git status -s)" ]] } +_git_changes() { + git diff +} + # PROGRAM echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in @@ -56,13 +60,12 @@ prettier $INPUT_PRETTIER_OPTIONS || { PRETTIER_RESULT=$?; echo "Problem running # To keep runtime good, just continue if something was changed if _git_changed; then + # case when --write is used with dry-run so if something is unpretty there will always have _git_changed if $INPUT_DRY; then - if [ "$PRETTIER_RESULT" -eq 1 ]; then - echo "Prettier found unpretty files!" - exit 1 - else - echo "No unpretty files! Finishing dry-run." - fi + echo "Unpretty Files Changes:" + _git_changes + echo "Finishing dry-run. Exiting before committing." + exit 1 else # Calling method to configure the git environemnt _git_setup @@ -91,5 +94,13 @@ if _git_changed; then echo "Changes pushed successfully." fi else + # case when --check is used so there will never have something to commit but there are unpretty files + if [ "$PRETTIER_RESULT" -eq 1 ]; then + echo "Prettier found unpretty files!" + exit 1 + else + echo "Finishing dry-run." + fi + echo "No unpretty files!" echo "Nothing to commit. Exiting." fi From 707db7683735a7823f4524d4b7c1f86ff8dc94c5 Mon Sep 17 00:00:00 2001 From: Steve Lacy Date: Thu, 20 May 2021 09:39:31 -1000 Subject: [PATCH 43/43] Add input git push options --- README.md | 1 + action.yml | 3 +++ entrypoint.sh | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2971f4..1b3fb6d 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | prettier_version | :x: | `false` | Specific prettier version (by default use latest) | | 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 | | 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` | | file_pattern | :x: | `*` | Custom git add file pattern, can't be used with only_changed! | diff --git a/action.yml b/action.yml index a0d155c..383ea4d 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,9 @@ inputs: commit_options: description: Commit options required: false + push_options: + description: Git push options + required: false file_pattern: description: File pattern used for `git add`, can't be used with only_changed! required: false diff --git a/entrypoint.sh b/entrypoint.sh index 023e697..b7029a5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -81,7 +81,7 @@ if _git_changed; then 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 push origin + git push origin $INPUT_PUSH_OPTIONS fi echo "Changes pushed successfully." fi