mirror of
https://github.com/creyD/prettier_action.git
synced 2026-04-12 19:30:30 +02:00
Merge branch 'dev' into master
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#!/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
|
||||
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)
|
||||
@@ -25,31 +26,53 @@ _git_changed() {
|
||||
[[ -n "$(git status -s)" ]]
|
||||
}
|
||||
|
||||
(
|
||||
# PROGRAM
|
||||
# Changing to the directory
|
||||
cd "$GITHUB_ACTION_PATH"
|
||||
|
||||
echo "Installing prettier..."
|
||||
case $INPUT_PRETTIER_VERSION in
|
||||
false)
|
||||
npm install --silent --global prettier
|
||||
npm install --silent prettier
|
||||
;;
|
||||
*)
|
||||
npm install --silent --global prettier@$INPUT_PRETTIER_VERSION
|
||||
npm install --silent prettier@$INPUT_PRETTIER_VERSION
|
||||
;;
|
||||
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
|
||||
)
|
||||
|
||||
echo "Prettifing files..."
|
||||
PRETTIER_RESULT=0
|
||||
echo "Prettifying files..."
|
||||
echo "Files:"
|
||||
prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"
|
||||
prettier $INPUT_PRETTIER_OPTIONS || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; }
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user