35 Commits
v1.1 ... master

Author SHA1 Message Date
bd58fcf50d Fixed a bug with the action path 2023-05-24 11:21:35 +02:00
8595edd403 Removed i and r default options from autopep 2023-05-24 10:50:35 +02:00
191697834d Minor Cleanup 2023-05-24 10:45:37 +02:00
6995413f33 Changed action to be based on python docker 2023-05-24 10:37:49 +02:00
b94a3d0b2b Added default github token 2023-05-24 10:37:37 +02:00
fc2267b495 Adjusted pip commands for Python 3 2022-09-28 00:09:22 +02:00
3b42b54814 Updated to Python 3 2022-09-28 00:08:11 +02:00
d36ec0e312 Added no_commit option 2022-01-04 16:06:43 +01:00
18f406b1d0 Merge pull request #1 from creyD/dev
Feature Upgrade
2020-05-06 13:46:58 +02:00
6b39f1b281 Added explicit shebang to bash script 2020-05-06 13:46:30 +02:00
f515b34fb6 Removed apk upgrade from the dockerfile 2020-05-06 13:44:57 +02:00
60ab91e841 Switched off explicit mode 2020-05-06 13:42:02 +02:00
0982f18fb5 Used alpine docker image instead of python 2020-05-06 12:47:49 +02:00
5d9e84c500 Added debug parameter 2020-05-06 12:40:33 +02:00
3f07e64ccb Removed -l command from the shebang 2020-05-06 12:34:50 +02:00
c8d9e2fc74 Fixed the git status bug 2020-05-06 12:30:39 +02:00
4449ec2f27 Removed install commands from sh 2020-05-06 10:52:19 +02:00
fe6126ea98 Moved install commands to docker file 2020-05-06 10:49:14 +02:00
308fd515a8 Tried to fix permission problem 2020-05-06 10:42:09 +02:00
faaac4d215 Fixed git status call 2020-05-06 10:39:52 +02:00
d4eb464ac0 Update entrypoint.sh 2020-05-06 10:37:15 +02:00
daa4e6b569 Moved git changed out of the function 2020-05-06 10:33:18 +02:00
a51a186977 Fixed a bug with function names 2020-05-06 10:29:22 +02:00
ded507f15f Adjusted function blocks 2020-05-06 10:25:44 +02:00
e658219e54 Updated docs 2020-05-06 10:15:41 +02:00
6271ffc1c4 Removed dependencies parameter 2020-05-06 10:15:04 +02:00
2a43a06c54 Minor Cleanup 2020-05-06 10:14:42 +02:00
90bfa73dca Renamed autoparameters to options 2020-05-06 10:14:06 +02:00
8fa1e16ff1 Removed branch parameter 2020-05-06 10:13:24 +02:00
552eff98a5 Added dry run parameter 2020-05-06 10:12:17 +02:00
8994743494 Updated link 2019-11-18 12:27:28 +01:00
f84db99f70 Bugfix for autoparameter issue 2019-11-17 23:58:59 +01:00
4a8632c121 Fixed a bug where autopep8 parameters weren't noticed 2019-11-17 23:53:00 +01:00
4db3b98ca0 Fixed Readme Parameters 2019-11-15 09:41:03 +01:00
08c429cdb4 Added Custom Checkpath and Parameters Options 2019-11-15 09:38:54 +01:00
5 changed files with 110 additions and 65 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
# MacOS system files
.DS_Store

View File

@@ -1,3 +1,9 @@
FROM python:3 FROM python:3.11.3-slim-bullseye
RUN apt update && apt install -y --no-install-recommends git
RUN pip install --no-cache-dir -q --upgrade pip
RUN pip install --no-cache-dir -q autopep8
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -1,50 +1,66 @@
# GitHub autopep8 Action # GitHub autopep8 Action
This action uses the newly released GitHub action to automatically restyle your Python code according to [PEP-8](https://www.python.org/dev/peps/pep-0008/) using [autopep8](https://github.com/hhatto/autopep8). [![License MIT](https://img.shields.io/github/license/creyD/autopep8_action)](https://github.com/creyD/autopep8_action/blob/master/LICENSE)
[![Latest Release](https://img.shields.io/github/v/release/creyD/autopep8_action)](https://github.com/creyD/autopep8_action/releases)
[![Contributors](https://img.shields.io/github/contributors-anon/creyD/autopep8_action)](https://github.com/creyD/autopep8_action/graphs/contributors)
[![Issues](https://img.shields.io/github/issues/creyD/autopep8_action)](https://github.com/creyD/autopep8_action/issues)
This action automatically restyles Python code according to [PEP-8](https://www.python.org/dev/peps/pep-0008/) using [autopep8](https://github.com/hhatto/autopep8).
## Usage ## Usage
### Parameters ### Parameters
The following parameters can be used in your custom action configuration. The following parameters can be used in your custom action configuration.
| Parameter | Required | Default | Description | | Parameter | Required | Default | Description |
| - | - | - | - | | - | - | - | - |
| commit_message | :x: | 'Adjusted files for PEP-8 compliance' | Custom git commit message| | commit_message | :x: | 'Adjusted files for PEP-8 compliance' | Custom git commit message |
| commit_options | :x: | '*' | Custom git commit options| | commit_options | :x: | - | Custom git commit options |
| file_pattern | :x: | '.' | Custom file pattern for `git add`| | file_pattern | :x: | '*' | Custom file pattern for `git add` |
| dependencies | :x: | 'requirements.txt' | Path for the repositories 'requirements.txt'. If you have none, you may skip this.| | checkpath | :x: | '.' | The path autopep8 checks |
| 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.| | no_commit | :x: | False | Avoid committing, if used in a pipeline |
| 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. |
| github_token | :x: | `${{ github.token }}` | The default [GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret) or a [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token)
> Note: using the same_commit option may lead to problems if other actions are relying on the commit being the same before and after the prettier action has ran. Keep this in mind.
### Example ### Example
This is a simple usage example of this script: This is a simple usage example of this script:
``` ```yaml
name: Autopep 8 # This action works with pull requests and pushes
name: Continuous Integration
on: [pull_request] on:
pull_request:
push:
branches:
- master
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v3
with: with:
fetch-depth: 1 # Make sure the actual branch is checked out when running on pull requests
- uses: creyD/action_autopep8@master ref: ${{ github.head_ref }}
with: - uses: creyD/action_autopep8@v3.1
dependencies: 'requirements.txt'
branch: ${{ github.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
``` ```
More documentation for writing a workflow can be found [here](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions).
## Issues ## 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 ## Special Thanks
- Hideo Hattori [(GitHub)](https://github.com/hhatto) for creating and maintaining autopep8 - Hideo Hattori [(GitHub)](https://github.com/hhatto) for creating and maintaining autopep8
- Stefan Zweifel [(GitHub)](https://github.com/stefanzweifel) for providing an action to commit and push a git change - Stefan Zweifel [(GitHub)](https://github.com/stefanzweifel) for providing an action to commit and push a git change
If you want you may also use my [autoflake](https://github.com/creyD/autoflake_action) and [prettier](https://github.com/creyD/prettier_action) GitHub actions.

View File

@@ -1,5 +1,5 @@
name: 'Autopep8 Action' name: Autopep8 Action
description: 'Automatically runs the autopep8 command against any commit/ pull request created.' description: Automatically runs the autopep8 command on all your changes.
author: Conrad Großer <grosserconrad@gmail.com> author: Conrad Großer <grosserconrad@gmail.com>
@@ -12,26 +12,33 @@ inputs:
description: Commit options description: Commit options
required: false required: false
file_pattern: file_pattern:
description: File pattern used for "git add" description: File pattern used for `git add`
required: false required: false
default: '*' default: '*'
dependencies: checkpath:
description: Path for the repositories 'requirements.txt'. If you have none, you may skip this. description: Path autopep8 checks
required: false required: false
default: 'requirements.txt' default: '.'
branch: options:
description: Branch which the changes are merged to description: Parameters for autopep8
required: true required: false
default: ''
dry:
description: Should this script apply autopep8 directly or just warn?
required: false
default: false
no_commit:
description: Can be used to avoid committing the changes
required: false
default: false
github_token:
description: GitHub Token or PAT token used to authenticate against a repository
required: false
default: ${{ github.token }}
runs: runs:
using: 'docker' using: 'docker'
image: 'Dockerfile' image: 'Dockerfile'
args:
- ${{ inputs.commit_message }}
- ${{ inputs.commit_options }}
- ${{ inputs.file_pattern }}
- ${{ inputs.dependencies }}
- ${{ inputs.branch }}
branding: branding:
icon: 'fast-forward' icon: 'fast-forward'

View File

@@ -1,47 +1,61 @@
#!/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 set -eu
shopt -s globstar
# 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) # 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 ( ) { _git_setup() {
cat <<- EOF > $HOME/.netrc cat <<- EOF > $HOME/.netrc
machine github.com machine github.com
login $GITHUB_ACTOR login $GITHUB_ACTOR
password $GITHUB_TOKEN password $GITHUB_TOKEN
machine api.github.com machine api.github.com
login $GITHUB_ACTOR login $GITHUB_ACTOR
password $GITHUB_TOKEN password $GITHUB_TOKEN
EOF EOF
chmod 600 $HOME/.netrc chmod 600 $HOME/.netrc
git config --global user.email "actions@github.com" 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..." # Checks if any files are changed
pip install -q --upgrade pip _git_changed() {
# Install dependencies [[ -n "$(git status -s)" ]]
pip install -q autopep8 }
# Install custom project dependencies if applicable _git_changes() {
pip install -r $INPUT_DEPENDENCIES || echo "No dependency file found." git diff
}
# Apply PEP 8 # PROGRAM
echo "Running autopep8..." echo "Running autopep8..."
autopep8 --in-place -r . || echo "Problem running autopep8." autopep8 $INPUT_CHECKPATH $INPUT_OPTIONS || echo "Problem running autopep8!"
if ! git diff --quiet if $INPUT_NO_COMMIT; then
exit 0
fi
if _git_changed;
then then
echo "Commiting and pushing changes." if $INPUT_DRY; then
# Calling method to configure the git environemnt echo "Found non-compliant files:"
git_setup _git_changes
# Switch to the actual branch echo "Finishing dry-run. Exiting before committing."
git checkout $INPUT_BRANCH exit 1
else
git add "${INPUT_FILE_PATTERN}" # Calling method to configure the git environemnt
_git_setup
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} echo "Commiting and pushing changes..."
git push --set-upstream origin "HEAD:$INPUT_BRANCH" # 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 else
echo "Nothing to commit. Exiting." echo "Nothing to commit. Exiting."
fi fi