Merge pull request #1 from creyD/dev

Feature Upgrade
This commit is contained in:
2020-05-06 13:46:58 +02:00
committed by GitHub
4 changed files with 65 additions and 65 deletions

View File

@@ -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 COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -8,35 +8,38 @@ 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.|
| 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. |
| checkpath | :x: | '.' | The path autopep8 checks | | checkpath | :x: | '.' | The path autopep8 checks |
| autoparameters | :x: | ' ' | Parameters to use with autopep8 | | 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 ### 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@v2
with: 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 - uses: creyD/action_autopep8@master
with:
dependencies: 'requirements.txt'
branch: ${{ github.head_ref }}
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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,36 +12,25 @@ 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:
description: Path for the repositories 'requirements.txt'. If you have none, you may skip this.
required: false
default: 'requirements.txt'
branch:
description: Branch which the changes are merged to
required: true
checkpath: checkpath:
description: Path autopep8 checks description: Path autopep8 checks
required: false required: false
default: '.' default: '.'
autoparameters: options:
description: Parameters for autopep8 description: Parameters for autopep8
required: false required: false
default: '' default: ''
dry:
description: Should this script apply autopep8 directly or just warn?
required: false
default: false
runs: runs:
using: 'docker' using: 'docker'
image: 'Dockerfile' image: 'Dockerfile'
args:
- ${{ inputs.commit_message }}
- ${{ inputs.commit_options }}
- ${{ inputs.file_pattern }}
- ${{ inputs.dependencies }}
- ${{ inputs.branch }}
- ${{ inputs.checkpath }}
- ${{ inputs.autoparameters }}
branding: branding:
icon: 'fast-forward' icon: 'fast-forward'

View File

@@ -1,47 +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 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) # 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
pip install -r $INPUT_DEPENDENCIES || echo "No dependency file found."
# Apply PEP 8
echo "Running autopep8..." echo "Running autopep8..."
autopep8 -i -r $INPUT_CHECKPATH $INPUT_AUTOPARAMETERS || echo "Problem running autopep8!" autopep8 -i -r $INPUT_CHECKPATH $INPUT_OPTIONS || echo "Problem running autopep8!"
if ! git diff --quiet 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 exit 1
# Switch to the actual branch else
git checkout $INPUT_BRANCH # Calling method to configure the git environemnt
_git_setup
git add "${INPUT_FILE_PATTERN}" echo "Commiting and pushing changes..."
# Add changes to git
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}"
git push --set-upstream origin "HEAD:$INPUT_BRANCH" # 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