-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (90 loc) · 2.83 KB
/
ci-api.yml
File metadata and controls
107 lines (90 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: CI — API Service
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/api
jobs:
lint:
name: Lint & Import Check (API)
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: Install lint dependencies
run: |
pip install flake8 black isort
[ -f api/requirements.txt ] && pip install -r api/requirements.txt || true
- name: Black auto-format
run: black api/
- name: isort auto-fix import order
run: isort api/
- name: Commit formatting fixes (if any)
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "style: auto-format api/ with black & isort [skip ci]"
file_pattern: "api/**/*.py"
- name: Flake8 lint
run: flake8 api/ --max-line-length=100 --ignore=E203,W503
- name: Python import check (catch broken imports)
run: |
cd api
python -c "import ast, sys, pathlib
errors = []
for f in pathlib.Path('.').rglob('*.py'):
try:
ast.parse(f.read_text())
except SyntaxError as e:
errors.append(f'{f}: {e}')
if errors:
print('\n'.join(errors)); sys.exit(1)
print('All Python files parsed OK')"
build-and-push:
name: Build & Push API Image
runs-on: ubuntu-latest
needs: lint
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=sha-
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push API Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.api
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max