Skip to content
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
29 changes: 29 additions & 0 deletions РукосуеваЕД/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
pull_request:
branches: [main]

jobs:
build-and-test:
runs-on: ubuntu-latest

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

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

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

- name: Build (syntax check)
run: python -m py_compile src/temperature.py

- name: Run tests
run: python -m pytest tests/ -v
87 changes: 87 additions & 0 deletions РукосуеваЕД/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Задание 106. Continuous Integration (CI)

## Описание проекта

Небольшая библиотека для конвертации температур между шкалами Цельсия, Фаренгейта и Кельвина, с проверкой корректности входных значений (запрет температур ниже абсолютного нуля).

Репозиторий проекта: https://github.com/kir1903/ci-demo-temperature

## Структура

```text
src/temperature.py — функции конвертации
tests/test_temperature.py — юнит-тесты (pytest)
requirements.txt — зависимости
.github/workflows/ci.yml — пайплайн CI
```

## Запуск локально

```bash
pip install -r requirements.txt
python -m pytest tests/ -v
```

## Настройка CI

Используется **GitHub Actions**. Файл пайплайна: `.github/workflows/ci.yml`.

Пайплайн запускается автоматически при создании pull request в ветку `main` и выполняет шаги последовательно:

1. Checkout репозитория.
2. Установка Python и зависимостей проекта (`pip install -r requirements.txt`).
3. Сборка — проверка синтаксиса модуля (`python -m py_compile`).
4. Запуск тестов (`pytest`).

Если один из шагов завершается с ошибкой (например, тест не проходит), весь пайплайн завершается с ошибкой, и pull request помечается как непрошедший проверку.

```yaml
name: CI

on:
pull_request:
branches: [main]

jobs:
build-and-test:
runs-on: ubuntu-latest

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

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

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

- name: Build (syntax check)
run: python -m py_compile src/temperature.py

- name: Run tests
run: python -m pytest tests/ -v
```

## Демонстрация работы пайплайна

Для демонстрации подготовлены две ветки в репозитории:

- `feature/add-fahrenheit-to-kelvin` — добавляет новую функцию конвертации и тест к ней. Все тесты проходят, пайплайн завершается успешно.
- `bugfix/broken-fahrenheit-formula` — намеренно содержит ошибку в формуле конвертации Цельсия в Фаренгейт (пропущено слагаемое `+32`). Тест `test_celsius_to_fahrenheit` не проходит, пайплайн завершается с ошибкой.

### Успешный запуск

Pull request из ветки `feature/add-fahrenheit-to-kelvin` в `main`.

![Успешный запуск CI](./screenshots/ci-success.png)

### Неуспешный запуск

Pull request из ветки `bugfix/broken-fahrenheit-formula` в `main`.

![Неуспешный запуск CI](./screenshots/ci-failure.png)
1 change: 1 addition & 0 deletions РукосуеваЕД/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==8.3.3
Binary file added РукосуеваЕД/screenshots/ci-failure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
28 changes: 28 additions & 0 deletions РукосуеваЕД/src/temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Simple temperature conversion utilities used to demonstrate CI."""

ABSOLUTE_ZERO_CELSIUS = -273.15


def celsius_to_fahrenheit(celsius: float) -> float:
if celsius < ABSOLUTE_ZERO_CELSIUS:
raise ValueError("Temperature below absolute zero is not possible")
return celsius * 9 / 5 + 32


def fahrenheit_to_celsius(fahrenheit: float) -> float:
celsius = (fahrenheit - 32) * 5 / 9
if celsius < ABSOLUTE_ZERO_CELSIUS:
raise ValueError("Temperature below absolute zero is not possible")
return celsius


def celsius_to_kelvin(celsius: float) -> float:
if celsius < ABSOLUTE_ZERO_CELSIUS:
raise ValueError("Temperature below absolute zero is not possible")
return celsius + 273.15


def kelvin_to_celsius(kelvin: float) -> float:
if kelvin < 0:
raise ValueError("Temperature in Kelvin cannot be negative")
return kelvin - 273.15
Empty file.
36 changes: 36 additions & 0 deletions РукосуеваЕД/tests/test_temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

from src.temperature import (
celsius_to_fahrenheit,
celsius_to_kelvin,
fahrenheit_to_celsius,
kelvin_to_celsius,
)


def test_celsius_to_fahrenheit():
assert celsius_to_fahrenheit(0) == 32
assert celsius_to_fahrenheit(100) == 212


def test_fahrenheit_to_celsius():
assert fahrenheit_to_celsius(32) == 0
assert fahrenheit_to_celsius(212) == 100


def test_celsius_to_kelvin():
assert celsius_to_kelvin(0) == 273.15


def test_kelvin_to_celsius():
assert kelvin_to_celsius(273.15) == 0


def test_celsius_below_absolute_zero_raises():
with pytest.raises(ValueError):
celsius_to_fahrenheit(-300)


def test_kelvin_negative_raises():
with pytest.raises(ValueError):
kelvin_to_celsius(-1)