From e338a630e679fac7089c57b02995c9e8942a19e6 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Fri, 19 Feb 2021 00:49:16 -0500 Subject: [PATCH 01/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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/32] 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 672408b1dbf630b8db43bdbb709b896c01cd84c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Sch=C3=B6nfeldt?= Date: Mon, 10 May 2021 18:01:39 +0200 Subject: [PATCH 31/32] Update README.md Use latest action version in example :-) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e689898..d2971f4 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ jobs: ref: ${{ github.head_ref }} - name: Prettify code - uses: creyD/prettier_action@v3.1 + uses: creyD/prettier_action@v3.3 with: # This part is also where you can pass other options, for example: prettier_options: --write **/*.{js,md} @@ -83,7 +83,7 @@ jobs: fetch-depth: 0 - name: Prettify code - uses: creyD/prettier_action@v3.1 + uses: creyD/prettier_action@v3.3 with: # This part is also where you can pass other options, for example: prettier_options: --write **/*.{js,md} From 707db7683735a7823f4524d4b7c1f86ff8dc94c5 Mon Sep 17 00:00:00 2001 From: Steve Lacy Date: Thu, 20 May 2021 09:39:31 -1000 Subject: [PATCH 32/32] 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