-
Notifications
You must be signed in to change notification settings - Fork 15
112 lines (98 loc) · 4.12 KB
/
Copy pathpr-checks.yml
File metadata and controls
112 lines (98 loc) · 4.12 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
108
109
110
111
112
name: "PR checks"
on:
pull_request:
jobs:
pr-checks:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_DB: metrics_service
POSTGRES_USER: metrics_service
POSTGRES_PASSWORD: metrics_service
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: "Check PR target"
env:
BASE_REPO: ${{ github.event.pull_request.base.repo.full_name }}
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
run: |
if [[ "$BASE_REPO" == "ansible/metrics-service" && "$BASE_BRANCH" == "devel" ]]; then
echo "✓ PR targets devel on upstream"
elif [[ "$BASE_BRANCH" == stable-2.* ]]; then
echo "✓ PR targets $BASE_BRANCH"
else
echo "::error::PRs should target devel on ansible/metrics-service or a stable-2.x branch"
exit 1
fi
- name: "Checkout metrics-service (${{ github.ref }})"
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: "Check for wildcard cron minutes in renovate config"
run: |
if grep -Pn '"schedule".*"\* ' renovate.json; then
echo "::error::Cron schedules in renovate.json must not use * for minutes (runs every minute). Use a specific minute like 0."
exit 1
fi
- name: "Install uv"
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
- name: "Set up Python"
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version-file: "pyproject.toml"
- name: "Check for changes in uv.lock"
run: |
uv sync
if ! git diff --quiet uv.lock; then
echo "uv.lock has changed. Run 'uv sync' locally and commit the updated lock file."
git diff uv.lock
exit 1 # Fail the job
fi
- name: "Run ruff check"
run: |
uvx ruff check --output-format=github .
- name: "Check ruff format"
run: |
uvx ruff format --check
- name: "Check for missing migrations"
env:
METRICS_SERVICE_DATABASES__default__HOST: localhost
METRICS_SERVICE_DATABASES__default__PORT: 5432
METRICS_SERVICE_DATABASES__default__USER: metrics_service
METRICS_SERVICE_DATABASES__default__PASSWORD: metrics_service
METRICS_SERVICE_DATABASES__default__NAME: metrics_service
METRICS_SERVICE_DATABASES__default__OPTIONS__sslmode: disable
run: |
if ! uv run ./manage.py makemigrations --check; then
echo "Models have changed. Run 'uv run ./manage.py makemigrations' locally and commit the updated migrations."
exit 1 # Fail the job
fi
- name: Generate OpenAPI schema
env:
METRICS_SERVICE_DATABASES__default__HOST: localhost
METRICS_SERVICE_DATABASES__default__PORT: 5432
METRICS_SERVICE_DATABASES__default__USER: metrics_service
METRICS_SERVICE_DATABASES__default__PASSWORD: metrics_service
METRICS_SERVICE_DATABASES__default__NAME: metrics_service
METRICS_SERVICE_DATABASES__default__OPTIONS__sslmode: disable
run: |
mkdir -p tools/openapi-schema
uv run --frozen python manage.py spectacular --file tools/openapi-schema/metrics-service.yaml
uv run --frozen python manage.py spectacular --format openapi-json --file tools/openapi-schema/metrics-service.json
git diff --exit-code -- tools/openapi-schema/metrics-service.yaml
git diff --exit-code -- tools/openapi-schema/metrics-service.json
- name: Validate OpenAPI schema
run: |
uv run --frozen python -c "
from openapi_spec_validator import validate
import yaml
spec = yaml.safe_load(open('tools/openapi-schema/metrics-service.yaml'))
validate(spec)
print('✓ OpenAPI schema is valid!')
"