Skip to content

Commit

Permalink
[#35] Feature: Add ruff check on circleci (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-regis authored Sep 13, 2023
2 parents 7f52f81 + ce1474b commit ed8d9a3
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 295 deletions.
150 changes: 139 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,149 @@
version: 2.1

workflows:
build-deploy:
jobs:
- build
- approval:
type: approval
requires:
- build
orbs:
python: circleci/python@2.1.1

executors:
app-executor:
docker:
- image: cimg/python:3.11
# @ 13-Sep-23:
# ubuntu 22.04.2 LTS | python3 3.11.5 | poetry 1.6.1
working_directory: ~/app

aliases:
- &install-dependencies
run:
name: Install dependencies
command: poetry install

- &install-dev-dependencies
run:
name: Install dev dependencies
command: poetry install --only dev

- &install-test-dependencies
run:
name: Install test dependencies
command: poetry install --only test

- &build-project
run:
name: Build Project
command: poetry install

jobs:
requirements:
executor: app-executor
steps:
- checkout
- python/install-packages:
pkg-manager: poetry
- run:
name: Requirements check
command: |
python -V
poetry -V
lint:
# executor: app-executor
executor: &python-executor
name: python/default
tag: "3.11"
steps:
- checkout
- *install-dev-dependencies
- run: &git-diff-py-files
name: List added, copied, modified, and renamed *py files
command: git diff --name-only --diff-filter=ACMR origin/main | grep -E "(.py$)" > diff.txt || true
- run:
name: Ruff linting
command: poetry run ruff check --config=pyproject.toml . &> lint_checks.txt || true
- run:
name: Diff-based ruff
command: &display-lint-errors |
grep -Ff diff.txt lint_checks.txt > lint_errors.txt || true
if [ -s lint_errors.txt ]; then
cat lint_errors.txt
printf 'Run the following command to fix your branch:\n make fixes'
exit 1
fi

format:
# executor: app-executor
executor: *python-executor
steps:
- checkout
- *install-dev-dependencies
- run: *git-diff-py-files
- run:
name: Black style formatting
command: |
python -V
poetry -V
poetry run black . --check --diff --color --config=pyproject.toml &> lint_checks.txt || true
- run:
name: Diff-based black
command: *display-lint-errors

test:
# executor: app-executor
executor: *python-executor
steps:
- checkout
- python/install-packages:
pkg-manager: poetry
- run:
name: Unit testing
command: |
python -V
poetry -V
build:
docker:
- image: cimg/python:3.11.5
executor: app-executor
steps:
- checkout
- *install-dependencies
- run:
name: Ruff linting and Black formatting
name: Build
command: |
python -V
poetry -V
workflows:
ci:
jobs:
- requirements:
name: Validate requirements
filters: &ci-filter
branches:
ignore: main
tags:
ignore: /.*/

- lint:
name: Ruff linting
filters: *ci-filter
requires:
- Validate requirements

- format:
name: Black formatting
filters: *ci-filter
requires:
- Validate requirements

- test:
name: Unit testing
filters: *ci-filter
requires:
- Ruff linting
- Black formatting

build:
jobs:
- build
- approval:
type: approval
requires:
- build
14 changes: 10 additions & 4 deletions .github/workflows/auto-assign.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
name: Auto Assign Issues and PRs
name: assign issues and prs

on:
issues:
types: [opened]
pull_request:
types: [opened]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSIGNEE: ${{ vars.DEFAULT_ISSUE_ASSIGNEE }}

jobs:
auto-assign:
auto_assign:
runs-on: ubuntu-latest
permissions:
issues: write
Expand All @@ -14,5 +20,5 @@ jobs:
- uses: pozil/auto-assign-issue@v1
with:
abortIfPreviousAssignees: true
repo-token: ${{ secrets.GITHUB_TOKEN }}
assignees: ${{ vars.DEFAULT_ISSUE_ASSIGNEE }}
repo-token: GITHUB_TOKEN
assignees: ASSIGNEE
13 changes: 8 additions & 5 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
name: Bump version
name: bump version

on:
push:
branches:
- master
- main

env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

jobs:
bump-version:
bump_version:
if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }}
runs-on: ubuntu-latest
name: "Bump version and create changelog with commitizen"
steps:
- name: Check out
uses: actions/checkout@v3
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
token: PERSONAL_ACCESS_TOKEN
fetch-depth: 0
- name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
github_token: PERSONAL_ACCESS_TOKEN

111 changes: 84 additions & 27 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,98 @@
name: CI
on:
pull_request:
push:
branches-ignore: main
name: ci

on: [push, pull_request]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
lint-ruff:
requirements:
# Ubunty latest @ 13-Sep-23:
# Ubuntu 22.04.3 LTS | Python 3.10.12 | Pipx 1.2.0 | No poetry | PostgreSQL 14.9
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: python -m pipx install poetry
- name: Set up Python version from Poetry config
uses: actions/setup-python@v4
with:
python-version-file: 'pyproject.toml'
cache: 'poetry' # caching poetry dependencies
# Warning: poetry cache is not found
- name: Requirements check
run: poetry install --no-interaction

lint:
runs-on: ubuntu-latest
needs: [requirements]
steps:
- uses: actions/checkout@v3
# - name: Set up Python 3.11
# uses: actions/setup-python@v4
# with:
# python-version: 3.11
- uses: actions/checkout@v4
- run: python -m pipx install poetry
- name: Set up Python version from Poetry config
uses: actions/setup-python@v4
with:
python-version-file: 'pyproject.toml'
cache: 'poetry' # caching poetry dependencies
# Warning: poetry cache is not found
- run: poetry install --only dev --no-interaction
- name: Ruff linting
uses: chartboost/ruff-action@v1
with:
args: check --config=pyproject.toml --verbose
# run: |
# python -m pip install --upgrade pip
# python -m pip install poetry
# poetry install
check-black:
args: --config=pyproject.toml

format:
runs-on: ubuntu-latest
needs: [requirements]
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
- uses: actions/checkout@v4
- run: python -m pipx install poetry
- name: Set up Python version from Poetry config
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Black formatting
python-version-file: 'pyproject.toml'
cache: 'poetry' # caching poetry dependencies
# Warning: poetry cache is not found
- run: poetry install --only dev --no-interaction
- name: Black style formatting
uses: psf/black@stable
with:
options: --color --config=pyproject.toml --verbose
# run: |
# python -m pip install --upgrade pip
# python -m pip install poetry
# poetry install --only dev
# poetry run black .
options: --check --diff --color --config=pyproject.toml
# env:
# CHANGED_FILES: ${{ steps.file_changes.outputs.added_modified }}

test:
runs-on: ubuntu-latest
needs: [lint, format]
steps:
- uses: actions/checkout@v4
- run: python -m pipx install poetry
- name: Set up Python version from Poetry config
uses: actions/setup-python@v4
with:
python-version-file: 'pyproject.toml'
cache: 'poetry' # caching poetry dependencies
# Warning: poetry cache is not found
- run: poetry install --only dev --no-interaction
- name: Unit testing
run: |
python -V
poetry -V
# poetry run pytest
build:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4
- run: python -m pipx install poetry
- name: Set up Python version from Poetry config
uses: actions/setup-python@v4
with:
python-version-file: 'pyproject.toml'
cache: 'poetry' # caching poetry dependencies
# Warning: poetry cache is not found
- run: poetry install
- name: Build
run: |
python -V
poetry -V
20 changes: 12 additions & 8 deletions .github/workflows/pr-on-push.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Create or update a pull request on push
on:
push:
branches-ignore:
- main
name: pull request on push

on: [push]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSIGNEE: ${{ vars.DEFAULT_ISSUE_ASSIGNEE }}
REVIEWER: ${{ vars.DEFAULT_PR_REVIEWER }}

jobs:
create_pull_request:
runs-on: ubuntu-latest
Expand All @@ -12,12 +16,12 @@ jobs:
id: open-pr
uses: devops-infra/action-pull-request@v0.5.5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: GITHUB_TOKEN
target_branch: main
title: "[#] <Feature>: PLACEHOLDER TITLE"
template: ".github/PULL_REQUEST_TEMPLATE.md"
reviewer: ${{ vars.DEFAULT_PR_REVIEWER }}
assignee: ${{ vars.DEFAULT_PR_ASSIGNEE }}
reviewer: REVIEWER
assignee: ASSIGNEE
draft: true
#label: "auto-pr" # Comma-separated list (no spaces)
#milestone: "Milestone 1" # Milestone name
Expand Down
Loading

0 comments on commit ed8d9a3

Please sign in to comment.