Skip to content

Commit

Permalink
👷🏻 ci: implement code formatting pipeline
Browse files Browse the repository at this point in the history
Refs: DEVTOOL-22
  • Loading branch information
adriamontoto committed Jul 20, 2024
1 parent 7a578c6 commit 45ca1f0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Format Pipeline

permissions:
contents: write

on:
push:
branches:
- master
- develop
pull_request:
types:
- opened
- synchronize

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.11]
timeout-minutes: 15
steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Only last commit

- name: 🐍 Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- id: cache
name: 📦 Create cache
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'requirements.txt', 'requirements_dev.txt') }}

- name: 📦 Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
pip install -r requirements_dev.txt --no-warn-script-location --no-python-version-warning --no-warn-conflicts
- name: 🏃 Run Formatter
run: bash scripts/format.sh

- name: 📤 Commit & Push Changes
run: |
if ! git diff-index --quiet HEAD --; then
git config --global user.name "Formatter Action"
git config --global user.email "formatter@github.com"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git add .
git commit -m "🔨 refactor: run automatic formatter"
git push origin HEAD:${{ github.ref }}
fi
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pytest-cov==5.0.0 # https://pytest-cov.readthedocs.io/en/latest/
pytest-xdist[psutil]==3.6.1 # https://pytest-xdist.readthedocs.io/en/stable/
pytest-asyncio==0.23.7 # https://pytest-asyncio.readthedocs.io/en/latest/
pytest-randomly==3.15.0 # https://github.com/pytest-dev/pytest-randomly
ruff==0.5.1 # https://docs.astral.sh/ruff/
7 changes: 7 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh -e
set -x

wget https://raw.githubusercontent.com/adriamontoto/dotfiles/master/python/ruff.toml --output-document /tmp/ruff.toml

ruff check developing_tools tests --fix-only --config /tmp/ruff.toml
ruff format developing_tools tests --config /tmp/ruff.toml

0 comments on commit 45ca1f0

Please sign in to comment.