Skip to content

Commit

Permalink
Add support for running the action locally and linting py files (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jashparekh authored Dec 4, 2021
1 parent bf465c6 commit c2e7a41
Show file tree
Hide file tree
Showing 19 changed files with 505 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .bandit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bandit]
exclude: *venv*,*env*,*scratch*
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
max-line-length = 88
max-complexity = 8
ignore = W503,E501
builtins = unicode
tee = True
exclude = venv,env,.venv,scratch
14 changes: 14 additions & 0 deletions .github/actions/install-dependencies/action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set -euo pipefail

echo "Ensuring pip is up to date"
python -m pip install --upgrade pip

if [[ "${INSTALL_REQUIREMENTS}" == "true" ]]; then
echo "Installing code requirements"
pip install -r requirements.lock
fi

if [[ "${INSTALL_TEST_REQUIREMENTS}" == "true" ]]; then
echo "Installing test requirements"
pip install -r requirements-test.txt
fi
20 changes: 20 additions & 0 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Install Dependencies"
description: "Install Python dependencies"
inputs:
requirements:
description: "Should requirements.lock be installed"
default: "false"
required: false
test-requirements:
description: "Should requirements-test.txt be installed"
default: "false"
required: false
runs:
using: "composite"
steps:
- name: "Install Python dependencies"
run: "$GITHUB_ACTION_PATH/action.sh"
shell: "bash"
env:
INSTALL_REQUIREMENTS: ${{ inputs.requirements }}
INSTALL_TEST_REQUIREMENTS: ${{ inputs.test-requirements }}
3 changes: 0 additions & 3 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ jobs:
uses: actions/checkout@v2
- name: Mypy Lint
uses: ./ # Uses an action in the root directory
with:
mypy_version: '0.901'
mypy_flags: '--verbose'
91 changes: 91 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: "Lint"
on:
pull_request: {}
push:
branches: ["main"]

env:
PYTHON_VERSION: "3.10"

jobs:

bandit:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
test-requirements: "true"

- name: Run bandit
run: bandit --ini .bandit -r github.py

black:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/[email protected]
- name: Set up Python
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
test-requirements: "true"

- name: Run black
run: black --check github.py

flake8:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
test-requirements: "true"

- name: Run flake8
run: flake8 github.py

isort:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
test-requirements: "true"

- name: Run isort
run: isort --recursive --check-only github.py

mypy:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
test-requirements: "true"

- name: Run mypy
run: mypy github.py
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v1] - 2021-09-12

### Added

- Initial Release
126 changes: 126 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement by contacting [a
project maintainer][maintainers].
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[maintainers]: MAINTAINERS.md
[homepage]: https://www.contributor-covenant.org
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contributing

When contributing to this repository, please first discuss the change you wish to make via issue before making a change.

Please note we have a [code of conduct](CODE_OF_CONDUCT.md), please follow it in all your interactions with the project.

## Pull Request Process

1. Ensure the CI pipeline and all checks are passing.
2. Update documentation with details of changes.
3. Add an entry to the [change log](CHANGELOG.md).
4. You may merge the Pull Request in once it has approvals of two other developers. If you do not have permission to do
that, you may request the second reviewer to merge it for you.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM python:3.10-alpine
LABEL "maintainer"="Jash Parekh <[email protected]>"

ADD entrypoint.sh /entrypoint.sh
ADD github.py /github.py

RUN apk add bash gcc musl-dev

Expand Down
3 changes: 3 additions & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Maintainers

* Jash Parekh - me [at] jashparekh.com
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
# mypy-action
# Mypy Github Action

GitHub Action for [mypy](https://mypy.readthedocs.io/en/master/).

Influenced by [jpetrucciani/mypy-check](https://github.com/jpetrucciani/mypy-check).

### Simple

```yaml
name: "Mypy"
on:
pull_request: {}
push:
branches: ["main"]

jobs:
deploy_schemas:
runs-on: ubuntu-latest
name: Mypy
steps:
# To use this repository's private action,
# you must check out the repository
- name: Checkout
uses: actions/checkout@v2
- name: Deploy schemas to BigQuery
uses: jashparekh/mypy-action@v2
with:
path: '.'
mypy_version: '0.910'
mypy_flags: '--verbose'
```
## Configuration
### `path` (optional, string)

File or directory to run mypy on.

Default: `.`

### `mypy_version` (optional, string)

Version of mypy library to use for linting.

Default: `0.910`

### `mypy_config_file` (optional, string)

Location of mypy config file in the repository.

Default: `mypy.ini`

### `mypy_flags` (optional, string)

Optional mypy flags (refer to `mypy --help`)

Default: `mypy.ini`
10 changes: 8 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
version: '3.5'

services:
devbox:
devbox: &devbox
build:
dockerfile: "./Dockerfile"
dockerfile: "./docker/devbox.dockerfile"
context: "."
stdin_open: "true" # docker run -i
tty: "true" # docker run -t
command: /bin/bash
volumes:
- "./:/app"

# run all the linting locally
# - black & isort will format code to address issues
lint:
<<: *devbox
command: "docker/run_linting.sh --format-code"

volumes:
home:
env:
Expand Down
Loading

0 comments on commit c2e7a41

Please sign in to comment.