mirror of
https://github.com/creyD/prettier_action.git
synced 2026-04-12 19:30:30 +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:
|
||||
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,12 +38,27 @@ inputs:
|
||||
prettier_plugins:
|
||||
description: Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin`
|
||||
required: false
|
||||
default: ''
|
||||
default: ""
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
using: "composite"
|
||||
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:
|
||||
icon: 'award'
|
||||
color: 'green'
|
||||
icon: "award"
|
||||
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
|
||||
# x would be for showing the commands before they are executed
|
||||
set -eu
|
||||
@@ -25,14 +25,18 @@ _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
|
||||
|
||||
@@ -46,13 +50,18 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
npm install --silent --global $INPUT_PRETTIER_PLUGINS
|
||||
npm install --silent $INPUT_PRETTIER_PLUGINS
|
||||
fi
|
||||
)
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user