mirror of
https://github.com/creyD/prettier_action.git
synced 2026-04-15 04:40:33 +02:00
Added Prettier Action
This commit is contained in:
5
Dockerfile
Normal file
5
Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
FROM node:latest
|
||||||
|
COPY entrypoint.sh ./entrypoint.sh
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
37
action.yml
Normal file
37
action.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: 'Prettier Action'
|
||||||
|
description: 'Automatically runs prettier on all your pull requests.'
|
||||||
|
|
||||||
|
author: Conrad Großer <grosserconrad@gmail.com>
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
commit_message:
|
||||||
|
description: Commit message
|
||||||
|
required: false
|
||||||
|
default: 'Prettified Code!'
|
||||||
|
commit_options:
|
||||||
|
description: Commit options
|
||||||
|
required: false
|
||||||
|
file_pattern:
|
||||||
|
description: File pattern used for "git add"
|
||||||
|
required: false
|
||||||
|
default: '*'
|
||||||
|
prettier_options:
|
||||||
|
description: Options for the 'prettier' command
|
||||||
|
required: true
|
||||||
|
branch:
|
||||||
|
description: Branch which the changes are merged to, should be ${{ github.head_ref }} for PRs
|
||||||
|
required: true
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: 'docker'
|
||||||
|
image: 'Dockerfile'
|
||||||
|
args:
|
||||||
|
- ${{ inputs.commit_message }}
|
||||||
|
- ${{ inputs.commit_options }}
|
||||||
|
- ${{ inputs.file_pattern }}
|
||||||
|
- ${{ inputs.prettier_options }}
|
||||||
|
- ${{ inputs.branch }}
|
||||||
|
|
||||||
|
branding:
|
||||||
|
icon: 'award'
|
||||||
|
color: 'green'
|
||||||
39
entrypoint.sh
Executable file
39
entrypoint.sh
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/sh -l
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
# 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
|
||||||
|
machine github.com
|
||||||
|
login $GITHUB_ACTOR
|
||||||
|
password $GITHUB_TOKEN
|
||||||
|
machine api.github.com
|
||||||
|
login $GITHUB_ACTOR
|
||||||
|
password $GITHUB_TOKEN
|
||||||
|
EOF
|
||||||
|
chmod 600 $HOME/.netrc
|
||||||
|
|
||||||
|
git config --global user.email "actions@github.com"
|
||||||
|
git config --global user.name "GitHub Actions"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Prettifing files..."
|
||||||
|
prettier $INPUT_PRETTIER_OPTIONS
|
||||||
|
|
||||||
|
if ! git diff --quiet
|
||||||
|
then
|
||||||
|
echo "Commiting and pushing changes..."
|
||||||
|
# Calling method to configure the git environemnt
|
||||||
|
git_setup
|
||||||
|
# Switch to the actual branch
|
||||||
|
git checkout $INPUT_BRANCH
|
||||||
|
# Add changes to git
|
||||||
|
git add "${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 --set-upstream origin "HEAD:$INPUT_BRANCH"
|
||||||
|
echo "Changes pushed successfully."
|
||||||
|
else
|
||||||
|
echo "Nothing to commit. Exiting."
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user