mirror of
https://github.com/creyD/autopep8_action.git
synced 2026-04-12 19:40:28 +02:00
Added action code
This commit is contained in:
3
Dockerfile
Normal file
3
Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM python:3
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
38
action.yml
Normal file
38
action.yml
Normal file
@@ -0,0 +1,38 @@
|
||||
name: 'Autopep8'
|
||||
description: 'Automatically runs the autopep8 command against any pull request created.'
|
||||
|
||||
author: Conrad Großer <grosserconrad@gmail.com>
|
||||
|
||||
inputs:
|
||||
commit_message:
|
||||
description: Commit message
|
||||
required: false
|
||||
default: 'Adjusted files for PEP-8 compliance'
|
||||
commit_options:
|
||||
description: Commit options
|
||||
required: false
|
||||
file_pattern:
|
||||
description: File pattern used for "git add"
|
||||
required: false
|
||||
default: '*'
|
||||
dependencies:
|
||||
description: Path for the repositories 'requirements.txt'. If you have none, you may skip this.
|
||||
required: false
|
||||
default: 'false'
|
||||
branch:
|
||||
description: Branch which the changes are merged to
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.commit_message }}
|
||||
- ${{ inputs.commit_options }}
|
||||
- ${{ inputs.file_pattern }}
|
||||
- ${{ inputs.dependencies }}
|
||||
- ${{ inputs.branch }}
|
||||
|
||||
branding:
|
||||
icon: 'fast-forward'
|
||||
color: 'green'
|
||||
50
entrypoint.sh
Normal file
50
entrypoint.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/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 "Installing dependencies..."
|
||||
pip install --upgrade pip
|
||||
# Install dependencies
|
||||
pip install autopep8
|
||||
|
||||
# Install custom project dependencies if applicable
|
||||
if ! $INPUT_DEPENDENCIES == "false"
|
||||
then
|
||||
pip install -r $INPUT_DEPENDENCIES
|
||||
fi
|
||||
|
||||
# Apply PEP 8
|
||||
echo "Running autopep8..."
|
||||
autopep8 --in-place -r .
|
||||
|
||||
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
|
||||
|
||||
git add "${INPUT_FILE_PATTERN}"
|
||||
|
||||
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"
|
||||
else
|
||||
echo "Nothing to commit. Exiting."
|
||||
fi
|
||||
Reference in New Issue
Block a user