Skip to content

Commit dbdc557

Browse files
authored
Merge pull request #73 from creyD/dev
v4.1 Deployment
2 parents 0b655e2 + 9accc7b commit dbdc557

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ A GitHub action for styling files with [prettier](https://prettier.io).
1818
| - | :-: | :-: | - |
1919
| 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 |
2020
| prettier_version | :x: | `false` | Specific prettier version (by default use latest) |
21+
| 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/` |
2122
| prettier_options | :x: | `"--write **/*.js"` | Prettier options (by default it applies to the whole repository) |
2223
| commit_options | :x: | - | Custom git commit options |
2324
| push_options | :x: | - | Custom git push options |
2425
| 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) |
2526
| commit_message | :x: | `"Prettified Code!"` | Custom git commit message, will be ignored if used with `same_commit` |
27+
| commit_description | :x: | - | Custom git extended commit message, will be ignored if used with `same_commit` |
2628
| file_pattern | :x: | `*` | Custom git add file pattern, can't be used with only_changed! |
2729
| prettier_plugins | :x: | - | Install Prettier plugins, i.e. `@prettier/plugin-php @prettier/plugin-other` |
2830
| 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)|
@@ -32,7 +34,8 @@ A GitHub action for styling files with [prettier](https://prettier.io).
3234
3335
### Example Config
3436

35-
#### Example 1 (run on push in master)
37+
> Hint: if you still use the old naming convention or generally a different branch name, please replace the `main` in the following configurations.
38+
#### Example 1 (run on push in branch main)
3639
```yaml
3740
name: Continuous Integration
3841

@@ -41,7 +44,7 @@ on:
4144
pull_request:
4245
push:
4346
branches:
44-
- master
47+
- main
4548

4649
jobs:
4750
prettier:
@@ -55,7 +58,7 @@ jobs:
5558
ref: ${{ github.head_ref }}
5659

5760
- name: Prettify code
58-
uses: creyD/prettier_action@v4.0
61+
uses: creyD/prettier_action@v4.1
5962
with:
6063
# This part is also where you can pass other options, for example:
6164
prettier_options: --write **/*.{js,md}
@@ -67,7 +70,7 @@ name: Continuous Integration
6770

6871
on:
6972
pull_request:
70-
branches: [master]
73+
branches: [main]
7174

7275
jobs:
7376
prettier:
@@ -83,7 +86,7 @@ jobs:
8386
fetch-depth: 0
8487

8588
- name: Prettify code
86-
uses: creyD/prettier_action@v4.0
89+
uses: creyD/prettier_action@v4.1
8790
with:
8891
# This part is also where you can pass other options, for example:
8992
prettier_options: --write **/*.{js,md}
@@ -96,7 +99,7 @@ name: Continuous Integration
9699

97100
on:
98101
pull_request:
99-
branches: [master]
102+
branches: [main]
100103

101104
jobs:
102105
prettier:
@@ -112,7 +115,7 @@ jobs:
112115
persist-credentials: false
113116

114117
- name: Prettify code
115-
uses: creyD/prettier_action@v4.0
118+
uses: creyD/prettier_action@v4.1
116119
with:
117120
prettier_options: --write **/*.{js,md}
118121
only_changed: True
@@ -126,7 +129,7 @@ name: Continuous Integration
126129

127130
on:
128131
pull_request:
129-
branches: [master]
132+
branches: [main]
130133

131134
jobs:
132135
prettier:
@@ -142,7 +145,7 @@ jobs:
142145
persist-credentials: false
143146

144147
- name: Prettify code
145-
uses: creyD/prettier_action@v4.0
148+
uses: creyD/prettier_action@v4.1
146149
with:
147150
dry: True
148151
github_token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}

action.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ inputs:
88
description: Commit message, will be ignored if used with same_commit
99
required: false
1010
default: "Prettified Code!"
11+
commit_description:
12+
description: Extended commit message, will be ignored if used with same_commit
13+
required: false
14+
default: ""
1115
same_commit:
1216
description: Update the current commit instead of creating a new one
1317
required: false
@@ -34,20 +38,23 @@ inputs:
3438
description: Specific version of prettier (by default just use the latest version)
3539
required: false
3640
default: false
41+
working_directory:
42+
description: Specify a directory to cd into before installing prettier and running it
43+
required: false
44+
default: false
3745
only_changed:
3846
description: Only prettify files changed in the last commit, can't be used with file_pattern!
3947
required: false
4048
default: false
4149
prettier_plugins:
4250
description: Install Prettier plugins, i.e. `@prettier/plugin-php @prettier/plugin-other`
4351
required: false
44-
default: ''
52+
default: ""
4553
github_token:
4654
description: GitHub Token or PAT token used to authenticate against a repository
4755
required: false
4856
default: ${{ github.token }}
4957

50-
5158
runs:
5259
using: "composite"
5360
steps:
@@ -58,6 +65,7 @@ runs:
5865
${{ github.action_path }}/entrypoint.sh
5966
env:
6067
INPUT_COMMIT_MESSAGE: ${{ inputs.commit_message }}
68+
INPUT_COMMIT_DESCRIPTION: ${{ inputs.commit_description }}
6169
INPUT_SAME_COMMIT: ${{ inputs.same_commit }}
6270
INPUT_COMMIT_OPTIONS: ${{ inputs.commit_options }}
6371
INPUT_FILE_PATTERN: ${{ inputs.file_pattern }}
@@ -66,6 +74,7 @@ runs:
6674
INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }}
6775
INPUT_ONLY_CHANGED: ${{ inputs.only_changed }}
6876
INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }}
77+
INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }}
6978
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
7079

7180
branding:

entrypoint.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ cd "$GITHUB_ACTION_PATH"
3737

3838
echo "Installing prettier..."
3939

40+
case $INPUT_WORKING_DIRECTORY in
41+
false)
42+
;;
43+
*)
44+
cd $INPUT_WORKING_DIRECTORY
45+
;;
46+
esac
47+
4048
case $INPUT_PRETTIER_VERSION in
4149
false)
4250
npm install --silent prettier
@@ -74,7 +82,7 @@ else
7482
fi
7583

7684
if [ -f 'package-lock.json' ]; then
77-
git reset --hard package-lock.json || rm package-lock.json
85+
git checkout -- package-lock.json
7886
else
7987
echo "No package-lock.json file."
8088
fi
@@ -93,10 +101,13 @@ if _git_changed; then
93101

94102
if $INPUT_ONLY_CHANGED; then
95103
# --diff-filter=d excludes deleted files
104+
OLDIFS="$IFS"
105+
IFS=$'\n'
96106
for file in $(git diff --name-only --diff-filter=d HEAD^..HEAD)
97107
do
98-
git add $file
108+
git add "$file"
99109
done
110+
IFS="$OLDIFS"
100111
else
101112
# Add changes to git
102113
git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}"
@@ -109,7 +120,7 @@ if _git_changed; then
109120
git commit --amend --no-edit
110121
git push origin -f
111122
else
112-
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"
123+
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"
113124
git push origin ${INPUT_PUSH_OPTIONS:-}
114125
fi
115126
echo "Changes pushed successfully."

0 commit comments

Comments
 (0)