Skip to content
Merged
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
55 changes: 55 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: Checks

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

on:
pull_request:
branches:
- main
- stable-*
tags:
- "*"

jobs:
schema-check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox

- name: Run schema checks
run: tox -e check

type-check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox

- name: Run schema checks
run: tox -e type
26 changes: 20 additions & 6 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

on: # yamllint disable-line rule:truthy
on:
pull_request:
branches:
- main
Expand All @@ -14,8 +14,22 @@ on: # yamllint disable-line rule:truthy
- "*"

jobs:
linters:
name: Linters
uses: ansible-network/github_actions/.github/workflows/tox.yml@main
with:
envname: linters
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox

- name: Run unit tests
run: tox -e lint
13 changes: 5 additions & 8 deletions .github/workflows/units.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Tests
name: Tests

on:
pull_request:
Expand All @@ -25,15 +25,12 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: "3.13"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/requirements-dev.txt
python -m pip install tox

- name: Run migrations
run: python manage.py migrate

- name: Run core tests
run: python manage.py test core
- name: Run unit tests
run: tox -e test
20 changes: 19 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pre-commit-user
/.eggs
.python-version


# Testing
.cache
.coverage
Expand Down Expand Up @@ -49,3 +48,22 @@ tower-backup-*

# DB
db.sqlite3
*.db

# Environment variables
.env
.env.*
*.env

# Linting
.mypy_cache/

# Logs and temporary files
*.log
tmp/
temp/

# Virtual environments
.venv/
venv/
env/
8 changes: 6 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ repos:
args: [--indent=4, --no-sort-keys]
- id: trailing-whitespace

- repo: https://github.com/psf/black
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.1.0
hooks:
- id: black
args: [--config, pyproject.toml]

- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
args: [--max-line-length, "90"]

- repo: https://github.com/ikamensh/flynt/
rev: 1.0.1
Expand All @@ -42,9 +44,11 @@ repos:
rev: 6.0.1
hooks:
- id: isort
name: isort (python)
args: [--settings-path, pyproject.toml]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.0
hooks:
- id: mypy
pass_filenames: false
args: [--config-file=pyproject.toml, --ignore-missing-imports, "."]
52 changes: 41 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ Hi there! We're excited to have you as a contributor.
- [pattern-service](#pattern-service)
- [Table of contents](#table-of-contents)
- [Things to know prior to submitting code](#things-to-know-prior-to-submitting-code)
- [Build and Run the Development Environment](#build-and-run-the-development-environment)
- [Clone the repo](#clone-the-repo)
- [Configure python environment](#configure-python-environment)
- [Configure and run the application](#configure-and-run-the-application)
- [Build and Run the Development Environment](#build-and-run-the-development-environment)
- [Clone the repo](#clone-the-repo)
- [Configure Python environment](#configure-python-environment)
- [Set env variables for development](#set-env-variables-for-development)
- [Configure and run the application](#configure-and-run-the-application)
- [Updating dependencies](#updating-dependencies)
- [Running tests, linters, and code checks](#running-tests-linters-and-code-checks)

## Things to know prior to submitting code

Expand All @@ -20,15 +23,17 @@ Hi there! We're excited to have you as a contributor.
- We ask all of our community members and contributors to adhere to the [Ansible code of conduct](http://docs.ansible.com/ansible/latest/community/code_of_conduct.html). If you have questions, or need assistance, please reach out to our community team at [[email protected]](mailto:[email protected])
- This repository uses a`pre-commit`, configuration, so ensure that you install pre-commit globally for your user, or by using pipx.

### Build and Run the Development Environment
## Build and Run the Development Environment

#### Clone the repo
### Clone the repo

If you have not already done so, you will need to clone, or create a local copy, of the [pattern-service repository](https://github.com/ansible/pattern-service).
For more on how to clone the repo, view [git clone help](https://git-scm.com/docs/git-clone).
Once you have a local copy, run the commands in the following sections from the root of the project tree.

#### Configure python environment
### Configure Python environment

Ensure you are using a supported Python version, defined in the [pyproject.toml file](./pyproject.toml).

Create python virtual environment using one of the below commands:

Expand All @@ -38,12 +43,37 @@ Set the virtual environment

`source /path/to/virtualenv/bin/activate/`

Install required python modules
Install required python modules for development

`pip install -r requirements/requirements-dev.txt`

### Set env variables for development

`pip install -r ./requirements-all.txt`
Either create a .env file in the project root containing the following env variables, or export them to your shell env:

#### Configure and run the application
```bash
PATTERN_SERVICE_MODE=development
```

### Configure and run the application

`python manage.py migrate && python manage.py runserver`

The application can be reached in your browser at `https://localhost:8000/`
The application can be reached in your browser at `https://localhost:8000/`. The Django admin UI is accessible at `https://localhost:8000/admin` and the available API endpoints will be listed in the 404 information at `http://localhost:8000/api/pattern-service/v1/`.

## Updating dependencies

Project dependencies for all environments are specified in the [pyproject.toml file](./pyproject.toml). A requirements.txt file is generated for each environment using pip-compile, to simplify dependency installation with pip.

To add a new dependency:

1. Add the package to the appropriate project or optional dependencies section of the pyproject.toml file, using dependency specifiers to constrain versions.
2. Update the requirements files with the command `make requirements`. This should update the relevant requirements.txt files in the project's requirements directory.

## Running tests, linters, and code checks

Unit tests, linters, type checks, and other checks can all be run via `tox`. To see the available `tox` commands for this project, run `tox list`.

To run an individual tox command use the `-e` flag to specify the environment, for example: `tox -e test` to run tests with all supported python versions.
s
To run all tests and checks, simply run `tox` with no options.
48 changes: 33 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
.PHONY: build build-multi run test clean install-deps lint push-quay login-quay push-quay-multi
.DEFAULT_GOAL := help

.PHONY: help
help: ## Show this help message
@grep -hE '^[a-zA-Z0-9._-]+:.*?##' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-24s\033[0m %s\n", $$1, $$2}' | \
sort -u


# -------------------------------------
# Container image
# -------------------------------------

# Image name and tag
CONTAINER_RUNTIME ?= podman
IMAGE_NAME ?= ansible-pattern-service
IMAGE_NAME ?= pattern-service
IMAGE_TAG ?= latest

# Build the Docker image
build:
ensure-namespace:
@test -n "$$QUAY_NAMESPACE" || (echo "Error: QUAY_NAMESPACE is required to push quay.io" && exit 1)

.PHONY: build
build: ## Build the container image
@echo "Building container image..."
$(CONTAINER_RUNTIME) build -t $(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile.dev --arch amd64 .

ensure-namespace:
ifndef QUAY_NAMESPACE
$(error QUAY_NAMESPACE is required to push quay.io)
endif

# Clean up
clean:
.PHONY: clean
clean: ## Remove container image
@echo "Cleaning up..."
$(CONTAINER_RUNTIME) rmi -f $(IMAGE_NAME):$(IMAGE_TAG) || true

# Tag and push to Quay.io
push: ensure-namespace build
@echo "Tagging and pushing to registry..."
.PHONY: push
push: ensure-namespace build ## Tag and push container image to Quay.io
@echo "Tagging and pushing to quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)..."
$(CONTAINER_RUNTIME) tag $(IMAGE_NAME):$(IMAGE_TAG) quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
$(CONTAINER_RUNTIME) push quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)

# -------------------------------------
# Dependencies
# -------------------------------------

.PHONY: requirements
requirements: ## Generate requirements.txt files from pyproject.toml
pip-compile -o requirements/requirements.txt pyproject.toml
pip-compile --extra dev --extra test -o requirements/requirements-dev.txt pyproject.toml
pip-compile --extra test -o requirements/requirements-test.txt pyproject.toml
Loading