Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add python ci #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
extends: default

rules:
# Rule to enforce the use of double quotes
quoted-strings:
quote-type: double
required: false
# Additional rules can be configured as needed
line-length:
max: 120
indentation:
spaces: 2
document-start: disable
...
89 changes: 89 additions & 0 deletions actions/python/code-quality/format/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
name: Format Code
description: Checks and ensures the code is formatted according to the defined
style guidelines.

inputs:
os:
description: The operating system to use
default: ubuntu-latest
required: false
python_version:
description: Python version to use
default: "3.12"
required: false
poetry_install_options:
description: Options for installing dependencies via poetry
required: false
default: "--only=code_quality --no-root"
poetry_export_options:
description: Options for exporting dependencies to check for hash
changes for cache invalidation
required: false
default: "--only=code_quality"
Comment on lines +11 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way that we could get around having to define this in all actions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you mean poetry options, then no, but if you see the defaults are already set to what we use in cookiecutter, so if some one would want to use this action with cookicutter, they wont have to pass them either way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well.... technically yes, but I am assuming people from outside the org might also use this action with CC and their own separate groups of deps, if we don't take that into consideration, yes we can definitely remove it.


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

- name: Set up environment
uses: elixir-cloud-aai/actions/python/setup/poetry@main
id: setup
continue-on-error: true
with:
os: ${{ inputs.os }}
python_version: ${{ inputs.python_version }}
poetry_install_options: ${{ inputs.poetry_install_options }}
poetry_export_options: ${{ inputs.poetry_export_options }}

- name: Comment on PR
if: steps.setup.outcome == 'failure'
uses: elixir-cloud-aai/actions/github/comment@main
with:
ci_name: format
step_name: setup
commit_id: ${{ github.sha }}
issue-number: ${{ github.event.number }}
username: ${{ github.actor}}
message: |
Check your `pyproject.toml` and the dependency groups in them,
especially the `code_quality` group.

<details>
<summary>Env used for CI</summary>
OS: ${{ inputs.os }}
Python Version: ${{ inputs.python_version }}
Poetry Install Options: ${{ inputs.poetry_install_options }}
Poetry Export Options: ${{ inputs.poetry_export_options }}
</details>

- name: Check code style
id: format
continue-on-error: true
shell: bash
run: poetry run ruff format --check

- name: Comment on PR
if: steps.format.outcome == 'failure'
uses: elixir-cloud-aai/actions/github/comment@main
with:
ci_name: format
step_name: format
commit_id: ${{ github.sha }}
issue-number: ${{ github.event.number }}
username: ${{ github.actor}}
message: |
With the environment set up and dependencies installed,
run `poetry run ruff format` to check and fix some code style issues.

<details>
<summary>Use Makefile command</summary>
Default makefile from cookiecutter template has a command
`make fl` to run the check.

Run make in the root directory of the project, to see all the
available commands.
</details>
...
86 changes: 86 additions & 0 deletions actions/python/code-quality/lint/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
name: Lint Code
description: Lints the code to ensure code quality and adherence to standards.

inputs:
os:
description: The operating system to use
default: ubuntu-latest
required: false
python_version:
description: Python version to use
default: "3.12"
required: false
poetry_install_options:
description: Options for installing dependencies via poetry
required: false
default: "--only=code_quality --no-root"
poetry_export_options:
description: Options for exporting dependencies to check for hash
changes for cache invalidation
required: false
default: "--only=code_quality"

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

- name: Set up environment
uses: elixir-cloud-aai/actions/python/setup/poetry@main
continue-on-error: true
with:
os: ${{ inputs.os }}
python_version: ${{ inputs.python_version }}
poetry_install_options: ${{ inputs.poetry_install_options }}
poetry_export_options: ${{ inputs.poetry_export_options }}

- name: Comment on PR
if: steps.setup.outcome == 'failure'
uses: elixir-cloud-aai/actions/github/comment@main
with:
ci_name: lint
step_name: setup
commit_id: ${{ github.sha }}
issue-number: ${{ github.event.number }}
username: ${{ github.actor}}
message: |
Check your `pyproject.toml` and the dependency groups in them.

<details>
<summary>Env used for CI</summary>
OS: ${{ inputs.os }}
Python Version: ${{ inputs.python_version }}
Poetry Install Options: ${{ inputs.poetry_install_options }}
Poetry Export Options: ${{ inputs.poetry_export_options }}
</details>

- name: Check code quality
shell: bash
id: lint
run: poetry run ruff check .

- name: Comment on PR
if: steps.lint.outcome == 'failure'
uses: elixir-cloud-aai/actions/github/comment@main
with:
ci_name: format
step_name: format
commit_id: ${{ github.sha }}
issue-number: ${{ github.event.number }}
username: ${{ github.actor}}
message: |
With the environment set up and dependencies installed,
run `poetry run ruff check --fix` to check and fix some lint
issues.

<details>
<summary>Use Makefile command</summary>
Default makefile from cookiecutter template has a command
`make fl` to run the check.

Run make in the root directory of the project, to see all the
available commands.
</details>
...
115 changes: 115 additions & 0 deletions actions/python/code-quality/type-check/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
name: Type Check
description: Runs a type check on the codebase to ensure type safety and
correctness.

inputs:
os:
description: The operating system to use
required: false
default: "ubuntu-latest"
python_version:
description: Python version to use
default: "3.12"
required: false
poetry_install_options:
description: Options for installing dependencies via poetry
required: false
default: "--with=code_quality --with=types --no-root"
poetry_export_options:
description: Options for exporting dependencies to check for hash
changes for cache invalidation
required: false
default: "--with=code_quality --with=types"
file_path:
description: The path to the file or directory to type check
required: false
default: "."


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

- name: Set up environment
uses: elixir-cloud-aai/actions/python/setup/poetry@main
id: setup
continue-on-error: true
with:
os: ${{ inputs.os }}
python_version: ${{ inputs.python_version }}
poetry_install_options: ${{ inputs.poetry_install_options }}
poetry_export_options: ${{ inputs.poetry_export_options }}

- name: Comment on PR
if: steps.setup.outcome == 'failure'
uses: elixir-cloud-aai/actions/github/comment@main
with:
ci_name: type-check
step_name: setup
commit_id: ${{ github.sha }}
issue-number: ${{ github.event.number }}
username: ${{ github.actor}}
message: |
Check your `pyproject.toml` and the dependency groups in them,
especially `code_quality` and `types` group.

<details>
<summary>Env used for CI</summary>
OS: ${{ inputs.os }}
Python Version: ${{ inputs.python_version }}
Poetry Install Options: ${{ inputs.poetry_install_options }}
Poetry Export Options: ${{ inputs.poetry_export_options }}
</details>

- name: Check types
id: type-check
continue-on-error: true
shell: bash
run: poetry run mypy ${{ inputs.file_path }}

- name: Comment on PR
if: steps.type-check.outcome == 'failure'
uses: elixir-cloud-aai/actions/github/comment@main
with:
ci_name: type-check
step_name: type-check
commit_id: ${{ github.sha }}
issue-number: ${{ github.event.number }}
username: ${{ github.actor}}
message: |
With the environment set up and dependencies installed,
run `run mypy ${{ inputs.file_path }}` to see mypy errors.

<details>
<summary>Missing stubs or types</summary>
If you see errors related to missing stubs or types,
try running `poetry add types-<package> --group=types` or
`poetry add <package>-stub --group=types` to add type stubs.

If that fails, either the package does not have types/stubs
or they have different name.

In that case you can seach for them and add them to types group.
</details>

<details>
<summary>Ignore error</summary>
Add the module name in pyproject.toml under [tools.mypy.overrides]
section inside modules list.

```toml
[[tool.mypy.overrides]]
ignore_missing_imports = true
module = [
"connexion.*",
]
```

Try to as granular as possible to avoid ignoring all errors. If
you are using `x.y.z` import, add `x.y.z.*` to the list instead
of `x.*`.
</details>
...
Loading