mirror of
https://github.com/creyD/autoflake_action.git
synced 2026-04-14 12:30:29 +02:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a60e88f40 | |||
| 68f07553f9 | |||
| 55de1ca890 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# MacOS system files
|
||||||
|
.DS_Store
|
||||||
3
CODE_OF_CONDUCT.md
Normal file
3
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Code of Conduct
|
||||||
|
|
||||||
|
Be excellent to each other.
|
||||||
19
README.md
19
README.md
@@ -1,5 +1,10 @@
|
|||||||
# GitHub autoflake Action
|
# GitHub autoflake Action
|
||||||
|
|
||||||
|
[](https://github.com/creyD/autoflake_action/blob/master/LICENSE)
|
||||||
|
[](https://github.com/creyD/autoflake_action/releases)
|
||||||
|
[](https://github.com/creyD/autoflake_action/graphs/contributors)
|
||||||
|
[](https://github.com/creyD/autoflake_action/issues)
|
||||||
|
|
||||||
This GitHub action automatically removes unused imports and variables from your Python code using [autoflake](https://pypi.org/project/autoflake/).
|
This GitHub action automatically removes unused imports and variables from your Python code using [autoflake](https://pypi.org/project/autoflake/).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -15,15 +20,16 @@ The following parameters can be used in your custom action configuration.
|
|||||||
| no_commit | :x: | False | Avoid committing, if used in a pipeline |
|
| no_commit | :x: | False | Avoid committing, if used in a pipeline |
|
||||||
| options | :x: | ' ' | Parameters to use with autoflake |
|
| options | :x: | ' ' | Parameters to use with autoflake |
|
||||||
| dry | :x: | false | Dry-run the action to fail when detecting uncompliant files, instead of automatically fixing them. |
|
| dry | :x: | false | Dry-run the action to fail when detecting 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
|
```yaml
|
||||||
# This action works with pull requests and pushes
|
name: autoflake format
|
||||||
name: Continuous Integration
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -37,12 +43,13 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: creyD/autoflake_action@master
|
- uses: creyD/autoflake_action@v1.1
|
||||||
env:
|
with:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
options: --in-place --remove-all-unused-imports -r
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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/autoflake_action/issues/new).
|
Please report all bugs and feature request using the [GitHub issues function](https://github.com/creyD/autoflake_action/issues/new).
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ inputs:
|
|||||||
description: Can be used to avoid committing the changes
|
description: Can be used to avoid committing the changes
|
||||||
required: false
|
required: false
|
||||||
default: 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'
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set
|
# 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
|
# x would be for showing the commands before they are executed
|
||||||
set -eu
|
set -eu
|
||||||
|
shopt -s globstar
|
||||||
|
|
||||||
# FUNCTIONS
|
# 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)
|
||||||
@@ -25,6 +26,10 @@ _git_changed() {
|
|||||||
[[ -n "$(git status -s)" ]]
|
[[ -n "$(git status -s)" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_git_changes() {
|
||||||
|
git diff
|
||||||
|
}
|
||||||
|
|
||||||
git config --global --add safe.directory /github/workspace
|
git config --global --add safe.directory /github/workspace
|
||||||
|
|
||||||
echo "Running autoflake..."
|
echo "Running autoflake..."
|
||||||
@@ -37,7 +42,9 @@ fi
|
|||||||
if _git_changed;
|
if _git_changed;
|
||||||
then
|
then
|
||||||
if $INPUT_DRY; then
|
if $INPUT_DRY; then
|
||||||
echo "Found non-compliant files!"
|
echo "Unpretty Files Changes:"
|
||||||
|
_git_changes
|
||||||
|
echo "Finishing dry-run. Exiting before committing."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Calling method to configure the git environemnt
|
# Calling method to configure the git environemnt
|
||||||
|
|||||||
Reference in New Issue
Block a user