Skip to content

Commit

Permalink
infra: migrate to pdm and full ruff (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobCoffee authored Sep 24, 2023
1 parent 8c88293 commit eddb978
Show file tree
Hide file tree
Showing 53 changed files with 1,659 additions and 1,188 deletions.
104 changes: 68 additions & 36 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
name: ci
name: Tests And Linting

on:
pull_request:
push:
branches:
- main

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Pre-Commit
run: python -m pip install pre-commit && pre-commit install

- name: Load cached Pre-Commit Dependencies
id: cached-poetry-dependencies
id: cached-pre-commit-dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit/
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}

- name: Execute Pre-Commit
run: pre-commit run --show-diff-on-failure --color=always --all-files

test:
runs-on: ubuntu-latest
strategy:
Expand All @@ -32,66 +39,84 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up python ${{ matrix.python-version }}
id: checkout-python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1

- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: v1-venv-${{ runner.os }}-${{ steps.checkout-python.outputs.version }}-${{ matrix.pydantic-version}}-${{ hashFiles('**/poetry.lock') }}
python-version: ${{ matrix.python-version }}
allow-python-prereleases: true
cache: true

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --extras full
run: pdm install -G:all

- name: Install pydantic
if: matrix.pydantic-version == '1.10'
run: source .venv/bin/activate && pip install "pydantic==1.10.10" && pip uninstall pydantic_core -y

- name: Set pythonpath
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV

- name: Test
if: matrix.python-version != '3.11' || matrix.pydantic-version != '2.0'
run: poetry run pytest
run: pdm run pytest

- name: Test with Coverage
if: matrix.python-version == '3.11' && matrix.pydantic-version == '2.0'
run: poetry run pytest tests docs/examples --cov=. --cov-report=xml
run: pdm run pytest tests docs/examples --cov=. --cov-report=xml

- uses: actions/upload-artifact@v3
if: matrix.python-version == '3.11'
with:
name: coverage-xml
path: coverage.xml
check-docs:

build-docs:
needs:
- validate
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-create: false
installer-parallel: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3

- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
path: .venv
key: venv-docs-${{ hashFiles('**/poetry.lock') }}
- name: Install docs dependencies
run: poetry install --no-interaction --with docs --extras full
python-version: "3.11"
allow-python-prereleases: true
cache: true

- name: Install dependencies
run: pdm install -G:docs

- name: Build docs
run: poetry run make docs
run: pdm run make docs

- name: Save PR number
env:
PR_NUMBER: ${{ github.event.number }}
run: echo $PR_NUMBER > .pr_number

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: docs-preview
path: |
docs/_build/html
.pr_number
sonar:
needs:
- test
Expand All @@ -101,17 +126,21 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: coverage-xml

- name: Fix coverage file for sonarcloud
run: sed -i "s/home\/runner\/work\/polyfactory\/polyfactory/github\/workspace/g" coverage.xml

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

codeql:
needs:
- test
Expand All @@ -122,13 +151,16 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL With Dependencies
if: github.event_name == 'push' && github.ref_name == 'main'
uses: github/codeql-action/init@v2

- name: Initialize CodeQL Without Dependencies
if: github.event_name == 'pull_request'
uses: github/codeql-action/init@v2
with:
setup-python-dependencies: false

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
72 changes: 72 additions & 0 deletions .github/workflows/docs-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Deploy Documentation Preview

on:
workflow_run:
workflows: [Tests And Linting]
types: [completed]

jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }}
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
path: docs-preview
name: docs-preview

- name: Set PR number
run: echo "PR_NUMBER=$(cat docs-preview/.pr_number)" >> $GITHUB_ENV

- name: Deploy docs preview
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs-preview/docs/_build/html
token: ${{ secrets.DOCS_PREVIEW_DEPLOY_TOKEN }}
repository-name: litestar-org/polyfactory-docs-preview
clean: false
target-folder: ${{ env.PR_NUMBER }}
branch: gh-pages

- uses: actions/github-script@v6
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
with:
script: |
const issue_number = process.env.PR_NUMBER
const body = "Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/" + issue_number
const opts = github.rest.issues.listComments.endpoint.merge({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
});
const comments = await github.paginate(opts)
for (const comment of comments) {
if (comment.user.id === 41898282 && comment.body === body) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id
})
}
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: body,
})
46 changes: 46 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Documentation Building

on:
release:
types: [published]
push:
branches:
- main

jobs:
docs:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: "3.11"

- uses: pdm-project/setup-pdm@v3
name: Set up PDM
with:
python-version: "3.11"
allow-python-prereleases: true
cache: true

- name: Install dependencies
run: pdm install -G:docs

- name: Fetch gh pages
run: git fetch origin gh-pages --depth=1

- name: Build release docs
run: pdm run python tools/build_docs.py docs-build
if: github.event_name == 'release'

- name: Build dev docs
run: pdm run python tools/build_docs.py docs-build
if: github.event_name == 'push'

- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs-build
Loading

0 comments on commit eddb978

Please sign in to comment.