mirror of
https://github.com/creyD/prettier_action.git
synced 2026-04-15 04:40:33 +02:00
Merge pull request #39 from creyD/dev_composite
Moved the action to composite
This commit is contained in:
@@ -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"]
|
|
||||||
31
action.yml
31
action.yml
@@ -7,7 +7,7 @@ inputs:
|
|||||||
commit_message:
|
commit_message:
|
||||||
description: Commit message, will be ignored if used with same_commit
|
description: Commit message, will be ignored if used with same_commit
|
||||||
required: false
|
required: false
|
||||||
default: 'Prettified Code!'
|
default: "Prettified Code!"
|
||||||
same_commit:
|
same_commit:
|
||||||
description: Update the current commit instead of creating a new one
|
description: Update the current commit instead of creating a new one
|
||||||
required: false
|
required: false
|
||||||
@@ -18,11 +18,11 @@ inputs:
|
|||||||
file_pattern:
|
file_pattern:
|
||||||
description: File pattern used for `git add`, can't be used with only_changed!
|
description: File pattern used for `git add`, can't be used with only_changed!
|
||||||
required: false
|
required: false
|
||||||
default: '*'
|
default: "*"
|
||||||
prettier_options:
|
prettier_options:
|
||||||
description: Options for the `prettier` command
|
description: Options for the `prettier` command
|
||||||
required: false
|
required: false
|
||||||
default: '--write **/*.js'
|
default: "--write **/*.js"
|
||||||
dry:
|
dry:
|
||||||
description: Running the script in dry mode just shows whether there are files that should be prettified or not
|
description: Running the script in dry mode just shows whether there are files that should be prettified or not
|
||||||
required: false
|
required: false
|
||||||
@@ -38,12 +38,27 @@ inputs:
|
|||||||
prettier_plugins:
|
prettier_plugins:
|
||||||
description: Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin`
|
description: Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin`
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ""
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: "composite"
|
||||||
image: 'Dockerfile'
|
steps:
|
||||||
|
- name: Prettify code!
|
||||||
|
shell: bash
|
||||||
|
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 }}
|
||||||
|
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:
|
branding:
|
||||||
icon: 'award'
|
icon: "award"
|
||||||
color: 'green'
|
color: "green"
|
||||||
|
|||||||
@@ -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
|
# 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
|
# x would be for showing the commands before they are executed
|
||||||
set -eu
|
set -eu
|
||||||
@@ -25,14 +25,18 @@ _git_changed() {
|
|||||||
[[ -n "$(git status -s)" ]]
|
[[ -n "$(git status -s)" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(
|
||||||
# PROGRAM
|
# PROGRAM
|
||||||
|
# Changing to the directory
|
||||||
|
cd "$GITHUB_ACTION_PATH"
|
||||||
|
|
||||||
echo "Installing prettier..."
|
echo "Installing prettier..."
|
||||||
case $INPUT_PRETTIER_VERSION in
|
case $INPUT_PRETTIER_VERSION in
|
||||||
false)
|
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
|
esac
|
||||||
|
|
||||||
@@ -46,13 +50,18 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
npm install --silent --global $INPUT_PRETTIER_PLUGINS
|
npm install --silent $INPUT_PRETTIER_PLUGINS
|
||||||
fi
|
fi
|
||||||
|
)
|
||||||
|
|
||||||
echo "Prettifing files..."
|
echo "Prettifing files..."
|
||||||
echo "Files:"
|
echo "Files:"
|
||||||
prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"
|
prettier $INPUT_PRETTIER_OPTIONS || 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
|
# To keep runtime good, just continue if something was changed
|
||||||
if _git_changed; then
|
if _git_changed; then
|
||||||
if $INPUT_DRY; then
|
if $INPUT_DRY; then
|
||||||
|
|||||||
Reference in New Issue
Block a user