mirror of
https://github.com/creyD/prettier_action.git
synced 2026-04-12 19:30:30 +02:00
Improved README and Code
This commit is contained in:
2
LICENSE
2
LICENSE
@@ -14,7 +14,7 @@ copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
|
||||
@@ -14,9 +14,7 @@ A GitHub action for styling files with [prettier](https://prettier.io).
|
||||
| commit_options | :x: | - | Custom git commit options |
|
||||
| commit_message | :x: | Prettified Code! | Custom git commit message |
|
||||
| file_pattern | :x: | * | Custom git add file pattern |
|
||||
| branch | :white_check_mark: | - | See note below! |
|
||||
|
||||
> There are two types of action triggers in GitHub: on pull request and on push. The branch needs to be defined for both, but in case of the pull request trigger it should have `${{ github.head_ref }}` and on push it should have the branch the trigger is designed for.
|
||||
| branch | :white_check_mark: | - | There are two types of action triggers in GitHub: on pull request and on push. The branch needs to be defined for both, but in case of the pull request trigger it should have `${{ github.head_ref }}` and on push it should have the branch the trigger is designed for. |
|
||||
|
||||
### Example Config
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#!/bin/sh
|
||||
# e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set, x is for showing the commands before they are executed
|
||||
set -eux
|
||||
# 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
|
||||
|
||||
# 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)
|
||||
_git_setup ( ) {
|
||||
cat <<- EOF > $HOME/.netrc
|
||||
@@ -18,10 +20,12 @@ EOF
|
||||
git config --global user.name "GitHub Action"
|
||||
}
|
||||
|
||||
# Checks if any files are changed
|
||||
_git_changed() {
|
||||
[[ -n "$(git status -s)" ]]
|
||||
}
|
||||
|
||||
# Pushes to the according upstream (origin or input branch)
|
||||
_git_push() {
|
||||
if [ -z "$INPUT_BRANCH" ]
|
||||
then
|
||||
@@ -31,21 +35,23 @@ _git_push() {
|
||||
fi
|
||||
}
|
||||
|
||||
# PROGRAM
|
||||
echo "Installing prettier..."
|
||||
npm install --silent --global prettier
|
||||
|
||||
echo "Prettifing files..."
|
||||
prettier $INPUT_PRETTIER_OPTIONS || echo "Problem while prettifying your files!"
|
||||
prettier $INPUT_PRETTIER_OPTIONS || echo "Problem while prettifying your files with options $INPUT_PRETTIER_OPTIONS"
|
||||
|
||||
# To keep runtime good, just continue if something was changed
|
||||
if _git_changed;
|
||||
then
|
||||
# Calling method to configure the git environemnt
|
||||
_git_setup
|
||||
echo "Commiting and pushing changes..."
|
||||
# Switch to the actual branch
|
||||
git checkout $INPUT_BRANCH
|
||||
git checkout $INPUT_BRANCH || echo "Problem checking out the specified branch: $INPUT_BRANCH"
|
||||
# Add changes to git
|
||||
git add "${INPUT_FILE_PATTERN}"
|
||||
git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}"
|
||||
# Commit and push changes back
|
||||
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"}
|
||||
_git_push
|
||||
|
||||
Reference in New Issue
Block a user