Skip to content

Commit e37a2e7

Browse files
committed
exercises
1 parent 00adb6c commit e37a2e7

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

.github/workflows/ci-cd.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ jobs:
1919
- name: Checkout code
2020
uses: actions/checkout@v4
2121

22+
- name: Install Ruff
23+
run: pip install ruff
24+
25+
- name: Lint with Ruff
26+
run: ruff check .
27+
2228
test:
2329
name: Run Tests
2430
runs-on: ubuntu-latest
@@ -28,15 +34,52 @@ jobs:
2834
- name: Checkout code
2935
uses: actions/checkout@v4
3036

37+
- name: Set up Python
38+
uses: actions/setup-python@v5
39+
with:
40+
python-version: '3.11'
41+
42+
- name: Install dependencies
43+
run: |
44+
pip install pytest pytest-cov
45+
pip install -r requirements.txt # If you have one
46+
47+
- name: Run tests with coverage
48+
run: |
49+
pytest --cov=. --cov-fail-under=80
50+
3151
build:
3252
name: Build Docker Image
3353
runs-on: ubuntu-latest
3454
needs: [lint, test]
3555
if: github.event_name == 'push' || github.event_name == 'release'
3656
permissions:
3757
contents: read
38-
actions: read
3958
packages: write
4059
steps:
4160
- name: Checkout code
4261
uses: actions/checkout@v4
62+
63+
- name: Log in to GitHub Container Registry
64+
uses: docker/login-action@v3
65+
with:
66+
registry: ghcr.io
67+
username: ${{ github.actor }}
68+
password: ${{ secrets.GITHUB_TOKEN }}
69+
70+
- name: Extract Docker metadata
71+
id: meta
72+
uses: docker/metadata-action@v5
73+
with:
74+
images: ghcr.io/${{ github.repository }}
75+
tags: |
76+
type=semver,pattern={{version}}
77+
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
78+
79+
- name: Build and push
80+
uses: docker/build-push-action@v5
81+
with:
82+
context: .
83+
push: ${{ github.event_name == 'release' }}
84+
tags: ${{ steps.meta.outputs.tags }}
85+
labels: ${{ steps.meta.outputs.labels }}

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ repos:
33
rev: v5.0.0
44
hooks:
55
- id: trailing-whitespace
6+
- id: check-added-large-files
7+
args: ['--maxkb=150']
8+
- id: check-yaml
9+
exclude: helm
10+
- id: sort-pythom
11+
- id: check-security
12+
- id: detect-private-key
13+
- id: check-style

app/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ async def get_item(item_id: int):
4848
"description": f"This is item number {item_id}",
4949
}
5050

51+
@app.post("/api/items")
52+
async def create_item(name: str, description: str):
53+
"""Create a new item."""
54+
return {
55+
"id": 999,
56+
"name": name,
57+
"description": description,
58+
"created": True
59+
}
5160

5261
if __name__ == "__main__":
5362
uvicorn.run(app, host="0.0.0.0", port=8000)

0 commit comments

Comments
 (0)