mirror of
https://github.com/creyD/autopep8_action.git
synced 2026-04-12 19:40:28 +02:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 18f406b1d0 | |||
| 6b39f1b281 | |||
| f515b34fb6 | |||
| 60ab91e841 | |||
| 0982f18fb5 | |||
| 5d9e84c500 | |||
| 3f07e64ccb | |||
| c8d9e2fc74 | |||
| 4449ec2f27 | |||
| fe6126ea98 | |||
| 308fd515a8 | |||
| faaac4d215 | |||
| d4eb464ac0 | |||
| daa4e6b569 | |||
| a51a186977 | |||
| ded507f15f | |||
| e658219e54 | |||
| 6271ffc1c4 | |||
| 2a43a06c54 | |||
| 90bfa73dca | |||
| 8fa1e16ff1 | |||
| 552eff98a5 | |||
| 8994743494 | |||
| f84db99f70 | |||
| 4a8632c121 | |||
| 4db3b98ca0 | |||
| 08c429cdb4 | |||
| 3aac0062d0 | |||
| 421e07b203 | |||
| e6bb938eaf | |||
| 6ab9bc834c |
@@ -1,3 +1,9 @@
|
||||
FROM python:3
|
||||
FROM node:lts-alpine3.9
|
||||
|
||||
RUN apk update && apk add --no-cache bash git openssh python py-pip
|
||||
|
||||
RUN pip install --no-cache-dir -q --upgrade pip
|
||||
RUN pip install --no-cache-dir -q autopep8
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
33
README.md
33
README.md
@@ -8,33 +8,38 @@ The following parameters can be used in your custom action configuration.
|
||||
|
||||
| Parameter | Required | Default | Description |
|
||||
| - | - | - | - |
|
||||
| commit_message | :x: | 'Adjusted files for PEP-8 compliance' | Custom git commit message|
|
||||
| commit_options | :x: | '*' | Custom git commit options|
|
||||
| file_pattern | :x: | '.' | Custom file pattern for `git add`|
|
||||
| dependencies | :x: | 'false' | Path for the repositories 'requirements.txt'. If you have none, you may skip this.|
|
||||
| branch | :white_check_mark: | - | The specific branch you want to merge into. Use ${{ github.head_ref }} if you want to use this with pull requests.|
|
||||
| commit_message | :x: | 'Adjusted files for PEP-8 compliance' | Custom git commit message |
|
||||
| commit_options | :x: | - | Custom git commit options |
|
||||
| file_pattern | :x: | '*' | Custom file pattern for `git add` |
|
||||
| checkpath | :x: | '.' | The path autopep8 checks |
|
||||
| options | :x: | ' ' | Parameters to use with autopep8 |
|
||||
| dry | :x: | false | Dry-run the action to fail when detecting PEP-8 uncompliant files, instead of automatically fixing them. |
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
This is a simple usage example of this script:
|
||||
|
||||
```
|
||||
name: Autopep 8
|
||||
```yaml
|
||||
# This action works with pull requests and pushes
|
||||
name: Continuous Integration
|
||||
|
||||
on: [pull_request]
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 1
|
||||
# Make sure the actual branch is checked out when running on pull requests
|
||||
ref: ${{ github.head_ref }}
|
||||
- uses: creyD/action_autopep8@master
|
||||
with:
|
||||
dependencies: 'requirements.txt'
|
||||
branch: ${{ github.head_ref }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -42,7 +47,7 @@ jobs:
|
||||
|
||||
## Issues
|
||||
|
||||
Please report all bugs and feature request using the [GitHub issues function](https://github.com/creyD/action_autopep8/issues/new).
|
||||
Please report all bugs and feature request using the [GitHub issues function](https://github.com/creyD/autopep8_action/issues/new).
|
||||
|
||||
## Special Thanks
|
||||
|
||||
|
||||
29
action.yml
29
action.yml
@@ -1,5 +1,5 @@
|
||||
name: 'Autopep8 Action'
|
||||
description: 'Automatically runs the autopep8 command against any commit/ pull request created.'
|
||||
name: Autopep8 Action
|
||||
description: Automatically runs the autopep8 command on all your changes.
|
||||
|
||||
author: Conrad Großer <grosserconrad@gmail.com>
|
||||
|
||||
@@ -12,26 +12,25 @@ inputs:
|
||||
description: Commit options
|
||||
required: false
|
||||
file_pattern:
|
||||
description: File pattern used for "git add"
|
||||
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.
|
||||
checkpath:
|
||||
description: Path autopep8 checks
|
||||
required: false
|
||||
default: 'false'
|
||||
branch:
|
||||
description: Branch which the changes are merged to
|
||||
required: true
|
||||
default: '.'
|
||||
options:
|
||||
description: Parameters for autopep8
|
||||
required: false
|
||||
default: ''
|
||||
dry:
|
||||
description: Should this script apply autopep8 directly or just warn?
|
||||
required: false
|
||||
default: false
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.commit_message }}
|
||||
- ${{ inputs.commit_options }}
|
||||
- ${{ inputs.file_pattern }}
|
||||
- ${{ inputs.dependencies }}
|
||||
- ${{ inputs.branch }}
|
||||
|
||||
branding:
|
||||
icon: 'fast-forward'
|
||||
|
||||
67
entrypoint.sh
Normal file → Executable file
67
entrypoint.sh
Normal file → Executable file
@@ -1,50 +1,49 @@
|
||||
#!/bin/sh -l
|
||||
|
||||
#!/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
|
||||
|
||||
# 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)
|
||||
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
|
||||
_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"
|
||||
git config --global user.name "GitHub Action"
|
||||
}
|
||||
|
||||
echo "Installing dependencies..."
|
||||
pip install --upgrade pip
|
||||
# Install dependencies
|
||||
pip install autopep8
|
||||
# Checks if any files are changed
|
||||
_git_changed() {
|
||||
[[ -n "$(git status -s)" ]]
|
||||
}
|
||||
|
||||
# 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 .
|
||||
autopep8 -i -r $INPUT_CHECKPATH $INPUT_OPTIONS || echo "Problem running autopep8!"
|
||||
|
||||
if ! git diff --quiet
|
||||
if _git_changed;
|
||||
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"
|
||||
if $INPUT_DRY; then
|
||||
echo "Found non-compliant files!"
|
||||
exit 1
|
||||
else
|
||||
# Calling method to configure the git environemnt
|
||||
_git_setup
|
||||
echo "Commiting and pushing changes..."
|
||||
# Add changes to git
|
||||
git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${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 origin
|
||||
echo "Changes pushed successfully."
|
||||
fi
|
||||
else
|
||||
echo "Nothing to commit. Exiting."
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user