forked from asetalias/amibot-tg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request asetalias#116 from Vyogami/ci/linting-formating
- Loading branch information
Showing
8 changed files
with
343 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: "setup-poetry-env" | ||
description: "Composite action to setup the Python and poetry environment." | ||
|
||
inputs: | ||
python-version: | ||
required: false | ||
description: "The python version to use" | ||
default: "3.11" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Set up python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
|
||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
virtualenvs-in-project: true | ||
|
||
- name: Load cached venv | ||
id: cached-poetry-dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }} | ||
|
||
- name: Install dependencies | ||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | ||
run: poetry install --no-interaction | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Main | ||
|
||
on: | ||
push: | ||
branches: | ||
- "*" | ||
pull_request: | ||
types: [opened, synchronize, reopened, ready_for_review] | ||
|
||
jobs: | ||
quality: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out | ||
uses: actions/checkout@v3 | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pre-commit | ||
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} | ||
|
||
- name: Set up the environment | ||
uses: ./.github/actions/setup-poetry-env | ||
|
||
- name: Run checks | ||
run: make check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
exclude: ^gen/ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: "v4.4.0" | ||
hooks: | ||
- id: check-case-conflict | ||
- id: check-merge-conflict | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: "v0.1.6" | ||
hooks: | ||
- id: ruff | ||
args: [--exit-non-zero-on-fix] | ||
- id: ruff-format | ||
|
||
- repo: https://github.com/pre-commit/mirrors-prettier | ||
rev: "v3.0.3" | ||
hooks: | ||
- id: prettier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
gen: | ||
rm -f gen/*.py; cd proto; buf generate; cd ... | ||
|
||
mongo: | ||
docker run -d --name py-mongo -p 27017:27017 mongo | ||
|
||
dev: | ||
poetry run nodemon --no-colors --exec python main.py | ||
install: ## Install dependencies and pre-commit hooks + setup virtual environment. | ||
@echo "🚀 Creating virtual environment using pyenv and poetry" | ||
@poetry install | ||
@poetry run pre-commit install | ||
@poetry shell | ||
|
||
env: | ||
poetry shell | ||
|
||
docker: | ||
docker build -t py-amibot . | ||
gen: ## Generate proto buffs. | ||
rm -f gen/*.py; cd proto; buf generate; cd ... | ||
|
||
dockerRun: | ||
docker run -d --name py-amibot -p 3333:3333 py-amibot | ||
mongo: ## Run mongodb server in docker. | ||
docker run -d --name py-mongo -p 27017:27017 mongo | ||
|
||
lint: | ||
poetry run ruff check **/*.py | ||
dev: ## Run amibot server | ||
poetry run nodemon --no-colors --exec python main.py | ||
|
||
format: | ||
poetry run ruff format **/*.py | ||
docker: ## Builds the docker image for amibot server. | ||
@docker build -t py-amibot . | ||
|
||
.PHONY: gen, mongo, dev, env, docker, dockerRun | ||
dockerRun: ## Runs the amibot server in docker. | ||
@docker run -d --name py-amibot -p 3333:3333 py-amibot | ||
|
||
check: ## Run code quality tools. | ||
@echo "🚀 Checking Poetry lock file consistency with 'pyproject.toml': Running poetry lock --check" | ||
@poetry check --lock | ||
@echo "🚀 Linting code: Running pre-commit" | ||
@poetry run pre-commit run -a | ||
|
||
help: ## List available targets with respective description. | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
|
||
.PHONY: gen, mongo, dev, env, docker, dockerRun, install, check, help | ||
.DEFAULT_GOAL := help |
Oops, something went wrong.